Skip to content

Commit

Permalink
#80 refactor: 이슈 참여자 목록 조회 응답 dto 리스트 포함하게 구조 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
chunghye98 committed Aug 14, 2023
1 parent 6b59bc4 commit bc7991a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public ApiResponse<IssueMilestoneResponseDto> getIssueMilestones() {
}

@GetMapping("/issues/participants")
public ApiResponse<List<IssueUserResponseDto>> getIssueUsers() {
List<IssueUserResponseDto> participants = issueService.getIssueUsers();
public ApiResponse<IssueUserResponseDto> getIssueUsers() {
IssueUserResponseDto participants = issueService.getIssueUsers();
return ApiResponse.success(SUCCESS.getStatus(), participants);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public IssueOptionResponseDto(List<AssigneeVo> assignees, List<IssueLabelVo> lab
}

public static IssueOptionResponseDto of(List<AssigneeVo> assignees, List<IssueLabelVo> labels, IssueMilestoneVo milestone) {
if (milestone.getIssueMileStoneDetailVo() == null) {
if (milestone.getIssueMileStoneDetailVo().getId() == null) {
return IssueOptionResponseDto.builder()
.assignees(assignees)
.labels(labels)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
package codesquad.issueTracker.issue.dto;

import codesquad.issueTracker.user.domain.User;
import codesquad.issueTracker.issue.vo.IssueUserVo;
import java.util.List;
import lombok.Builder;
import lombok.Getter;

@Getter
public class IssueUserResponseDto {
private Long id;
private String name;
private String imageUrl;
private List<IssueUserVo> participants;


@Builder
public IssueUserResponseDto(Long id, String name, String imageUrl) {
this.id = id;
this.name = name;
this.imageUrl = imageUrl;
public IssueUserResponseDto(List<IssueUserVo> participants) {
this.participants = participants;
}

public static IssueUserResponseDto from(User user) {
public static IssueUserResponseDto from(List<IssueUserVo> participants) {
return IssueUserResponseDto.builder()
.id(user.getId())
.name(user.getName())
.imageUrl(user.getProfileImg())
.participants(participants)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package codesquad.issueTracker.issue.service;

import codesquad.issueTracker.issue.vo.IssueMileStoneDetailVo;
import codesquad.issueTracker.issue.vo.IssueUserVo;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
Expand Down Expand Up @@ -115,11 +116,12 @@ public IssueMilestoneResponseDto getIssueMilestones() {
return IssueMilestoneResponseDto.from(milestoneVos);
}

public List<IssueUserResponseDto> getIssueUsers() {
public IssueUserResponseDto getIssueUsers() {
List<User> users = userService.getUsers();
return users.stream()
.map(IssueUserResponseDto::from)
List<IssueUserVo> participants = users.stream()
.map(IssueUserVo::from)
.collect(Collectors.toList());
return IssueUserResponseDto.from(participants);
}

public IssueResponseDto getIssueById(Long issueId) {
Expand All @@ -142,7 +144,7 @@ public IssueOptionResponseDto getIssueOptions(Long issueId) {
List<IssueLabelVo> labels = labelService.findByIssueId(issueId);
IssueMilestoneVo milestone = milestoneService.findByIssueId(issueId);

if (milestone.getIssueMileStoneDetailVo() != null) {
if (milestone.getIssueMileStoneDetailVo().getId() != null) {
int closeCount = issueRepository.findCountByStatusAndMilestone(Status.CLOSED.getStatus(), milestone);
int openCount = issueRepository.findCountByStatusAndMilestone(Status.OPEN.getStatus(), milestone);
return IssueOptionResponseDto.of(assignees, labels, milestone.getMilestoneWithRatio(openCount, closeCount));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package codesquad.issueTracker.issue.vo;

import codesquad.issueTracker.user.domain.User;
import lombok.Builder;
import lombok.Getter;

@Getter
public class IssueUserVo {
private Long id;
private String name;
private String imageUrl;

@Builder
public IssueUserVo(Long id, String name, String imageUrl) {
this.id = id;
this.name = name;
this.imageUrl = imageUrl;
}

public static IssueUserVo from(User user) {
return IssueUserVo.builder()
.id(user.getId())
.name(user.getName())
.imageUrl(user.getProfileImg())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public int getLabelCount() {
.build();

public Optional<MilestoneVo> findByIssueId(Long issueId) {
String sql = "select m.id, m.name, m.description, m.don_date "
String sql = "select m.id, m.name "
+ "from milestones m "
+ " join issues i on m.id = i.milestone_id "
+ "where i.id = :issueId "
Expand Down

0 comments on commit bc7991a

Please sign in to comment.