Skip to content

Commit

Permalink
feat(#14) :하단 mainpage api
Browse files Browse the repository at this point in the history
  • Loading branch information
eojinny committed Nov 19, 2023
1 parent c1662c2 commit ab15305
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}

}

0 comments on commit ab15305

Please sign in to comment.