diff --git a/src/main/java/gwangjang/server/domain/Issue/application/dto/res/TopicAndIssueRes.java b/src/main/java/gwangjang/server/domain/Issue/application/dto/res/TopicAndIssueRes.java new file mode 100644 index 0000000..c5e68b1 --- /dev/null +++ b/src/main/java/gwangjang/server/domain/Issue/application/dto/res/TopicAndIssueRes.java @@ -0,0 +1,19 @@ +package gwangjang.server.domain.Issue.application.dto.res; + +import gwangjang.server.domain.Issue.domain.entity.Issue; +import lombok.*; + +import java.util.List; + +@Getter +@Builder +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class TopicAndIssueRes { + private Long topicId; + private String topicTitle; + + private List<TopicIssueRes> issueList; + +} diff --git a/src/main/java/gwangjang/server/domain/Issue/application/dto/res/TopicIssueRes.java b/src/main/java/gwangjang/server/domain/Issue/application/dto/res/TopicIssueRes.java new file mode 100644 index 0000000..a037752 --- /dev/null +++ b/src/main/java/gwangjang/server/domain/Issue/application/dto/res/TopicIssueRes.java @@ -0,0 +1,17 @@ +package gwangjang.server.domain.Issue.application.dto.res; + +import lombok.*; + +@Getter +@Builder +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class TopicIssueRes { + + private Long id; + private String issueTitle; + + private String imgUrl; + +} diff --git a/src/main/java/gwangjang/server/domain/Issue/domain/repository/IssueRepository.java b/src/main/java/gwangjang/server/domain/Issue/domain/repository/IssueRepository.java index f9ecf17..fb975e6 100644 --- a/src/main/java/gwangjang/server/domain/Issue/domain/repository/IssueRepository.java +++ b/src/main/java/gwangjang/server/domain/Issue/domain/repository/IssueRepository.java @@ -4,6 +4,9 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface IssueRepository extends JpaRepository<Issue, Long>, IssueCustomRepository{ + List<Issue> findByTopicId(Long topicId); } diff --git a/src/main/java/gwangjang/server/domain/Issue/domain/service/IssueService.java b/src/main/java/gwangjang/server/domain/Issue/domain/service/IssueService.java index 151e446..0fd2ec4 100644 --- a/src/main/java/gwangjang/server/domain/Issue/domain/service/IssueService.java +++ b/src/main/java/gwangjang/server/domain/Issue/domain/service/IssueService.java @@ -1,11 +1,9 @@ package gwangjang.server.domain.Issue.domain.service; -import gwangjang.server.domain.Issue.application.dto.res.BubbleChartRes; -import gwangjang.server.domain.Issue.application.dto.res.IssueRes; -import gwangjang.server.domain.Issue.application.dto.res.KeywordRes; -import gwangjang.server.domain.Issue.application.dto.res.TotalRes; +import gwangjang.server.domain.Issue.application.dto.res.*; import gwangjang.server.domain.Issue.domain.entity.Issue; import gwangjang.server.domain.Issue.domain.entity.Keyword; +import gwangjang.server.domain.Issue.domain.entity.Topic; import gwangjang.server.domain.Issue.domain.repository.IssueCustomRepository; import gwangjang.server.domain.Issue.domain.repository.IssueRepository; import gwangjang.server.domain.Issue.domain.repository.KeywordRepository; @@ -14,6 +12,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -73,5 +72,37 @@ public List<TotalRes> getTotals() { List<Keyword> keywords = keywordRepository.findAll(); return TotalRes.fromIssuesAndKeywords(issues, keywords); -} + } + public List<TopicAndIssueRes> getTopicAndIssueList() { + List<Topic> topics = topicRepository.findAll(); + List<TopicAndIssueRes> topicAndIssueResList = new ArrayList<>(); + + for (Topic topic : topics) { + List<Issue> issues = issueRepository.findByTopicId(topic.getId()); + List<TopicIssueRes> topicIssueResList = new ArrayList<>(); + + for (Issue issue : issues) { + TopicIssueRes topicIssueRes = TopicIssueRes.builder() + .id(issue.getId()) + .issueTitle(issue.getIssueTitle()) + .imgUrl(issue.getImgUrl()) + .build(); + + topicIssueResList.add(topicIssueRes); + } + + TopicAndIssueRes topicAndIssueRes = TopicAndIssueRes.builder() + .topicId(topic.getId()) + .topicTitle(topic.getTopicTitle()) + .issueList(topicIssueResList) + .build(); + + topicAndIssueResList.add(topicAndIssueRes); + } + + return topicAndIssueResList; + } + + + } diff --git a/src/main/java/gwangjang/server/domain/Issue/presentation/IssueController.java b/src/main/java/gwangjang/server/domain/Issue/presentation/IssueController.java index 8e40298..860d87d 100644 --- a/src/main/java/gwangjang/server/domain/Issue/presentation/IssueController.java +++ b/src/main/java/gwangjang/server/domain/Issue/presentation/IssueController.java @@ -2,6 +2,7 @@ import gwangjang.server.domain.Issue.application.dto.res.IssueRes; import gwangjang.server.domain.Issue.application.dto.res.KeywordRes; +import gwangjang.server.domain.Issue.application.dto.res.TopicAndIssueRes; import gwangjang.server.domain.Issue.application.dto.res.TotalRes; import gwangjang.server.domain.Issue.domain.service.IssueService; import gwangjang.server.domain.Issue.exception.NotFoundIssueException; @@ -32,4 +33,9 @@ public ResponseEntity<SuccessResponse<List<KeywordRes>>> getKeywordById(@PathVar public ResponseEntity<SuccessResponse<List<TotalRes>>> getAll() { return ResponseEntity.ok(SuccessResponse.create(IssueResponseMessage.GET_ISSUE_SUCCESS.getMessage(),this.issueService.getTotals())); } + @GetMapping("/topic/all") + public ResponseEntity<SuccessResponse<List<TopicAndIssueRes>>> getTopicAndIssue() { + return ResponseEntity.ok(SuccessResponse.create(IssueResponseMessage.GET_ISSUE_SUCCESS.getMessage(),this.issueService.getTopicAndIssueList())); + } + }