From f99f79afeac314e8b5a8d51e33fe4daab072bb06 Mon Sep 17 00:00:00 2001 From: DOEKYONG Date: Sun, 20 Aug 2023 00:41:03 +0900 Subject: [PATCH] =?UTF-8?q?#119=20refactor=20:=20=EC=9D=B4=EC=8A=88=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20label,assignee=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../issue/service/IssueService.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 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 18042bcca..9471f88c9 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 @@ -68,26 +68,32 @@ public Long save(IssueWriteRequestDto request, Long id) { Issue issue = IssueWriteRequestDto.toEntity(request, id); Long savedIssueId = issueRepository.insert(issue); - // 라벨 리스트가 null 이 아니면 해당 라벨이 존재하는지 검증 후 라벨과 이슈 연결 테이블에 insert if (labels != null) { - duplicatedId(labels); - labels.stream() - .map(labelId -> labelService.validateLabelsId(labelId)) - .map(existLabel -> issueRepository.insertLabels(savedIssueId, existLabel.getId())) - .collect(Collectors.toList()); + insertLabel(labels, savedIssueId); } - // assignee 리스트가 null 이 아니면 assignees( 유저 id )가 존재하는지 검증 후 assignees 테이블에 insert if (assignees != null) { - duplicatedId(assignees); - assignees.stream() - .map(assigneesId -> userService.validateUserId(assigneesId)) - .map(existUser -> issueRepository.insertAssignees(savedIssueId, existUser.getId())) - .collect(Collectors.toList()); + insertAssignee(assignees, savedIssueId); } return savedIssueId; } + private List insertLabel(List labels, Long savedIssueId) { + duplicatedId(labels); + return labels.stream() + .map(labelId -> labelService.validateLabelsId(labelId)) + .map(existLabel -> issueRepository.insertLabels(savedIssueId, existLabel.getId())) + .collect(Collectors.toList()); + } + + private List insertAssignee(List assignees, Long savedIssueId) { + duplicatedId(assignees); + return assignees.stream() + .map(assigneesId -> userService.validateUserId(assigneesId)) + .map(existUser -> issueRepository.insertAssignees(savedIssueId, existUser.getId())) + .collect(Collectors.toList()); + } + private void duplicatedId(List list) { Set set = new HashSet<>(); for (Long temp : list) {