From db405cce680378620303530b7eb3f4e980d78a89 Mon Sep 17 00:00:00 2001 From: DOEKYONG Date: Mon, 14 Aug 2023 15:21:37 +0900 Subject: [PATCH 01/11] =?UTF-8?q?#80=20feat=20:=20issue=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=EC=97=90=EC=84=9C=20=EC=9D=B4?= =?UTF-8?q?=EC=8A=88=EB=93=A4=20=EC=83=81=ED=83=9C=EB=B3=80=EA=B2=BD=20api?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/ErrorCode.java | 7 ++-- .../issue/controller/IssueController.java | 9 +++++ .../issue/repository/IssueRepository.java | 33 +++++++++++++++++++ .../issue/service/IssueService.java | 18 ++++++++++ 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/be/issue/src/main/java/codesquad/issueTracker/global/exception/ErrorCode.java b/be/issue/src/main/java/codesquad/issueTracker/global/exception/ErrorCode.java index 2a516eb34..ad90994f4 100644 --- a/be/issue/src/main/java/codesquad/issueTracker/global/exception/ErrorCode.java +++ b/be/issue/src/main/java/codesquad/issueTracker/global/exception/ErrorCode.java @@ -37,7 +37,7 @@ public enum ErrorCode implements StatusCode { ALREADY_DELETED_COMMENT(HttpStatus.BAD_REQUEST, "이미 삭제된 댓글입니다."), FAILED_CREATE_COMMENT(HttpStatus.SERVICE_UNAVAILABLE, "DB 서버 오류로 인해 댓글 생성에 실패했습니다."), FAILED_UPDATE_COMMENT(HttpStatus.SERVICE_UNAVAILABLE, "DB 서버 오류로 인해 댓글 수정에 실패했습니다."), - FAILED_DELETE_COMMENT(HttpStatus.SERVICE_UNAVAILABLE,"DB 서버 오류로 인해 댓글 삭제에 실패했습니다."), + FAILED_DELETE_COMMENT(HttpStatus.SERVICE_UNAVAILABLE, "DB 서버 오류로 인해 댓글 삭제에 실패했습니다."), // -- [Milestone] -- // INVALIDATE_DATE(HttpStatus.BAD_REQUEST, "현재 날짜보다 이전 날짜 입니다."), @@ -51,10 +51,9 @@ public enum ErrorCode implements StatusCode { LABEL_DELETE_FAILED(HttpStatus.BAD_REQUEST, "DB에서 라벨 삭제에 실패했습니다"), LABEL_FIND_FAILED(HttpStatus.BAD_REQUEST, "서버 오류로 라벨을 조회할 수 없습니다"), - // -- [Issue] -- // - DUPLICATE_OBJECT_FOUND(HttpStatus.BAD_REQUEST, "중복된 항목 선택입니다."); - + DUPLICATE_OBJECT_FOUND(HttpStatus.BAD_REQUEST, "중복된 항목 선택입니다."), + NOT_FOUND_ISSUES(HttpStatus.BAD_REQUEST, "이슈를 찾을 수 없습니다."); private HttpStatus status; private String message; 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 4cf9203c8..29b8b67cb 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 @@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; +import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -12,6 +13,7 @@ import codesquad.issueTracker.global.common.ApiResponse; import codesquad.issueTracker.issue.dto.IssueWriteRequestDto; +import codesquad.issueTracker.issue.dto.ModifyIssueStatusRequestDto; import codesquad.issueTracker.issue.service.IssueService; import lombok.RequiredArgsConstructor; @@ -29,4 +31,11 @@ public ApiResponse postIssues(@Valid @RequestBody IssueWriteRequestDto r issueService.save(request, id); return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage()); } + + @PatchMapping("/issues/status") + public ApiResponse patchStatus(@RequestBody ModifyIssueStatusRequestDto request) { + issueService.modifyIssueStatus(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 13a9c25fd..f93feec47 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,6 +1,12 @@ package codesquad.issueTracker.issue.repository; +import java.time.LocalDateTime; +import java.util.Map; +import java.util.Optional; + +import org.springframework.dao.support.DataAccessUtils; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.SqlParameterSource; @@ -49,4 +55,31 @@ public Long insertAssignees(Long issueId, Long userId) { jdbcTemplate.update(sql, parameters, keyHolder); return keyHolder.getKey().longValue(); } + + public Optional findById(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( + jdbcTemplate.query(sql, Map.of("id", id), issueRowMapper))); + } + + public Long modifyStatus(Long issueId, Boolean status) { + String sql = "UPDATE issues SET is_closed = :status where id = :id AND is_deleted = 0"; + SqlParameterSource parameterSource = new MapSqlParameterSource() + .addValue("id", issueId) + .addValue("status", status); + 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(); + } 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 8a6dd0bfb..bf574c214 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 @@ -9,10 +9,12 @@ 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.IssueWriteRequestDto; +import codesquad.issueTracker.issue.dto.ModifyIssueStatusRequestDto; import codesquad.issueTracker.issue.repository.IssueRepository; import codesquad.issueTracker.label.service.LabelService; import codesquad.issueTracker.milestone.service.MilestoneService; @@ -66,4 +68,20 @@ private void duplicatedId(List list) { } } } + + @Transactional + public List modifyIssueStatus(ModifyIssueStatusRequestDto request) { + List issueIds = request.getIssueIds(); + Boolean status = Status.from(request.getStatus()).getStatus(); + duplicatedId(issueIds); + validateExistIssue(issueIds); + return issueIds.stream() + .map(issueId -> issueRepository.modifyStatus(issueId, status)).collect(Collectors.toList()); + } + + private void validateExistIssue(List issuesIds) { + for (Long issueId : issuesIds) { + issueRepository.findById(issueId).orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_ISSUES)); + } + } } From 9df8669b77d7e1946b0ef85ad74ed294b84c04db Mon Sep 17 00:00:00 2001 From: DOEKYONG Date: Mon, 14 Aug 2023 15:21:55 +0900 Subject: [PATCH 02/11] =?UTF-8?q?#80=20feat=20:=20issue=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=EC=97=90=EC=84=9C=20=EC=9D=B4?= =?UTF-8?q?=EC=8A=88=EB=93=A4=20=EC=83=81=ED=83=9C=EB=B3=80=EA=B2=BD=20api?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../issue/dto/ModifyIssueStatusRequestDto.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueStatusRequestDto.java diff --git a/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueStatusRequestDto.java b/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueStatusRequestDto.java new file mode 100644 index 000000000..944bfd7e0 --- /dev/null +++ b/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueStatusRequestDto.java @@ -0,0 +1,14 @@ +package codesquad.issueTracker.issue.dto; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class ModifyIssueStatusRequestDto { + private String status; + private List issueIds; + +} From 338cfa78c6a3128e87c481bbdc4c9a34d8927f35 Mon Sep 17 00:00:00 2001 From: DOEKYONG Date: Mon, 14 Aug 2023 17:04:40 +0900 Subject: [PATCH 03/11] =?UTF-8?q?#80=20refactor=20:=20=EC=9C=A0=EC=A0=80,?= =?UTF-8?q?=EB=9D=BC=EB=B2=A8=20=EC=A1=B4=EC=9E=AC=20=EC=97=AC=EB=B6=80=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../issueTracker/issue/service/IssueService.java | 8 ++++---- .../issueTracker/label/service/LabelService.java | 6 ++---- .../codesquad/issueTracker/user/service/UserService.java | 7 ++----- 3 files changed, 8 insertions(+), 13 deletions(-) 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 bf574c214..429005da2 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 @@ -43,18 +43,18 @@ public Long save(IssueWriteRequestDto request, Long id) { // 라벨 리스트가 null 이 아니면 해당 라벨이 존재하는지 검증 후 라벨과 이슈 연결 테이블에 insert if (labels != null) { duplicatedId(labels); - labelService.validateLabelsId(labels); labels.stream() - .map(findLabel -> issueRepository.insertLabels(savedIssueId, findLabel)) + .map(labelId -> labelService.validateLabelsId(labelId)) + .map(existLabel -> issueRepository.insertLabels(savedIssueId, existLabel.getId())) .collect(Collectors.toList()); } // assignee 리스트가 null 이 아니면 assignees( 유저 id )가 존재하는지 검증 후 assignees 테이블에 insert if (assignees != null) { duplicatedId(assignees); - userService.validateUserIds(assignees); assignees.stream() - .map(findUser -> issueRepository.insertAssignees(savedIssueId, findUser)) + .map(assigneesId -> userService.validateUserId(assigneesId)) + .map(existUser -> issueRepository.insertAssignees(savedIssueId, existUser.getId())) .collect(Collectors.toList()); } return savedIssueId; diff --git a/be/issue/src/main/java/codesquad/issueTracker/label/service/LabelService.java b/be/issue/src/main/java/codesquad/issueTracker/label/service/LabelService.java index fc022ee10..c5392c088 100644 --- a/be/issue/src/main/java/codesquad/issueTracker/label/service/LabelService.java +++ b/be/issue/src/main/java/codesquad/issueTracker/label/service/LabelService.java @@ -43,9 +43,7 @@ public LabelResponseDto findAll() { .orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_MILESTONE))); } - public void validateLabelsId(List labels) { - for (Long label : labels) { - labelRepository.findById(label).orElseThrow(() -> new CustomException(ErrorCode.LABEL_FIND_FAILED)); - } + public Label validateLabelsId(Long label) { + return labelRepository.findById(label).orElseThrow(() -> new CustomException(ErrorCode.LABEL_FIND_FAILED)); } } 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 759d1badf..37ead2e2f 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 @@ -103,11 +103,8 @@ public void logout(HttpServletRequest request) { .orElseThrow(() -> new CustomException(ErrorCode.FAILED_LOGOUT_USER)); } - public void validateUserIds(List assignees) { - for (Long assignee : assignees) { - userRepository.findById(assignee).orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_USER)); - } - + public User validateUserId(Long assigneeId) { + return userRepository.findById(assigneeId).orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_USER)); } } From d014f49cd87f69d244ba9811925a36e4ce729fbb Mon Sep 17 00:00:00 2001 From: DOEKYONG Date: Mon, 14 Aug 2023 17:20:51 +0900 Subject: [PATCH 04/11] =?UTF-8?q?#80=20feat=20:=20=EC=9D=B4=EC=8A=88=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=ED=8E=98=EC=9D=B4=EC=A7=80=EC=97=90=EC=84=9C?= =?UTF-8?q?=EC=9D=98=20=EC=83=81=ED=83=9C=EB=B3=80=EA=B2=BD=20api=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../issue/controller/IssueController.java | 8 ++++++ .../issue/service/IssueService.java | 28 +++++++++++++------ .../user/service/UserService.java | 3 +- 3 files changed, 29 insertions(+), 10 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 29b8b67cb..709f1126c 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 @@ -6,6 +6,7 @@ import javax.validation.Valid; import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -38,4 +39,11 @@ public ApiResponse patchStatus(@RequestBody ModifyIssueStatusRequestDto return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage()); } + @PatchMapping("/issues/{id}/status") + public ApiResponse patchInDetailStatus(@PathVariable Long id, + @RequestBody ModifyIssueStatusRequestDto request) { + issueService.modifyIssueStatusInDetail(id, request); + return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage()); + } + } 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 429005da2..9722616e8 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 @@ -73,15 +73,27 @@ private void duplicatedId(List list) { public List modifyIssueStatus(ModifyIssueStatusRequestDto request) { List issueIds = request.getIssueIds(); Boolean status = Status.from(request.getStatus()).getStatus(); - duplicatedId(issueIds); - validateExistIssue(issueIds); - return issueIds.stream() - .map(issueId -> issueRepository.modifyStatus(issueId, status)).collect(Collectors.toList()); + if (issueIds != null) { + duplicatedId(issueIds); + issueIds.stream() + .map(issueId -> validateExistIssue(issueId)) + .map(existIssue -> issueRepository.modifyStatus(existIssue.getId(), status)) + .collect(Collectors.toList()); + ; + } + return issueIds; + } - private void validateExistIssue(List issuesIds) { - for (Long issueId : issuesIds) { - issueRepository.findById(issueId).orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_ISSUES)); - } + @Transactional + public Long modifyIssueStatusInDetail(Long id, ModifyIssueStatusRequestDto request) { + Boolean status = Status.from(request.getStatus()).getStatus(); + validateExistIssue(id); + return issueRepository.modifyStatus(id, status); + + } + + private Issue validateExistIssue(Long issuesIds) { + return issueRepository.findById(issuesIds).orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_ISSUES)); } } 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 37ead2e2f..01868ca47 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,6 +1,5 @@ package codesquad.issueTracker.user.service; -import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -100,7 +99,7 @@ public ResponseAccessToken reissueAccessToken(RequestRefreshTokenDto refreshToke public void logout(HttpServletRequest request) { Long userId = Long.parseLong(String.valueOf(request.getAttribute("userId"))); userRepository.deleteTokenByUserId(userId) - .orElseThrow(() -> new CustomException(ErrorCode.FAILED_LOGOUT_USER)); + .orElseThrow(() -> new CustomException(ErrorCode.FAILED_LOGOUT_USER)); } public User validateUserId(Long assigneeId) { From 9d6ffbefa9704eced427f8135d4521232a3797b6 Mon Sep 17 00:00:00 2001 From: DOEKYONG Date: Mon, 14 Aug 2023 17:45:58 +0900 Subject: [PATCH 05/11] =?UTF-8?q?#80=20feat=20:=20=EC=9D=B4=EC=8A=88=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=88=98=EC=A0=95=20api=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../issue/controller/IssueController.java | 8 ++++++++ .../issue/dto/ModifyIssueContentRequestDto.java | 12 ++++++++++++ .../issue/dto/ModifyIssueContentResponseDto.java | 10 ++++++++++ .../issue/repository/IssueRepository.java | 9 +++++++++ .../issueTracker/issue/service/IssueService.java | 9 +++++++++ 5 files changed, 48 insertions(+) create mode 100644 be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueContentRequestDto.java create mode 100644 be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueContentResponseDto.java 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 709f1126c..6a80fc415 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 @@ -14,6 +14,8 @@ import codesquad.issueTracker.global.common.ApiResponse; import codesquad.issueTracker.issue.dto.IssueWriteRequestDto; +import codesquad.issueTracker.issue.dto.ModifyIssueContentRequestDto; +import codesquad.issueTracker.issue.dto.ModifyIssueContentResponseDto; import codesquad.issueTracker.issue.dto.ModifyIssueStatusRequestDto; import codesquad.issueTracker.issue.service.IssueService; import lombok.RequiredArgsConstructor; @@ -46,4 +48,10 @@ public ApiResponse patchInDetailStatus(@PathVariable Long id, return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage()); } + @PatchMapping("/issues/{id}/content") + public ApiResponse patchContent(@PathVariable Long id, + @RequestBody ModifyIssueContentRequestDto request) { + ModifyIssueContentResponseDto response = issueService.modifyIssueContent(id, request); + return ApiResponse.success(SUCCESS.getStatus(), response); + } } diff --git a/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueContentRequestDto.java b/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueContentRequestDto.java new file mode 100644 index 000000000..13a4c0d1f --- /dev/null +++ b/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueContentRequestDto.java @@ -0,0 +1,12 @@ +package codesquad.issueTracker.issue.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class ModifyIssueContentRequestDto { + private String content; +} diff --git a/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueContentResponseDto.java b/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueContentResponseDto.java new file mode 100644 index 000000000..3d30c762a --- /dev/null +++ b/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueContentResponseDto.java @@ -0,0 +1,10 @@ +package codesquad.issueTracker.issue.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class ModifyIssueContentResponseDto { + String modifiedContent; +} 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 f93feec47..dbf694a44 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 @@ -82,4 +82,13 @@ public Long modifyStatus(Long issueId, Boolean status) { .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() + .addValue("id", id) + .addValue("modifiedContent", modifiedContent); + jdbcTemplate.update(sql, parameterSource); + return id; + + } } 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 9722616e8..27b60d39e 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,8 @@ import codesquad.issueTracker.global.exception.ErrorCode; import codesquad.issueTracker.issue.domain.Issue; import codesquad.issueTracker.issue.dto.IssueWriteRequestDto; +import codesquad.issueTracker.issue.dto.ModifyIssueContentRequestDto; +import codesquad.issueTracker.issue.dto.ModifyIssueContentResponseDto; import codesquad.issueTracker.issue.dto.ModifyIssueStatusRequestDto; import codesquad.issueTracker.issue.repository.IssueRepository; import codesquad.issueTracker.label.service.LabelService; @@ -96,4 +98,11 @@ public Long modifyIssueStatusInDetail(Long id, ModifyIssueStatusRequestDto reque private Issue validateExistIssue(Long issuesIds) { return issueRepository.findById(issuesIds).orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_ISSUES)); } + + @Transactional + public ModifyIssueContentResponseDto modifyIssueContent(Long id, ModifyIssueContentRequestDto request) { + String modifiedContent = request.getContent(); + issueRepository.updateContent(id, modifiedContent); + return new ModifyIssueContentResponseDto(modifiedContent); + } } From eaa62840a7564c86929488e95bfcc8b71cc57e4c Mon Sep 17 00:00:00 2001 From: DOEKYONG Date: Mon, 14 Aug 2023 18:36:52 +0900 Subject: [PATCH 06/11] =?UTF-8?q?#80=20feat=20:=20=EC=9D=B4=EC=8A=88=20?= =?UTF-8?q?=EC=A0=9C=EB=AA=A9=20=EC=88=98=EC=A0=95=20api=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../issue/controller/IssueController.java | 9 +++++++++ .../issue/dto/ModifyIssueTitleRequest.java | 17 +++++++++++++++++ .../issue/dto/ModifyIssueTitleResponse.java | 10 ++++++++++ .../issue/repository/IssueRepository.java | 9 +++++++++ .../issue/service/IssueService.java | 11 +++++++++++ 5 files changed, 56 insertions(+) create mode 100644 be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueTitleRequest.java create mode 100644 be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueTitleResponse.java 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 6a80fc415..b5ac305f8 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 @@ -17,6 +17,8 @@ import codesquad.issueTracker.issue.dto.ModifyIssueContentRequestDto; import codesquad.issueTracker.issue.dto.ModifyIssueContentResponseDto; import codesquad.issueTracker.issue.dto.ModifyIssueStatusRequestDto; +import codesquad.issueTracker.issue.dto.ModifyIssueTitleRequest; +import codesquad.issueTracker.issue.dto.ModifyIssueTitleResponse; import codesquad.issueTracker.issue.service.IssueService; import lombok.RequiredArgsConstructor; @@ -54,4 +56,11 @@ public ApiResponse patchContent(@PathVariable Lon ModifyIssueContentResponseDto response = issueService.modifyIssueContent(id, request); return ApiResponse.success(SUCCESS.getStatus(), response); } + + @PatchMapping("/issues/{id}/title") + public ApiResponse patchTitle(@PathVariable Long id, + @Valid @RequestBody ModifyIssueTitleRequest request) { + ModifyIssueTitleResponse response = issueService.modifyIssueTitle(id, request); + return ApiResponse.success(SUCCESS.getStatus(), response); + } } diff --git a/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueTitleRequest.java b/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueTitleRequest.java new file mode 100644 index 000000000..b5087285f --- /dev/null +++ b/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueTitleRequest.java @@ -0,0 +1,17 @@ +package codesquad.issueTracker.issue.dto; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class ModifyIssueTitleRequest { + @NotNull(message = "제목을 입력해주세요.") + @NotBlank(message = "공백은 입력할 수 없습니다.") + private String title; +} diff --git a/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueTitleResponse.java b/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueTitleResponse.java new file mode 100644 index 000000000..90f93ee5c --- /dev/null +++ b/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyIssueTitleResponse.java @@ -0,0 +1,10 @@ +package codesquad.issueTracker.issue.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class ModifyIssueTitleResponse { + private String modifiedTitle; +} 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 dbf694a44..d7560360c 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 @@ -91,4 +91,13 @@ public Long updateContent(Long id, String modifiedContent) { return id; } + + public Long updateTitle(Long id, String modifiedTitle) { + String sql = "UPDATE issues SET title = :modifiedTitle WHERE Id = :id"; + SqlParameterSource parameterSource = new MapSqlParameterSource() + .addValue("id", id) + .addValue("modifiedTitle", modifiedTitle); + jdbcTemplate.update(sql, parameterSource); + return id; + } } 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 27b60d39e..7762b0c71 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 @@ -17,6 +17,8 @@ import codesquad.issueTracker.issue.dto.ModifyIssueContentRequestDto; import codesquad.issueTracker.issue.dto.ModifyIssueContentResponseDto; import codesquad.issueTracker.issue.dto.ModifyIssueStatusRequestDto; +import codesquad.issueTracker.issue.dto.ModifyIssueTitleRequest; +import codesquad.issueTracker.issue.dto.ModifyIssueTitleResponse; import codesquad.issueTracker.issue.repository.IssueRepository; import codesquad.issueTracker.label.service.LabelService; import codesquad.issueTracker.milestone.service.MilestoneService; @@ -101,8 +103,17 @@ private Issue validateExistIssue(Long issuesIds) { @Transactional public ModifyIssueContentResponseDto modifyIssueContent(Long id, ModifyIssueContentRequestDto request) { + validateExistIssue(id); String modifiedContent = request.getContent(); issueRepository.updateContent(id, modifiedContent); return new ModifyIssueContentResponseDto(modifiedContent); } + + @Transactional + public ModifyIssueTitleResponse modifyIssueTitle(Long id, ModifyIssueTitleRequest request) { + validateExistIssue(id); + String modifiedTitle = request.getTitle(); + issueRepository.updateTitle(id, modifiedTitle); + return new ModifyIssueTitleResponse(modifiedTitle); + } } From 266727bc861b2de3a084c90b27865a4734b6a8ef Mon Sep 17 00:00:00 2001 From: DOEKYONG Date: Mon, 14 Aug 2023 18:46:22 +0900 Subject: [PATCH 07/11] =?UTF-8?q?#80=20feat=20:=20=EC=9D=B4=EC=8A=88=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../issueTracker/issue/controller/IssueController.java | 7 +++++++ .../issueTracker/issue/repository/IssueRepository.java | 8 ++++++++ .../issueTracker/issue/service/IssueService.java | 8 ++++++++ 3 files changed, 23 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 b5ac305f8..0df65ada4 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 @@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -63,4 +64,10 @@ public ApiResponse patchTitle(@PathVariable Long id, ModifyIssueTitleResponse response = issueService.modifyIssueTitle(id, request); return ApiResponse.success(SUCCESS.getStatus(), response); } + + @DeleteMapping("/issues/{id}") + public ApiResponse deleteIssues(@PathVariable Long id) { + issueService.delete(id); + 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 d7560360c..152c72afd 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 @@ -100,4 +100,12 @@ public Long updateTitle(Long id, String modifiedTitle) { jdbcTemplate.update(sql, parameterSource); return id; } + + public Long delete(Long id) { + String sql = "UPDATE issues SET is_deleted = 1 where id = :id"; + SqlParameterSource parameters = new MapSqlParameterSource() + .addValue("id", id); + jdbcTemplate.update(sql, parameters); + return id; + } } 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 7762b0c71..9fd283750 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 @@ -116,4 +116,12 @@ public ModifyIssueTitleResponse modifyIssueTitle(Long id, ModifyIssueTitleReques issueRepository.updateTitle(id, modifiedTitle); return new ModifyIssueTitleResponse(modifiedTitle); } + + @Transactional + public Long delete(Long id) { + validateExistIssue(id); + Long deletedId = issueRepository.delete(id); + return deletedId; + + } } From a5a267af97915f7843fda0024c610fdfdff41355 Mon Sep 17 00:00:00 2001 From: DOEKYONG Date: Mon, 14 Aug 2023 20:33:11 +0900 Subject: [PATCH 08/11] =?UTF-8?q?#80=20feat=20:=20=EC=9D=B4=EC=8A=88=20ass?= =?UTF-8?q?ignee=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; + } + } From 5f105d0babc34a26adf13d338194a83dc00ba8d6 Mon Sep 17 00:00:00 2001 From: DOEKYONG Date: Mon, 14 Aug 2023 20:33:19 +0900 Subject: [PATCH 09/11] =?UTF-8?q?#80=20feat=20:=20=EC=9D=B4=EC=8A=88=20ass?= =?UTF-8?q?ignee=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/dto/ModifyAssigneeRequestDto.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyAssigneeRequestDto.java diff --git a/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyAssigneeRequestDto.java b/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyAssigneeRequestDto.java new file mode 100644 index 000000000..31769493e --- /dev/null +++ b/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyAssigneeRequestDto.java @@ -0,0 +1,10 @@ +package codesquad.issueTracker.issue.dto; + +import java.util.List; + +import lombok.Getter; + +@Getter +public class ModifyAssigneeRequestDto { + private List assignees; +} From eae871b572ed787de0bb472e13e904e9c0d459ea Mon Sep 17 00:00:00 2001 From: DOEKYONG Date: Mon, 14 Aug 2023 21:03:10 +0900 Subject: [PATCH 10/11] =?UTF-8?q?#80=20feat=20:=20=EC=9D=B4=EC=8A=88=20lab?= =?UTF-8?q?el=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=20labelID=20=EB=A1=9C=20=ED=95=B4=EB=8B=B9=20?= =?UTF-8?q?=EB=A1=9C=EC=9A=B0=20delete=20=ED=9B=84=20request=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EB=A5=BC=20=EB=B0=94=ED=83=95=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=9E=AC=20=EB=93=B1=EB=A1=9D=ED=95=98=EB=8A=94=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../issue/controller/IssueController.java | 7 ++++++ .../issue/dto/ModifyLabelRequestDto.java | 11 +++++++++ .../issue/service/IssueService.java | 23 ++++++++++++++++++- .../label/repository/LabelRepository.java | 19 +++++++++++++++ .../label/service/LabelService.java | 8 +++++++ 5 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyLabelRequestDto.java 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 68eb1cda6..04d31d58a 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 @@ -21,6 +21,7 @@ import codesquad.issueTracker.issue.dto.ModifyIssueStatusRequestDto; import codesquad.issueTracker.issue.dto.ModifyIssueTitleRequest; import codesquad.issueTracker.issue.dto.ModifyIssueTitleResponse; +import codesquad.issueTracker.issue.dto.ModifyLabelRequestDto; import codesquad.issueTracker.issue.service.IssueService; import lombok.RequiredArgsConstructor; @@ -77,4 +78,10 @@ public ApiResponse patchAssignees(@PathVariable Long id, @RequestBody Mo issueService.modifyAssignees(id, request); return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage()); } + + @PatchMapping("/issues/{id}/labels") + public ApiResponse patchLabel(@PathVariable Long id, @RequestBody ModifyLabelRequestDto request) { + issueService.modifyLabels(id, request); + return ApiResponse.success(SUCCESS.getStatus(), SUCCESS.getMessage()); + } } diff --git a/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyLabelRequestDto.java b/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyLabelRequestDto.java new file mode 100644 index 000000000..a57f4559b --- /dev/null +++ b/be/issue/src/main/java/codesquad/issueTracker/issue/dto/ModifyLabelRequestDto.java @@ -0,0 +1,11 @@ +package codesquad.issueTracker.issue.dto; + +import java.util.List; + +import lombok.Getter; + +@Getter +public class ModifyLabelRequestDto { + private List labels; + +} 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 276c59624..a44d19cda 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 @@ -20,6 +20,7 @@ import codesquad.issueTracker.issue.dto.ModifyIssueStatusRequestDto; import codesquad.issueTracker.issue.dto.ModifyIssueTitleRequest; import codesquad.issueTracker.issue.dto.ModifyIssueTitleResponse; +import codesquad.issueTracker.issue.dto.ModifyLabelRequestDto; import codesquad.issueTracker.issue.repository.IssueRepository; import codesquad.issueTracker.label.service.LabelService; import codesquad.issueTracker.milestone.service.MilestoneService; @@ -130,8 +131,9 @@ public Long delete(Long id) { public Long modifyAssignees(Long id, ModifyAssigneeRequestDto request) { validateExistIssue(id); List assignees = request.getAssignees(); - duplicatedId(assignees); + if (assignees != null) { + duplicatedId(assignees); for (Long assigneeId : assignees) { userService.validateUserId(assigneeId); } @@ -145,4 +147,23 @@ public Long modifyAssignees(Long id, ModifyAssigneeRequestDto request) { return id; } + @Transactional + public Long modifyLabels(Long id, ModifyLabelRequestDto request) { + validateExistIssue(id); + List labels = request.getLabels(); + + if (labels != null) { + duplicatedId(labels); + for (Long labelId : labels) { + labelService.validateLabelsId(labelId); + } + labelService.resetLabels(id); + for (Long labelId : labels) { + labelService.insertIssuesLabels(id, labelId); + } + return id; + } + labelService.resetLabels(id); + return id; + } } diff --git a/be/issue/src/main/java/codesquad/issueTracker/label/repository/LabelRepository.java b/be/issue/src/main/java/codesquad/issueTracker/label/repository/LabelRepository.java index 4fe621101..13d8aeac9 100644 --- a/be/issue/src/main/java/codesquad/issueTracker/label/repository/LabelRepository.java +++ b/be/issue/src/main/java/codesquad/issueTracker/label/repository/LabelRepository.java @@ -9,6 +9,7 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.support.GeneratedKeyHolder; import org.springframework.jdbc.support.KeyHolder; import org.springframework.stereotype.Repository; @@ -96,4 +97,22 @@ public Optional