Skip to content

Commit

Permalink
Merge pull request #30 from soulive-A/feat/#29-issue
Browse files Browse the repository at this point in the history
[feat] 모델 부정이슈 조회 api 생성 및 더미데이터 삽입
  • Loading branch information
lsm-del authored Mar 7, 2024
2 parents 041ce89 + 9e936d3 commit 0e2c19d
Show file tree
Hide file tree
Showing 16 changed files with 300 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,4 @@ public BaseResponse<ModelResponse> getModel(@RequestParam String modelName) {

}

/**
* 모델 등록 api
* @param request
* @return
*/
@PostMapping("")
public BaseResponse<ModelResponse> createModel(@RequestBody @Valid ModelRequest request) {
System.out.println("@");
return BaseResponse.<ModelResponse>builder()
.isSuccess(true)
.code(200)
.message("모델 생성에 성공했습니다.")
.data(modelService.createModel(request))
.build();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,7 @@ public BaseResponse<ModelIntroductionResponse> getModelIntroduction(@RequestPara
}


// @PostMapping("/{modelId}")
// public BaseResponse<ModelIntroductionResponse> createModelIntroduction(
// @PathVariable Long modelId,
// @RequestBody @Valid ModelIntroduceRequest request) {
// return BaseResponse.<ModelIntroductionResponse>builder()
// .isSuccess(true)
// .code(2006)
// .message("모델소개 정보 생성에 성공했습니다.")
// .data(modelIntroductionService.createModelIntroduction(request, modelId))
// .build();
// }


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.backend.soullive_a.controller;

import com.backend.soullive_a.dto.response.model.issue.ModelIssueResponse;
import com.backend.soullive_a.exception.base.BaseResponse;
import com.backend.soullive_a.service.ModelIssueService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("api/model/issue")
public class ModelIssueController {
private final ModelIssueService modelIssueService;
@GetMapping()
public BaseResponse<ModelIssueResponse> getIssue(@RequestParam String modelName) {
return BaseResponse.<ModelIssueResponse>builder()
.code(200)
.message("부정이슈 조회에 성공했습니다.")
.isSuccess(true)
.data(modelIssueService.getIssue(modelName))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.backend.soullive_a.dto.response.model.issue;

import lombok.Builder;

import java.util.List;

@Builder
public record ModelIssueResponse(
String scoreUrl,
String aiComment,
Integer crime,
List<ModelNewsResponse> modelNewsResponseList
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.backend.soullive_a.dto.response.model.issue;

import jakarta.persistence.Column;
import lombok.Builder;

import java.time.LocalDate;

@Builder
public record ModelNewsResponse(
String company,
LocalDate newsDate,
String title,
String newsUrl
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.backend.soullive_a.entity.model.issue;

import com.backend.soullive_a.entity.model.Model;
import jakarta.persistence.*;
import lombok.*;

@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class ModelIssue {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "MODEL_ISSUE_ID", nullable = false)
private Long id;

@Column(name = "SCORE_URL", nullable = false)
private String scoreUrl;

@Column(name = "AI_COMMENT", nullable = false)
private String aiComment;

@Column(name = "CRIME", nullable = false)
private Integer crime;

@OneToOne
@JoinColumn(name = "MODEL_ID", nullable = false)
private Model model;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.backend.soullive_a.entity.model.issue;

import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDate;

@Getter
@Entity
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class ModelNews {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "MODEL_NEWS_ID", nullable = false)
private Long id;

@Column(name = "COMPANY", nullable = false)
private String company;

@Column(name = "NEWS_DATE", nullable = false)
private LocalDate newsDate;

@Column(name = "TITLE", nullable = false)
private String title;

@Column(name = "NEWS_URL", nullable = false)
private String newsUrl;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "MODEL_ISSUE_ID", nullable = false)
private ModelIssue modelIssue;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.backend.soullive_a.repository.model.issue;

import com.backend.soullive_a.entity.model.issue.ModelIssue;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface ModelIssueRepository extends JpaRepository<ModelIssue, Long> {
public Optional<ModelIssue> findByModelModelName(String modelName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.backend.soullive_a.repository.model.issue;

import com.backend.soullive_a.entity.model.issue.ModelIssue;
import com.backend.soullive_a.entity.model.issue.ModelNews;
import com.backend.soullive_a.entity.model.popularity.ModelPopularGender;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface ModelNewsRepository extends JpaRepository<ModelNews, Long> {
List<ModelNews> findAllByModelIssueModelModelName(String modelName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
public interface ModelIntroductionService {
public ModelIntroductionResponse getModelIntroduction(String modelName);

public ModelIntroductionResponse createModelIntroduction(ModelIntroduceRequest request, Long modelId);

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.backend.soullive_a.service;


import com.backend.soullive_a.dto.response.model.issue.ModelIssueResponse;

public interface ModelIssueService {
public ModelIssueResponse getIssue(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
public interface ModelService {
public ModelResponse getModel(String modelName );

public ModelResponse createModel(ModelRequest request);

}
Original file line number Diff line number Diff line change
Expand Up @@ -93,101 +93,6 @@ public ModelIntroductionResponse getModelIntroduction(String modelName) {

}

/**
* 모델소개 생성 서비스 로직
*
* @param modelId
* @return
*/
@Override
@Transactional
public ModelIntroductionResponse createModelIntroduction(ModelIntroduceRequest request, Long modelId) {
List<String> modelImageKeywordList = new ArrayList<>();
List<ModelRecentWorkResponse> modelRecentWorkList = new ArrayList<>();
List<ModelRecentAdvertisementResponse> modelRecentAdvertisementList = new ArrayList<>();

Model model = modelRepository.findById(modelId)
.orElseThrow(() -> new NotFoundUserException());

// ModelIntroduction 엔티티 저장
modelIntroductionRepository.save(
ModelIntroduction.builder()
.model(model)
.build()
);

// ModelImageKeyword 엔티티 각각 저장
for (String keyword : request.keywords()) {
ModelImageKeyword modelImageKeyword = ModelImageKeyword.builder()
.model(model)
.keyword(keyword)
.build();

modelImageKeywordRepository.save(modelImageKeyword);

// ModelImageKeywordResponse (String) 생성
modelImageKeywordList.add(keyword);

}

// ModelRecentWorkRequest 엔티티 각각 저장
for (ModelRecentWorkRequest modelRecentWorkRequest : request.modelRecentWorks()) {
ModelRecentWork modelRecentWork = ModelRecentWork.builder()
.imageUrl(modelRecentWorkRequest.imageUrl())
.year(modelRecentWorkRequest.year())
.category(modelRecentWorkRequest.category())
.title(modelRecentWorkRequest.title())
.genre(modelRecentWorkRequest.genre())
.role(modelRecentWorkRequest.role())
.model(model)
.build();

modelRecentWorkRepository.save(modelRecentWork);

// ModelRecentWorkResponse 생성
ModelRecentWorkResponse modelRecentWorkResponse = ModelRecentWorkResponse.builder()
.imageUrl(modelRecentWorkRequest.imageUrl())
.year(modelRecentWorkRequest.year())
.category(modelRecentWorkRequest.category())
.title(modelRecentWorkRequest.title())
.genre(modelRecentWorkRequest.genre())
.role(modelRecentWorkRequest.role())
.build();

modelRecentWorkList.add(modelRecentWorkResponse);
}

// modelRecentAdvertisementRepository 엔티티 각각 저장
for (ModelRecentAdvertisementRequest modelRecentAdvertisementRequest : request.modelRecentAdvertisements()) {
ModelRecentAdvertisement modelRecentAdvertisement = ModelRecentAdvertisement.builder()
.imageUrl(modelRecentAdvertisementRequest.imageUrl())
.year(modelRecentAdvertisementRequest.year())
.brand(modelRecentAdvertisementRequest.brand())
.model(model)
.build();

modelRecentAdvertisementRepository.save(modelRecentAdvertisement);

// ModelRecentAdvertisementResponse 생성
ModelRecentAdvertisementResponse modelRecentAdvertisementResponse = ModelRecentAdvertisementResponse.builder()
.imageUrl(modelRecentAdvertisementRequest.imageUrl())
.year(modelRecentAdvertisementRequest.year())
.brand(modelRecentAdvertisementRequest.brand())
.build();

modelRecentAdvertisementList.add(modelRecentAdvertisementResponse);
}

//ModelIntroductionResponse 생성

return ModelIntroductionResponse.builder()
.modelImageKeywords(modelImageKeywordList)
.modelRecentWorks(modelRecentWorkList)
.modelRecentAdvertisements(modelRecentAdvertisementList)
.build();

}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.backend.soullive_a.service.impl;

import com.backend.soullive_a.constant.GenderType;
import com.backend.soullive_a.dto.response.model.issue.ModelIssueResponse;
import com.backend.soullive_a.dto.response.model.issue.ModelNewsResponse;
import com.backend.soullive_a.entity.model.issue.ModelIssue;
import com.backend.soullive_a.entity.model.issue.ModelNews;
import com.backend.soullive_a.entity.model.popularity.ModelPopularGender;
import com.backend.soullive_a.exception.custom.NotFoundUserException;
import com.backend.soullive_a.repository.model.issue.ModelIssueRepository;
import com.backend.soullive_a.repository.model.issue.ModelNewsRepository;
import com.backend.soullive_a.service.ModelIssueService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class ModelIssueImpl implements ModelIssueService {

private final ModelIssueRepository modelIssueRepository;
private final ModelNewsRepository modelNewsRepository;

/**
* 부정이슈 조회 서비스로직
* @param modelName
* @return
*/
@Override
public ModelIssueResponse getIssue(String modelName) {
ModelIssue modelIssue = modelIssueRepository.findByModelModelName(modelName)
.orElseThrow(() -> new NotFoundUserException());

List<ModelNews> modelNewsList = modelNewsRepository.findAllByModelIssueModelModelName(modelName);

List<ModelNewsResponse> modelNewsResponse = new ArrayList<>();

for (ModelNews modelNews : modelNewsList) {
modelNewsResponse.add(
ModelNewsResponse.builder()
.company(modelNews.getCompany())
.newsDate(modelNews.getNewsDate())
.title(modelNews.getTitle())
.newsUrl(modelNews.getNewsUrl())
.build()
);
}

return ModelIssueResponse.builder()
.scoreUrl(modelIssue.getScoreUrl())
.aiComment(modelIssue.getAiComment())
.crime(modelIssue.getCrime())
.modelNewsResponseList(modelNewsResponse)
.build();
}
}
Loading

0 comments on commit 0e2c19d

Please sign in to comment.