Skip to content

Commit fbb7ac6

Browse files
committed
refactor(review): @AuthenticationPrincipal 을 사용하여 userId 가져오도록 변경
1 parent d2bfe3c commit fbb7ac6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/main/java/com/somemore/review/controller/ReviewCommandApiController.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import java.util.UUID;
1414
import lombok.RequiredArgsConstructor;
1515
import org.springframework.security.access.annotation.Secured;
16-
import org.springframework.security.core.context.SecurityContextHolder;
16+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
1717
import org.springframework.web.bind.annotation.PostMapping;
1818
import org.springframework.web.bind.annotation.RequestMapping;
1919
import org.springframework.web.bind.annotation.RequestPart;
@@ -33,19 +33,20 @@ public class ReviewCommandApiController {
3333
@Operation(summary = "리뷰 등록", description = "리뷰를 등록합니다.")
3434
@PostMapping(value = "/review", consumes = MULTIPART_FORM_DATA_VALUE)
3535
public ApiResponse<Long> createReview(
36+
@AuthenticationPrincipal String userId,
3637
@Valid @RequestPart("data") ReviewCreateRequestDto requestDto,
3738
@RequestPart(value = "img_file", required = false) MultipartFile image) {
3839

3940
String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image));
4041
return ApiResponse.ok(
4142
201,
42-
createReviewUseCase.createReview(requestDto, getId(), imgUrl),
43+
createReviewUseCase.createReview(requestDto, getId(userId), imgUrl),
4344
"리뷰 등록 성공"
4445
);
4546
}
4647

47-
private static UUID getId() {
48-
return UUID.fromString(SecurityContextHolder.getContext().getAuthentication().getName());
48+
private static UUID getId(String id) {
49+
return UUID.fromString(id);
4950
}
5051

5152
}

0 commit comments

Comments
 (0)