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; + } + }