Skip to content

Commit 73c6549

Browse files
committed
[Feat] : Long userId = jwtUtil.getUserId(access); 사용
1 parent 6f34b2e commit 73c6549

16 files changed

Lines changed: 75 additions & 77 deletions

File tree

src/main/java/com/potato/balbambalbam/card/cardFeedback/controller/CardFeedbackController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public ResponseEntity<Object> postUserFeedback(@PathVariable("cardId") Long card
4646
@RequestHeader("access") String access,
4747
@Validated @RequestBody UserFeedbackRequestDto userFeedbackRequestDto) {
4848

49-
Long userId = joinService.findUserBySocialId(jwtUtil.getSocialId(access)).getId();
49+
Long userId = jwtUtil.getUserId(access);
5050

5151
UserFeedbackResponseDto userFeedbackResponseDto = cardFeedbackService.postUserFeedback(userFeedbackRequestDto, userId, cardId);
5252
userLevelService.updateUserLevelInfo(cardId, userId, userFeedbackResponseDto.getUserScore());
@@ -66,7 +66,7 @@ public ResponseEntity<Object> postUserFeedback(@PathVariable("cardId") Long card
6666
public ResponseEntity<Object> postCustomUserFeedback(@PathVariable("cardId") Long cardId,
6767
@Validated @RequestBody UserFeedbackRequestDto userFeedbackRequestDto,
6868
@RequestHeader("access") String access) {
69-
Long userId = joinService.findUserBySocialId(jwtUtil.getSocialId(access)).getId();
69+
Long userId = jwtUtil.getUserId(access);
7070

7171
UserFeedbackResponseDto userFeedbackResponseDto = customCardFeedbackService.postUserFeedback(userFeedbackRequestDto, cardId, userId);
7272
userLevelService.updateCustomCardUserLevelInfo(cardId, userId, userFeedbackResponseDto.getUserScore());
@@ -86,7 +86,7 @@ public ResponseEntity<Object> postCustomUserFeedback(@PathVariable("cardId") Lon
8686
public ResponseEntity<Object> postTodayCardUserFeedback(@PathVariable("cardId") Long cardId,
8787
@Validated @RequestBody UserFeedbackRequestDto userFeedbackRequestDto,
8888
@RequestHeader("access") String access) {
89-
Long userId = joinService.findUserBySocialId(jwtUtil.getSocialId(access)).getId();
89+
Long userId = jwtUtil.getUserId(access);
9090

9191
UserFeedbackResponseDto userFeedbackResponseDto = todayCardFeedbackService.postUserFeedback(userFeedbackRequestDto, cardId, userId);
9292
userLevelService.updateCustomCardUserLevelInfo(cardId, userId, userFeedbackResponseDto.getUserScore());

src/main/java/com/potato/balbambalbam/card/cardInfo/controller/CardInfoController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class CardInfoController {
4242
}
4343
)
4444
public ResponseEntity<CardInfoResponseDto> getCardInfo(@PathVariable("cardId") Long cardId, @RequestHeader("access") String access) {
45-
Long userId = joinService.findUserBySocialId(jwtUtil.getSocialId(access)).getId();
45+
Long userId = jwtUtil.getUserId(access);
4646
CardInfoResponseDto cardInfoResponseDto = cardInfoService.getCardInfo(userId, cardId);
4747
return ResponseEntity.ok().body(cardInfoResponseDto);
4848
}
@@ -56,7 +56,7 @@ public ResponseEntity<CardInfoResponseDto> getCardInfo(@PathVariable("cardId") L
5656
}
5757
)
5858
public ResponseEntity<CardInfoResponseDto> postCustomCardInfo(@PathVariable("cardId") Long cardId, @RequestHeader("access") String access) {
59-
Long userId = joinService.findUserBySocialId(jwtUtil.getSocialId(access)).getId();
59+
Long userId = jwtUtil.getUserId(access);
6060
CardInfoResponseDto cardInfoResponseDto = customCardInfoService.getCustomCardInfo(userId, cardId);
6161

6262
return ResponseEntity.ok().body(cardInfoResponseDto);
@@ -71,7 +71,7 @@ public ResponseEntity<CardInfoResponseDto> postCustomCardInfo(@PathVariable("car
7171
}
7272
)
7373
public ResponseEntity<TodayCardInfoResponseDto> postTodayCardInfo(@PathVariable("cardId") Long cardId, @RequestHeader("access") String access) {
74-
Long userId = joinService.findUserBySocialId(jwtUtil.getSocialId(access)).getId();
74+
Long userId = jwtUtil.getUserId(access);
7575
TodayCardInfoResponseDto cardInfoResponseDto = todayCardInfoService.getTodayCardInfo(userId, cardId);
7676

7777
return ResponseEntity.ok().body(cardInfoResponseDto);

src/main/java/com/potato/balbambalbam/card/todayCourse/controller/TodayCourseController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class TodayCourseController {
3737
})
3838
public ResponseEntity<TodayCourseResponseDto> getCardList(@RequestBody TodayCourseRequestDto requestDto,
3939
@RequestHeader("access") String access) {
40-
Long userId = joinService.findUserBySocialId(jwtUtil.getSocialId(access)).getId();
40+
Long userId = jwtUtil.getUserId(access);
4141

4242
TodayCourseResponseDto response = todayCourseService.getCardList(userId, requestDto);
4343

src/main/java/com/potato/balbambalbam/home/customCard/controller/CustomCardController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class CustomCardController {
3333
@ApiResponse(responseCode = "400", description = "ERROR : 카드를 생성 불가(10개 이상 or 한국어 X, 35자 이상)", content = @Content(schema = @Schema(implementation = ExceptionDto.class)))
3434
})
3535
public ResponseEntity<CustomCardResponseDto> postCustomCard(@Validated @RequestBody CustomCardRequestDto customCardRequestDto, @RequestHeader("access") String access) {
36-
Long userId = joinService.findUserBySocialId(jwtUtil.getSocialId(access)).getId();
36+
Long userId = jwtUtil.getUserId(access);
3737

3838
CustomCardResponseDto customCardResponse = customCardService.createCustomCardIfPossible(customCardRequestDto.getText(), userId);
3939

@@ -47,7 +47,7 @@ public ResponseEntity<CustomCardResponseDto> postCustomCard(@Validated @RequestB
4747
@ApiResponse(responseCode = "400", description = "ERROR : 카드 삭제 불가", content = @Content(schema = @Schema(implementation = ExceptionDto.class)))
4848
})
4949
public ResponseEntity deleteCustomCard(@PathVariable("cardId") Long cardId, @RequestHeader("access") String access) throws CardDeleteException {
50-
Long userId = joinService.findUserBySocialId(jwtUtil.getSocialId(access)).getId();
50+
Long userId = jwtUtil.getUserId(access);
5151

5252
boolean isDeleted = customCardService.deleteCustomCard(userId, cardId);
5353

src/main/java/com/potato/balbambalbam/home/customCard/controller/CustomCardListController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class CustomCardListController {
3838
@ApiResponse(responseCode = "400", description = "ERROR : 존재하지 않는 카테고리 조회", content = @Content(schema = @Schema(implementation = ExceptionDto.class)))
3939
})
4040
public ResponseEntity<CardListResponseDto<List<CustomCardDto>>> getCustomCardList(@RequestHeader("access") String access) {
41-
Long userId = joinService.findUserBySocialId(jwtUtil.getSocialId(access)).getId();
41+
Long userId = jwtUtil.getUserId(access);
4242

4343
List<CustomCardDto> cardDtoList = cardListService.getCustomCards(userId);
4444
CardListResponseDto<List<CustomCardDto>> response = new CardListResponseDto<>(cardDtoList, cardDtoList.size());

src/main/java/com/potato/balbambalbam/home/learningCourse/controller/CardListController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class CardListController {
3737
})
3838
public ResponseEntity<CardListResponseDto<List<ResponseCardDto>>> getCardList(@RequestParam("level") Long level,
3939
@RequestHeader("access") String access){
40-
Long userId = joinService.findUserBySocialId(jwtUtil.getSocialId(access)).getId();
40+
Long userId = jwtUtil.getUserId(access);
4141

4242
List<ResponseCardDto> cardDtoList = cardListService.getCardsByCategory(level, userId);
4343
CardListResponseDto<List<ResponseCardDto>> response = new CardListResponseDto<>(cardDtoList, cardDtoList.size());
@@ -53,7 +53,7 @@ public ResponseEntity<CardListResponseDto<List<ResponseCardDto>>> getCardList(@R
5353
@ApiResponse(responseCode = "400", description = "ERROR : 조회 실패", content = @Content(schema = @Schema(implementation = ExceptionDto.class)))
5454
})
5555
public ResponseEntity<CourseResponseDto> getCourseList(@RequestHeader("access") String access){
56-
Long userId = joinService.findUserBySocialId(jwtUtil.getSocialId(access)).getId();
56+
Long userId = jwtUtil.getUserId(access);
5757

5858
CourseResponseDto response = cardListService.getCourseList(userId);
5959

@@ -68,7 +68,7 @@ public ResponseEntity<CourseResponseDto> getCourseList(@RequestHeader("access")
6868
@ApiResponse(responseCode = "400", description = "ERROR : 존재하지 않는 카드", content = @Content(schema = @Schema(implementation = ExceptionDto.class)))
6969
})
7070
public ResponseEntity updateCardBookmark(@PathVariable("cardId") Integer cardId, @RequestHeader("access") String access){
71-
Long userId = joinService.findUserBySocialId(jwtUtil.getSocialId(access)).getId();
71+
Long userId = jwtUtil.getUserId(access);
7272

7373
String message = cardListService.toggleCardBookmark(Long.valueOf(cardId), userId);
7474
return ResponseEntity.ok().body(message);

src/main/java/com/potato/balbambalbam/home/menu/controller/BookmarkCardsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class BookmarkCardsController {
3434
@ApiResponse(responseCode = "400", description = "ERROR : 존재하지 않는 카테고리 조회", content = @Content(schema = @Schema(implementation = ExceptionDto.class)))
3535
})
3636
public ResponseEntity<BookmarkCardResponseDto> getCardList(@RequestHeader("access") String access) {
37-
Long userId = joinService.findUserBySocialId(jwtUtil.getSocialId(access)).getId();
37+
Long userId = jwtUtil.getUserId(access);
3838

3939
BookmarkCardResponseDto responseDto = bookmarkCardsService.getCards(userId);
4040
return ResponseEntity.ok().body(responseDto);

src/main/java/com/potato/balbambalbam/home/menu/controller/MissedCardsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class MissedCardsController {
3434
@ApiResponse(responseCode = "400", description = "ERROR : 존재하지 않는 카테고리 조회", content = @Content(schema = @Schema(implementation = ExceptionDto.class)))
3535
})
3636
public ResponseEntity<MissedCardResponseDto> getCardList(@RequestHeader("access") String access) {
37-
Long userId = joinService.findUserBySocialId(jwtUtil.getSocialId(access)).getId();
37+
Long userId = jwtUtil.getUserId(access);
3838

3939
MissedCardResponseDto responseDto = missedCardsService.getCards(userId);
4040

src/main/java/com/potato/balbambalbam/myReport/report/controller/ReportController.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,14 @@ public class ReportController {
2525
private final JWTUtil jwtUtil;
2626
private final ReportInfoService reportInfoService;
2727

28-
private Long extractUserIdFromToken(String access) { // access 토큰으로부터 userId 추출하는 함수
29-
String socialId = jwtUtil.getSocialId(access);
30-
return joinService.findUserBySocialId(socialId).getId();
31-
}
32-
3328
@Operation(summary = "My report 화면 정보 조회", description = "My report 화면에 필요한 모든 정보를 반환한다.")
3429
@ApiResponses(value = {
3530
@ApiResponse(responseCode = "200", description = "My report 화면 정보 조회 성공", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ReportInfoDto.class))),
3631
@ApiResponse(responseCode = "500", description = "서버 오류 발생", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionDto.class)))
3732
})
3833
@GetMapping("/report")
3934
public ResponseEntity<ReportInfoDto> getHomeInfo(@RequestHeader("access") String access) {
40-
Long userId = extractUserIdFromToken(access);
35+
Long userId = jwtUtil.getUserId(access);
4136
ReportInfoDto response = reportInfoService.getMyReportInfo(userId);
4237
return ResponseEntity.ok(response);
4338
}

src/main/java/com/potato/balbambalbam/myReport/test/controller/WeakSoundTestController.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,13 @@ public class WeakSoundTestController {
3737
private final JWTUtil jwtUtil;
3838
private final WeakSoundTestService weakSoundTestService;
3939

40-
private Long extractUserIdFromToken(String access) {
41-
String socialId = jwtUtil.getSocialId(access);
42-
return joinService.findUserBySocialId(socialId).getId();
43-
}
44-
4540
@Operation(summary = "취약음소 테스트 존재 여부 확인", description = "이전에 진행중이던 테스트가 있는지 확인한다.")
4641
@ApiResponses(value = {
4742
@ApiResponse(responseCode = "200", description = "확인 완료", content = @Content(mediaType = "application/json", schema = @Schema(implementation = TestStartResponseDto.class)))
4843
})
4944
@GetMapping("/test/check")
5045
public ResponseEntity<TestStartResponseDto> checkTest(@RequestHeader("access") String access) {
51-
Long userId = extractUserIdFromToken(access);
46+
Long userId = jwtUtil.getUserId(access);
5247
TestStartResponseDto response = weakSoundTestService.checkTestStatus(userId);
5348
return ResponseEntity.ok(response);
5449
}
@@ -59,7 +54,7 @@ public ResponseEntity<TestStartResponseDto> checkTest(@RequestHeader("access") S
5954
})
6055
@PostMapping("/test/new")
6156
public ResponseEntity<List<WeakSoundTestListDto>> startNewTest(@RequestHeader("access") String access) {
62-
Long userId = extractUserIdFromToken(access);
57+
Long userId = jwtUtil.getUserId(access);
6358
weakSoundTestService.startNewTest(userId);
6459
return ResponseEntity.ok(weakSoundTestService.getAllTests());
6560
}
@@ -71,7 +66,7 @@ public ResponseEntity<List<WeakSoundTestListDto>> startNewTest(@RequestHeader("a
7166
})
7267
@GetMapping("/test/continue")
7368
public ResponseEntity<List<WeakSoundTestListDto>> continueTest(@RequestHeader("access") String access) {
74-
Long userId = extractUserIdFromToken(access);
69+
Long userId = jwtUtil.getUserId(access);
7570
List<WeakSoundTestListDto> remainingTests = weakSoundTestService.getContinueTests(userId);
7671
return ResponseEntity.ok(remainingTests);
7772
}
@@ -85,7 +80,7 @@ public ResponseEntity<List<WeakSoundTestListDto>> continueTest(@RequestHeader("a
8580
})
8681
@PostMapping(value = "/test/{cardId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
8782
public ResponseEntity<String> uploadFile(@PathVariable("cardId") Long id, @RequestHeader("access") String access, @RequestParam("userAudio") MultipartFile userAudio) throws IOException {
88-
Long userId = extractUserIdFromToken(access);
83+
Long userId = jwtUtil.getUserId(access);
8984

9085
if (userAudio.isEmpty()) {
9186
throw new ParameterNotFoundException("사용자 음성 파일이 비었습니다.");
@@ -106,7 +101,7 @@ public ResponseEntity<String> uploadFile(@PathVariable("cardId") Long id, @Reque
106101
})
107102
@PostMapping("/test/finalize")
108103
public ResponseEntity<Map<Long, Integer>> finalizeAnalysis(@RequestHeader("access") String access) {
109-
Long userId = extractUserIdFromToken(access);
104+
Long userId = jwtUtil.getUserId(access);
110105
Map<Long, Integer> topPhonemes = weakSoundTestService.getTopPhonemes(userId);
111106
weakSoundTestService.finalizeTestStatus(userId);
112107
return ResponseEntity.ok(topPhonemes);

0 commit comments

Comments
 (0)