From 8a159a5782036ed4396016a995ce4d5c4349209d Mon Sep 17 00:00:00 2001 From: DOEKYONG Date: Mon, 14 Aug 2023 23:23:37 +0900 Subject: [PATCH] =?UTF-8?q?#80=20fix=20:=20merge=20conflict=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../issue/controller/IssueController.java | 17 ++-- .../issue/repository/IssueRepository.java | 94 ++++++++----------- .../issue/service/IssueService.java | 74 +++++++-------- .../user/service/UserService.java | 1 + 4 files changed, 82 insertions(+), 104 deletions(-) diff --git a/be/issue/src/main/java/codesquad/issueTracker/issue/controller/IssueController.java b/be/issue/src/main/java/codesquad/issueTracker/issue/controller/IssueController.java index 35e17c872..cbdc4958f 100644 --- a/be/issue/src/main/java/codesquad/issueTracker/issue/controller/IssueController.java +++ b/be/issue/src/main/java/codesquad/issueTracker/issue/controller/IssueController.java @@ -2,17 +2,13 @@ import static codesquad.issueTracker.global.exception.SuccessCode.*; -import codesquad.issueTracker.issue.dto.IssueLabelResponseDto; -import codesquad.issueTracker.issue.dto.IssueMilestoneResponseDto; -import codesquad.issueTracker.issue.dto.IssueOptionResponseDto; -import codesquad.issueTracker.issue.dto.IssueResponseDto; -import codesquad.issueTracker.issue.dto.IssueUserResponseDto; import java.util.List; + import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -21,6 +17,11 @@ import org.springframework.web.bind.annotation.RestController; import codesquad.issueTracker.global.common.ApiResponse; +import codesquad.issueTracker.issue.dto.IssueLabelResponseDto; +import codesquad.issueTracker.issue.dto.IssueMilestoneResponseDto; +import codesquad.issueTracker.issue.dto.IssueOptionResponseDto; +import codesquad.issueTracker.issue.dto.IssueResponseDto; +import codesquad.issueTracker.issue.dto.IssueUserResponseDto; import codesquad.issueTracker.issue.dto.IssueWriteRequestDto; import codesquad.issueTracker.issue.dto.ModifyAssigneeRequestDto; import codesquad.issueTracker.issue.dto.ModifyIssueContentRequestDto; @@ -42,13 +43,12 @@ public class IssueController { @PostMapping("/issues") public ApiResponse postIssues(@Valid @RequestBody IssueWriteRequestDto request, - HttpServletRequest httpServletRequest) { + HttpServletRequest httpServletRequest) { Long id = Long.parseLong(String.valueOf(httpServletRequest.getAttribute("userId"))); issueService.save(request, id); return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage()); } - @GetMapping("/issues/labels") public ApiResponse> getIssueLabels() { List labels = issueService.getIssueLabels(); @@ -77,6 +77,7 @@ public ApiResponse getIssue(@PathVariable Long issueId) { public ApiResponse getIssueOptions(@PathVariable Long issueId) { IssueOptionResponseDto issueOptionResponseDto = issueService.getIssueOptions(issueId); return ApiResponse.success(SUCCESS.getStatus(), issueOptionResponseDto); + } @PatchMapping("/issues/status") public ApiResponse patchStatus(@RequestBody ModifyIssueStatusRequestDto request) { diff --git a/be/issue/src/main/java/codesquad/issueTracker/issue/repository/IssueRepository.java b/be/issue/src/main/java/codesquad/issueTracker/issue/repository/IssueRepository.java index 0ffc3f7d0..aad6bcbc9 100644 --- a/be/issue/src/main/java/codesquad/issueTracker/issue/repository/IssueRepository.java +++ b/be/issue/src/main/java/codesquad/issueTracker/issue/repository/IssueRepository.java @@ -1,14 +1,9 @@ package codesquad.issueTracker.issue.repository; - -import codesquad.issueTracker.issue.vo.AssigneeVo; -import codesquad.issueTracker.issue.vo.IssueMilestoneVo; +import java.time.LocalDateTime; import java.util.List; import java.util.Map; import java.util.Optional; -import java.time.LocalDateTime; - - import org.springframework.dao.support.DataAccessUtils; import org.springframework.jdbc.core.JdbcTemplate; @@ -21,6 +16,8 @@ import org.springframework.stereotype.Repository; import codesquad.issueTracker.issue.domain.Issue; +import codesquad.issueTracker.issue.vo.AssigneeVo; +import codesquad.issueTracker.issue.vo.IssueMilestoneVo; @Repository public class IssueRepository { @@ -62,60 +59,37 @@ public Long insertAssignees(Long issueId, Long userId) { return keyHolder.getKey().longValue(); } - - public Optional findActiveIssueById(Long issueId) { - String sql = "SELECT * FROM issues WHERE id = :issueId AND is_deleted = false"; - return Optional.ofNullable( - DataAccessUtils.singleResult( - jdbcTemplate.query(sql, Map.of("issueId", issueId), issueRowMapper))); - } - - private final RowMapper issueRowMapper = ((rs, rowNum) -> Issue.builder() - .id(rs.getLong("id")) - .title(rs.getString("title")) - .content(rs.getString("content")) - .createdAt(rs.getTimestamp("created_at").toLocalDateTime()) - .isClosed(rs.isClosed()) - .build()); - public Optional findById(Long issueId) { - String sql = "SELECT * FROM issues WHERE id = :issueId"; + String sql = "SELECT id, milestone_id, user_id, title, content, created_at, is_closed FROM issues WHERE id = :issueId"; return Optional.ofNullable( - DataAccessUtils.singleResult( - jdbcTemplate.query(sql, Map.of("issueId", issueId), issueRowMapper))); + DataAccessUtils.singleResult( + jdbcTemplate.query(sql, Map.of("issueId", issueId), issueRowMapper))); } public List findAssigneesById(Long issueId) { String sql = "select u.id, u.name, u.profile_img " - + "from assignees a " - + " join users u on a.user_id = u.id " - + " join issues i on a.issue_id = i.user_id " - + "where i.id = :issueId " - + "AND i.is_deleted = false"; - return jdbcTemplate.query(sql, Map.of("issueId",issueId), assigneeVoRowMapper); + + "from assignees a " + + " join users u on a.user_id = u.id " + + " join issues i on a.issue_id = i.user_id " + + "where i.id = :issueId " + + "AND i.is_deleted = false"; + return jdbcTemplate.query(sql, Map.of("issueId", issueId), assigneeVoRowMapper); } - private final RowMapper assigneeVoRowMapper = ((rs, rowNum) -> AssigneeVo.builder() - .id(rs.getLong("id")) - .name(rs.getString("name")) - .imgUrl(rs.getString("profile_img")) - .build()); - - public int findCountByStatusAndMilestone(boolean status, IssueMilestoneVo milestone) { String sql = "select COUNT(i.id) as count " - + "from issues i " - + " join milestones m on m.id = i.milestone_id " - + "where m.id = :milestoneId " - + "and i.is_deleted = false " - + "and i.is_closed = :status"; + + "from issues i " + + " join milestones m on m.id = i.milestone_id " + + "where m.id = :milestoneId " + + "and i.is_deleted = false " + + "and i.is_closed = :status"; MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("milestoneId", milestone.getId()); params.addValue("status", status); return jdbcTemplate.queryForObject(sql, params, Integer.class); - } - - public Optional findById(Long id) { + } + + public Optional findActiveIssueById(Long id) { String sql = "SELECT id, milestone_id, user_id, title, content, created_at, is_closed FROM issues WHERE id = :id AND is_deleted = 0"; return Optional.ofNullable( DataAccessUtils.singleResult( @@ -131,16 +105,6 @@ public Long modifyStatus(Long issueId, Boolean status) { return issueId; } - private final RowMapper issueRowMapper = (rs, rowNum) -> Issue.builder() - .id(rs.getLong("id")) - .milestoneId(rs.getLong("milestone_id")) - .userId(rs.getLong("user_id")) - .title(rs.getString("title")) - .content(rs.getString("content")) - .createdAt(rs.getObject("created_at", LocalDateTime.class)) - .isClosed(rs.getBoolean("is_closed")) - .build(); - public Long updateContent(Long id, String modifiedContent) { String sql = "UPDATE issues SET content = :modifiedContent WHERE Id = :id"; SqlParameterSource parameterSource = new MapSqlParameterSource() @@ -183,5 +147,21 @@ public Long updateMilestone(Long issueId, Long milestoneId) { jdbcTemplate.update(sql, parameterSource); return issueId; } - + + private final RowMapper issueRowMapper = (rs, rowNum) -> Issue.builder() + .id(rs.getLong("id")) + .milestoneId(rs.getLong("milestone_id")) + .userId(rs.getLong("user_id")) + .title(rs.getString("title")) + .content(rs.getString("content")) + .createdAt(rs.getObject("created_at", LocalDateTime.class)) + .isClosed(rs.getBoolean("is_closed")) + .build(); + + private final RowMapper assigneeVoRowMapper = ((rs, rowNum) -> AssigneeVo.builder() + .id(rs.getLong("id")) + .name(rs.getString("name")) + .imgUrl(rs.getString("profile_img")) + .build()); + } diff --git a/be/issue/src/main/java/codesquad/issueTracker/issue/service/IssueService.java b/be/issue/src/main/java/codesquad/issueTracker/issue/service/IssueService.java index 379484be2..06c2ab767 100644 --- a/be/issue/src/main/java/codesquad/issueTracker/issue/service/IssueService.java +++ b/be/issue/src/main/java/codesquad/issueTracker/issue/service/IssueService.java @@ -1,18 +1,5 @@ package codesquad.issueTracker.issue.service; -import codesquad.issueTracker.global.common.Status; -import codesquad.issueTracker.issue.dto.IssueOptionResponseDto; -import codesquad.issueTracker.issue.dto.IssueLabelResponseDto; -import codesquad.issueTracker.issue.dto.IssueMilestoneResponseDto; -import codesquad.issueTracker.issue.vo.IssueLabelVo; -import codesquad.issueTracker.issue.vo.IssueMilestoneVo; -import codesquad.issueTracker.issue.dto.IssueResponseDto; -import codesquad.issueTracker.issue.dto.IssueUserResponseDto; -import codesquad.issueTracker.issue.vo.AssigneeVo; -import codesquad.issueTracker.label.dto.LabelResponseDto; - -import codesquad.issueTracker.milestone.vo.MilestoneVo; -import codesquad.issueTracker.user.domain.User; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -21,12 +8,15 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; - -import codesquad.issueTracker.comment.service.CommentService; import codesquad.issueTracker.global.common.Status; import codesquad.issueTracker.global.exception.CustomException; import codesquad.issueTracker.global.exception.ErrorCode; import codesquad.issueTracker.issue.domain.Issue; +import codesquad.issueTracker.issue.dto.IssueLabelResponseDto; +import codesquad.issueTracker.issue.dto.IssueMilestoneResponseDto; +import codesquad.issueTracker.issue.dto.IssueOptionResponseDto; +import codesquad.issueTracker.issue.dto.IssueResponseDto; +import codesquad.issueTracker.issue.dto.IssueUserResponseDto; import codesquad.issueTracker.issue.dto.IssueWriteRequestDto; import codesquad.issueTracker.issue.dto.ModifyAssigneeRequestDto; import codesquad.issueTracker.issue.dto.ModifyIssueContentRequestDto; @@ -37,8 +27,14 @@ import codesquad.issueTracker.issue.dto.ModifyIssueTitleResponse; import codesquad.issueTracker.issue.dto.ModifyLabelRequestDto; import codesquad.issueTracker.issue.repository.IssueRepository; +import codesquad.issueTracker.issue.vo.AssigneeVo; +import codesquad.issueTracker.issue.vo.IssueLabelVo; +import codesquad.issueTracker.issue.vo.IssueMilestoneVo; +import codesquad.issueTracker.label.dto.LabelResponseDto; import codesquad.issueTracker.label.service.LabelService; import codesquad.issueTracker.milestone.service.MilestoneService; +import codesquad.issueTracker.milestone.vo.MilestoneVo; +import codesquad.issueTracker.user.domain.User; import codesquad.issueTracker.user.service.UserService; import lombok.RequiredArgsConstructor; @@ -89,26 +85,25 @@ private void duplicatedId(List list) { } } - public List getIssueLabels() { LabelResponseDto allLabels = labelService.findAll(); return allLabels.getLabels().stream() - .map(IssueLabelResponseDto::from) - .collect(Collectors.toList()); + .map(IssueLabelResponseDto::from) + .collect(Collectors.toList()); } public List getIssueMilestones() { List milestones = milestoneService.findMilestonesByStatus(Status.OPEN.getStatus()); return milestones.stream() - .map(IssueMilestoneResponseDto::from) - .collect(Collectors.toList()); + .map(IssueMilestoneResponseDto::from) + .collect(Collectors.toList()); } public List getIssueUsers() { List users = userService.getUsers(); return users.stream() - .map(IssueUserResponseDto::from) - .collect(Collectors.toList()); + .map(IssueUserResponseDto::from) + .collect(Collectors.toList()); } public IssueResponseDto getIssueById(Long issueId) { @@ -118,14 +113,9 @@ public IssueResponseDto getIssueById(Long issueId) { return IssueResponseDto.from(issue); } - private void validateExistIssue(Long issueId) { - issueRepository.findById(issueId) - .orElseThrow(() -> new CustomException(ErrorCode.NOT_EXIST_ISSUE)); - } - private Issue validateActiveIssueById(Long issueId) { return issueRepository.findActiveIssueById(issueId) - .orElseThrow(() -> new CustomException(ErrorCode.ALREADY_DELETED_ISSUE)); + .orElseThrow(() -> new CustomException(ErrorCode.ALREADY_DELETED_ISSUE)); } public IssueOptionResponseDto getIssueOptions(Long issueId) { @@ -143,7 +133,7 @@ public IssueOptionResponseDto getIssueOptions(Long issueId) { } return IssueOptionResponseDto.of(assignees, labels, milestone); - } + } @Transactional public List modifyIssueStatus(ModifyIssueStatusRequestDto request) { @@ -152,7 +142,7 @@ public List modifyIssueStatus(ModifyIssueStatusRequestDto request) { if (issueIds != null) { duplicatedId(issueIds); issueIds.stream() - .map(issueId -> validateExistIssue(issueId)) + .map(issueId -> validateExistActiveIssue(issueId)) .map(existIssue -> issueRepository.modifyStatus(existIssue.getId(), status)) .collect(Collectors.toList()); } @@ -162,17 +152,23 @@ public List modifyIssueStatus(ModifyIssueStatusRequestDto request) { @Transactional public Long modifyIssueStatusInDetail(Long id, ModifyIssueStatusRequestDto request) { Boolean status = Status.from(request.getStatus()).getStatus(); - validateExistIssue(id); + validateExistActiveIssue(id); return issueRepository.modifyStatus(id, status); } - private Issue validateExistIssue(Long issuesIds) { - return issueRepository.findById(issuesIds).orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_ISSUES)); + private Issue validateExistActiveIssue(Long issuesIds) { + return issueRepository.findActiveIssueById(issuesIds) + .orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_ISSUES)); + } + + private void validateExistIssue(Long issueId) { + issueRepository.findById(issueId) + .orElseThrow(() -> new CustomException(ErrorCode.NOT_EXIST_ISSUE)); } @Transactional public ModifyIssueContentResponseDto modifyIssueContent(Long id, ModifyIssueContentRequestDto request) { - validateExistIssue(id); + validateExistActiveIssue(id); String modifiedContent = request.getContent(); issueRepository.updateContent(id, modifiedContent); return new ModifyIssueContentResponseDto(modifiedContent); @@ -180,7 +176,7 @@ public ModifyIssueContentResponseDto modifyIssueContent(Long id, ModifyIssueCont @Transactional public ModifyIssueTitleResponse modifyIssueTitle(Long id, ModifyIssueTitleRequest request) { - validateExistIssue(id); + validateExistActiveIssue(id); String modifiedTitle = request.getTitle(); issueRepository.updateTitle(id, modifiedTitle); return new ModifyIssueTitleResponse(modifiedTitle); @@ -188,7 +184,7 @@ public ModifyIssueTitleResponse modifyIssueTitle(Long id, ModifyIssueTitleReques @Transactional public Long delete(Long id) { - validateExistIssue(id); + validateExistActiveIssue(id); Long deletedId = issueRepository.delete(id); return deletedId; @@ -196,7 +192,7 @@ public Long delete(Long id) { @Transactional public Long modifyAssignees(Long id, ModifyAssigneeRequestDto request) { - validateExistIssue(id); + validateExistActiveIssue(id); List assignees = request.getAssignees(); if (assignees != null) { @@ -216,7 +212,7 @@ public Long modifyAssignees(Long id, ModifyAssigneeRequestDto request) { @Transactional public Long modifyLabels(Long id, ModifyLabelRequestDto request) { - validateExistIssue(id); + validateExistActiveIssue(id); List labels = request.getLabels(); if (labels != null) { @@ -236,7 +232,7 @@ public Long modifyLabels(Long id, ModifyLabelRequestDto request) { @Transactional public Long modifyMilestone(Long id, ModifyIssueMilestoneDto request) { - validateExistIssue(id); + validateExistActiveIssue(id); Long milestoneId = request.getMilestone(); if (milestoneId != null) { milestoneService.isExistMilestone(milestoneId); diff --git a/be/issue/src/main/java/codesquad/issueTracker/user/service/UserService.java b/be/issue/src/main/java/codesquad/issueTracker/user/service/UserService.java index 0837ff31c..ca4469b49 100644 --- a/be/issue/src/main/java/codesquad/issueTracker/user/service/UserService.java +++ b/be/issue/src/main/java/codesquad/issueTracker/user/service/UserService.java @@ -1,5 +1,6 @@ package codesquad.issueTracker.user.service; +import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest;