Skip to content

Commit

Permalink
마일스톤 생성 오류 임시 수정
Browse files Browse the repository at this point in the history
마일스톤 오류 수정 2 : 인가

마일스톤 수정 3..
  • Loading branch information
Miensoap committed May 22, 2024
1 parent 3cd026b commit 646d27d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public List<MilestoneListResponse> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 + "번 마일스톤에 대한 권한이 없습니다.");
}

Expand Down

0 comments on commit 646d27d

Please sign in to comment.