Skip to content

Commit

Permalink
fix: loginresponse role 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
KEEKE132 committed May 26, 2024
1 parent abd9cca commit 9599078
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void issueModify(@RequestBody IssueRequest issueRequest,@RequestParam("is
@PostMapping("/assignees")
public void issueSetAssignee(@RequestBody IssueRequest issueRequest,@RequestParam("issueId") Long issueid){
Issue issue = this.issueService.getIssue(issueid);
this.issueService.setAssignee(issue,issueRequest.getUserid());
this.issueService.setAssignee(issue,issueRequest.getUserid(),issueRequest.getAssigneeid());
}

@GetMapping("/{status}")
Expand All @@ -76,7 +76,7 @@ public ResponseEntity<List<IssueResponse>> issueCheckByStatus(@PathVariable("sta
@PatchMapping("/status")
public void issueChangeStatus(@RequestBody IssueRequest issueRequest,@RequestParam("issueId") Long issueid){
Issue issue = this.issueService.getIssue(issueid);
this.issueService.changeStatus(issueRequest,issue);
this.issueService.changeStatus(issueRequest.getUserid(),issue);
}

@GetMapping("/assigned")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public class IssueRequest {

private Long userid;

private Long assigneeid;

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public Issue create(Long projectid, String title, String description, Long repor
issue.setProject(project);
issue.setTitle(title);
issue.setDescription(description);
issue.setPriority(priority);
if(priority!=null) {
issue.setPriority(priority);
}
issue.setReporter(userRepository.findById(reporterid).orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND)));
issue.setCreated_at(LocalDateTime.now());
this.issueRepository.save(issue);
Expand Down Expand Up @@ -80,19 +82,23 @@ public void delete(Issue issue){
this.issueRepository.delete(issue);
}

public void setAssignee(Issue issue, Long assigneeid){
public void setAssignee(Issue issue,Long userid ,Long assigneeid){
User user = this.userRepository.findById(userid).orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
if (user.getRole() != "PL") {
throw new CustomException(ErrorCode.ROLE_FORBIDDEN);
}
issue.setAssignee(userRepository.findById(assigneeid).orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND)));
this.issueRepository.save(issue);
}

public void changeStatus(IssueRequest issueRequest, Issue issue){
public void changeStatus(Long userid, Issue issue){
if(issue.getStatus()== Issue.Status.NEW){
issue.setStatus(Issue.Status.ASSIGNED);
issue.setAssignee(this.userRepository.findById(issueRequest.getUserid()).orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND)));
issue.setAssignee(this.userRepository.findById(userid).orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND)));
}
else if(issue.getStatus()== Issue.Status.ASSIGNED){
issue.setStatus(Issue.Status.FIXED);
issue.setFixer(this.userRepository.findById(issueRequest.getUserid()).orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND)));
issue.setFixer(this.userRepository.findById(userid).orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND)));
}
else if(issue.getStatus()== Issue.Status.FIXED){
issue.setStatus(Issue.Status.RESOLVED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ public class LoginResponse {
@NotBlank
private final String username;

private final String role;

public LoginResponse(User user) {
this.userId = user.getId();
this.username = user.getUsername();
this.role = user.getRole();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class IssueTrackingSystemApplicationTests {
Admin: 27
Dev: 28,29
Project: 27
Issue: 12 (Assigned 29)
Issue: 12,25 (Assigned 29)
*/

Expand Down

0 comments on commit 9599078

Please sign in to comment.