-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[feat] 모델 부정이슈 조회 api 생성 및 더미데이터 삽입
- Loading branch information
Showing
16 changed files
with
300 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/com/backend/soullive_a/controller/ModelIssueController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/backend/soullive_a/dto/response/model/issue/ModelIssueResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) { | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/backend/soullive_a/dto/response/model/issue/ModelNewsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) { | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/backend/soullive_a/entity/model/issue/ModelIssue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/backend/soullive_a/entity/model/issue/ModelNews.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/backend/soullive_a/repository/model/issue/ModelIssueRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/backend/soullive_a/repository/model/issue/ModelNewsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/com/backend/soullive_a/service/ModelIssueService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/com/backend/soullive_a/service/impl/ModelIssueImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.