Skip to content

Commit

Permalink
codesquad-issue-team-05#80 feat : 이슈 assignee 수정 api 구현
Browse files Browse the repository at this point in the history
- 수정이지만 해당 issueID 로 delete 후 request 정보를 바탕으로 재 등록하는 방식
  • Loading branch information
DOEKYONG committed Aug 14, 2023
1 parent 266727b commit a5a267a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,4 +71,10 @@ public ApiResponse<String> deleteIssues(@PathVariable Long id) {
issueService.delete(id);
return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage());
}

@PatchMapping("/issues/{id}/assignees")
public ApiResponse<String> patchAssignees(@PathVariable Long id, @RequestBody ModifyAssigneeRequestDto request) {
issueService.modifyAssignees(id, request);
return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,4 +125,24 @@ public Long delete(Long id) {
return deletedId;

}

@Transactional
public Long modifyAssignees(Long id, ModifyAssigneeRequestDto request) {
validateExistIssue(id);
List<Long> 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;
}

}

0 comments on commit a5a267a

Please sign in to comment.