From 571291ded0534b4c5dcadb98520b7511d4608706 Mon Sep 17 00:00:00 2001 From: weejihye Date: Sat, 20 Jan 2024 17:45:15 +0900 Subject: [PATCH] fix: pass user as parameter instead auth when call service method --- .../peer/backend/controller/board/ShowcaseController.java | 6 +++--- .../peer/backend/service/board/team/ShowcaseService.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/peer/backend/controller/board/ShowcaseController.java b/src/main/java/peer/backend/controller/board/ShowcaseController.java index 59195976..86e48905 100644 --- a/src/main/java/peer/backend/controller/board/ShowcaseController.java +++ b/src/main/java/peer/backend/controller/board/ShowcaseController.java @@ -7,6 +7,7 @@ import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.*; import peer.backend.dto.board.team.*; +import peer.backend.entity.user.User; import peer.backend.service.board.team.ShowcaseService; import peer.backend.service.profile.UserPortfolioService; @@ -44,7 +45,7 @@ public ShowcaseResponse getShowcase(@PathVariable Long showcaseId, Authenticatio @PutMapping("/edit/{showcaseId}") public ResponseEntity updateShowcase(@PathVariable Long showcaseId, @RequestBody ShowcaseUpdateDto request, Authentication auth){ - return showcaseService.updateShowcase(showcaseId, request, auth); + return showcaseService.updateShowcase(showcaseId, request, User.authenticationToUser(auth)); } @GetMapping("/write/{teamId}") @@ -61,7 +62,6 @@ public Long createShowcase(@RequestBody @Valid ShowcaseCreateDto request, Authen @DeleteMapping("/{showcaseId}") public ResponseEntity deleteShowcase(@PathVariable Long showcaseId, Authentication auth){ - return showcaseService.deleteShowcase(showcaseId, auth); + return showcaseService.deleteShowcase(showcaseId, User.authenticationToUser(auth)); } - } diff --git a/src/main/java/peer/backend/service/board/team/ShowcaseService.java b/src/main/java/peer/backend/service/board/team/ShowcaseService.java index a669784b..36d7a579 100644 --- a/src/main/java/peer/backend/service/board/team/ShowcaseService.java +++ b/src/main/java/peer/backend/service/board/team/ShowcaseService.java @@ -205,11 +205,11 @@ public Long createShowcase(ShowcaseCreateDto request, Authentication auth){ } @Transactional - public ResponseEntity updateShowcase(Long showcaseId, ShowcaseUpdateDto request, Authentication auth){ + public ResponseEntity updateShowcase(Long showcaseId, ShowcaseUpdateDto request, User user){ Post post = postRepository.findById(showcaseId) .orElseThrow(() -> new NotFoundException("존재하지 않는 게시글입니다.")); Team team = post.getBoard().getTeam(); - if (!teamService.isLeader(team.getId(), User.authenticationToUser(auth))) + if (!teamService.isLeader(team.getId(), user)) throw new ForbiddenException("리더가 아닙니다."); String filePath = "team/showcase/" + post.getBoard().getTeam().getName(); String temp = post.getFiles().get(0).getUrl(); @@ -221,11 +221,11 @@ public ResponseEntity updateShowcase(Long showcaseId, ShowcaseUpdateDto } @Transactional - public ResponseEntity deleteShowcase(Long showcaseId, Authentication auth){ + public ResponseEntity deleteShowcase(Long showcaseId, User user){ Post post = postRepository.findById(showcaseId) .orElseThrow(() -> new NotFoundException("존재하지 않는 게시글입니다.")); Team team = post.getBoard().getTeam(); - if (!teamService.isLeader(team.getId(), User.authenticationToUser(auth))) + if (!teamService.isLeader(team.getId(), user)) throw new ForbiddenException("리더가 아닙니다."); objectService.deleteObject(post.getFiles().get(0).getUrl()); boardRepository.delete(post.getBoard());