From a5a267af97915f7843fda0024c610fdfdff41355 Mon Sep 17 00:00:00 2001 From: DOEKYONG Date: Mon, 14 Aug 2023 20:33:11 +0900 Subject: [PATCH] =?UTF-8?q?#80=20feat=20:=20=EC=9D=B4=EC=8A=88=20assignee?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20api=20=EA=B5=AC=ED=98=84=20-=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=EC=9D=B4=EC=A7=80=EB=A7=8C=20=ED=95=B4?= =?UTF-8?q?=EB=8B=B9=20issueID=20=EB=A1=9C=20delete=20=ED=9B=84=20request?= =?UTF-8?q?=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EB=B0=94=ED=83=95=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=9E=AC=20=EB=93=B1=EB=A1=9D=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=B0=A9=EC=8B=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../issue/controller/IssueController.java | 7 +++++++ .../issue/repository/IssueRepository.java | 8 +++++++ .../issue/service/IssueService.java | 21 +++++++++++++++++++ 3 files changed, 36 insertions(+) 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 0df65ada4..68eb1cda6 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 @@ -15,6 +15,7 @@ import codesquad.issueTracker.global.common.ApiResponse; import codesquad.issueTracker.issue.dto.IssueWriteRequestDto; +import codesquad.issueTracker.issue.dto.ModifyAssigneeRequestDto; import codesquad.issueTracker.issue.dto.ModifyIssueContentRequestDto; import codesquad.issueTracker.issue.dto.ModifyIssueContentResponseDto; import codesquad.issueTracker.issue.dto.ModifyIssueStatusRequestDto; @@ -70,4 +71,10 @@ public ApiResponse deleteIssues(@PathVariable Long id) { issueService.delete(id); return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage()); } + + @PatchMapping("/issues/{id}/assignees") + public ApiResponse patchAssignees(@PathVariable Long id, @RequestBody ModifyAssigneeRequestDto request) { + issueService.modifyAssignees(id, request); + return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage()); + } } 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 152c72afd..48f3e9be3 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 @@ -108,4 +108,12 @@ public Long delete(Long id) { jdbcTemplate.update(sql, parameters); return id; } + + public Long resetAssignees(Long issueId) { + String sql = "DELETE FROM assignees WHERE issue_id = :issueId"; + SqlParameterSource parameterSource = new MapSqlParameterSource() + .addValue("issueId", issueId); + jdbcTemplate.update(sql, parameterSource); + return issueId; + } } 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 9fd283750..276c59624 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 @@ -14,6 +14,7 @@ import codesquad.issueTracker.global.exception.ErrorCode; import codesquad.issueTracker.issue.domain.Issue; import codesquad.issueTracker.issue.dto.IssueWriteRequestDto; +import codesquad.issueTracker.issue.dto.ModifyAssigneeRequestDto; import codesquad.issueTracker.issue.dto.ModifyIssueContentRequestDto; import codesquad.issueTracker.issue.dto.ModifyIssueContentResponseDto; import codesquad.issueTracker.issue.dto.ModifyIssueStatusRequestDto; @@ -124,4 +125,24 @@ public Long delete(Long id) { return deletedId; } + + @Transactional + public Long modifyAssignees(Long id, ModifyAssigneeRequestDto request) { + validateExistIssue(id); + List assignees = request.getAssignees(); + duplicatedId(assignees); + if (assignees != null) { + for (Long assigneeId : assignees) { + userService.validateUserId(assigneeId); + } + issueRepository.resetAssignees(id); + for (Long assigneeId : assignees) { + issueRepository.insertAssignees(id, assigneeId); + } + return id; + } + issueRepository.resetAssignees(id); + return id; + } + }