Skip to content

Commit

Permalink
fix: pass user as parameter instead auth when call service method
Browse files Browse the repository at this point in the history
  • Loading branch information
weejihye committed Jan 20, 2024
1 parent 70ea0a5 commit 571291d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -44,7 +45,7 @@ public ShowcaseResponse getShowcase(@PathVariable Long showcaseId, Authenticatio

@PutMapping("/edit/{showcaseId}")
public ResponseEntity<Object> 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}")
Expand All @@ -61,7 +62,6 @@ public Long createShowcase(@RequestBody @Valid ShowcaseCreateDto request, Authen

@DeleteMapping("/{showcaseId}")
public ResponseEntity<Object> deleteShowcase(@PathVariable Long showcaseId, Authentication auth){
return showcaseService.deleteShowcase(showcaseId, auth);
return showcaseService.deleteShowcase(showcaseId, User.authenticationToUser(auth));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ public Long createShowcase(ShowcaseCreateDto request, Authentication auth){
}

@Transactional
public ResponseEntity<Object> updateShowcase(Long showcaseId, ShowcaseUpdateDto request, Authentication auth){
public ResponseEntity<Object> 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();
Expand All @@ -221,11 +221,11 @@ public ResponseEntity<Object> updateShowcase(Long showcaseId, ShowcaseUpdateDto
}

@Transactional
public ResponseEntity<Object> deleteShowcase(Long showcaseId, Authentication auth){
public ResponseEntity<Object> 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());
Expand Down

0 comments on commit 571291d

Please sign in to comment.