Skip to content

Commit

Permalink
feat: 라벨 개수와 마일스톤 개수를 묶어서 보내는 API 구현
Browse files Browse the repository at this point in the history
- 라벨 개수와 마일스톤 개수를 구하여 반환한다.
  • Loading branch information
zzawang committed May 29, 2024
1 parent 5d30989 commit 02b6bf1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.issuetracker.global.controller;

import com.issuetracker.global.dto.HomeComponentResponse;
import com.issuetracker.global.dto.HomeIssueResponse;
import com.issuetracker.global.service.HomeService;
import com.issuetracker.issue.dto.IssueQueryDto;
Expand All @@ -16,6 +17,12 @@
public class HomeController {
private final HomeService homeService;

@GetMapping("/components")
public ResponseEntity<HomeComponentResponse> getComponents() {
HomeComponentResponse homeComponentResponse = homeService.getComponents();
return ResponseEntity.ok().body(homeComponentResponse);
}

@GetMapping("/issues")
public ResponseEntity<HomeIssueResponse> getFilteredIssues(@ModelAttribute IssueQueryDto issueQueryDto) {
HomeIssueResponse homeIssueResponse = homeService.getFilteredIssues(issueQueryDto);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.issuetracker.global.dto;

import com.issuetracker.label.dto.LabelListDto;
import com.issuetracker.member.dto.SimpleMemberDto;
import com.issuetracker.milestone.dto.MilestoneListDto;
import java.util.List;
import com.issuetracker.label.dto.LabelCountDto;
import com.issuetracker.milestone.dto.MilestoneCountDto;
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
Expand All @@ -12,8 +10,6 @@
@ToString
@Builder
public class HomeComponentResponse {
private final List<SimpleMemberDto> assignees;
private final LabelListDto labels;
private final MilestoneListDto milestones;
private final List<SimpleMemberDto> authors;
private final LabelCountDto labelCount;
private final MilestoneCountDto milestoneCount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.issuetracker.issue.service.IssueFilterService;
import com.issuetracker.issue.service.IssueQueryService;
import com.issuetracker.label.service.LabelService;
import com.issuetracker.member.service.MemberService;
import com.issuetracker.milestone.service.MilestoneService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -21,18 +20,15 @@ public class HomeService {
private final IssueFilterService issueFilterService;
private final LabelService labelService;
private final MilestoneService milestoneService;
private final MemberService memberService;

/**
* 홈 화면의 상위 컴포넌트를 반환한다.
* 라벨의 개수와 마일스톤의 개수를 나타내는 홈 화면의 상위 컴포넌트를 반환한다.
*/
@Transactional(readOnly = true)
public HomeComponentResponse getComponents() {
return HomeComponentResponse.builder()
.assignees(memberService.getMembers())
.labels(labelService.getLabelListDto())
.milestones(milestoneService.showMilestoneList(false))
.authors(memberService.getMembers())
.labelCount(labelService.countLabels())
.milestoneCount(milestoneService.countMilestones())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.issuetracker.label.service;

import com.issuetracker.label.dto.LabelBgColorDto;
import com.issuetracker.label.dto.LabelCountDto;
import com.issuetracker.label.dto.LabelCoverDto;
import com.issuetracker.label.dto.LabelDto;
import com.issuetracker.label.dto.LabelListDto;
Expand All @@ -22,7 +23,7 @@
public class LabelService {
private final LabelRepository labelRepository;
private final HexColorGenerator hexColorGenerator;

/**
* 라벨의 개수와 함께 라벨의 전체 리스트를 반환한다.
*/
Expand Down Expand Up @@ -102,6 +103,15 @@ public LabelBgColorDto refreshLabelBackgroundColor() {
return new LabelBgColorDto(hexColorGenerator.generateRandomHexColor());
}

/**
* 라벨의 총 개수를 반환한다.
*/
@Transactional(readOnly = true)
public LabelCountDto countLabels() {
long count = labelRepository.countAll();
return new LabelCountDto(count);
}

private void validateLabelExists(Long id) {
if (!labelRepository.existsById(id)) {
throw new LabelNotFoundException();
Expand Down

0 comments on commit 02b6bf1

Please sign in to comment.