From 646d27dada756c4052de9460d7c1522c2f64e0eb Mon Sep 17 00:00:00 2001 From: Miensoap Date: Wed, 22 May 2024 22:41:52 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A7=88=EC=9D=BC=EC=8A=A4=ED=86=A4=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=98=A4=EB=A5=98=20=EC=9E=84=EC=8B=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 마일스톤 오류 수정 2 : 인가 마일스톤 수정 3.. --- .../domain/milestone/MilestoneController.java | 6 ++--- .../domain/milestone/MilestoneService.java | 22 +++++++++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/be/issue_tracker/src/main/java/team1/issuetracker/domain/milestone/MilestoneController.java b/be/issue_tracker/src/main/java/team1/issuetracker/domain/milestone/MilestoneController.java index 497b7d343..ab23fe208 100644 --- a/be/issue_tracker/src/main/java/team1/issuetracker/domain/milestone/MilestoneController.java +++ b/be/issue_tracker/src/main/java/team1/issuetracker/domain/milestone/MilestoneController.java @@ -29,10 +29,10 @@ public List milestoneList() { @Authenticate @PostMapping - public Milestone createMilestone(@RequestBody MilestoneMakeRequest milestoneMakeRequest, @AuthenticatedUserId String userId) + public MilestoneListResponse createMilestone(@RequestBody MilestoneMakeRequest milestoneMakeRequest, @AuthenticatedUserId String userId) throws IllegalArgumentException { - return milestoneService.createMilestone(milestoneMakeRequest.name(), milestoneMakeRequest.description(), - milestoneMakeRequest.deadline(), userId); + return MilestoneListResponse.of(milestoneService.createMilestone(milestoneMakeRequest.name(), milestoneMakeRequest.description(), + milestoneMakeRequest.deadline(), userId)); } @Authenticate diff --git a/be/issue_tracker/src/main/java/team1/issuetracker/domain/milestone/MilestoneService.java b/be/issue_tracker/src/main/java/team1/issuetracker/domain/milestone/MilestoneService.java index 18e998b9d..54e6ee0fb 100644 --- a/be/issue_tracker/src/main/java/team1/issuetracker/domain/milestone/MilestoneService.java +++ b/be/issue_tracker/src/main/java/team1/issuetracker/domain/milestone/MilestoneService.java @@ -1,11 +1,9 @@ package team1.issuetracker.domain.milestone; -import java.util.Date; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.relational.core.conversion.DbActionExecutionException; import org.springframework.stereotype.Service; import team1.issuetracker.domain.Issue.Issue; import team1.issuetracker.domain.milestone.dto.MilestoneInfo; @@ -47,8 +45,18 @@ public MilestoneShowResponse getMilestoneAtIssue(Issue issue) { } public Milestone createMilestone(String name, String description, Date deadline, String userId) { - Milestone milestone = Milestone.builder().name(name).description(description).deadline(deadline).userId(userId).build(); - return milestoneRepository.save(milestone); + Milestone milestone = Milestone.builder() + .name(name) + .description(description) + .deadline(deadline) + .userId(userId) + .issues(new HashSet<>()) + .build(); + try { + return milestoneRepository.save(milestone); + }catch (DbActionExecutionException failToCreate){ + throw new IllegalArgumentException("마일스톤 제목은 중복될 수 없습니다! 다시 확인하세요!"); + } } public void deleteMilestone(Long id, String userId) { @@ -79,7 +87,7 @@ public Milestone updateMilestone(MilestoneMakeRequest milestoneMakeRequest, Long @Override public Milestone authorize(Long milestoneId, String userId) { Milestone milestone = getMilestoneById(milestoneId); - if (milestone.getUserId().equals(userId)) { + if (!milestone.getUserId().equals(userId)) { throw new AuthorizeException(milestoneId + "번 마일스톤에 대한 권한이 없습니다."); }