diff --git a/src/main/java/umc/kkijuk/server/auth/service/KakaoAuthService.java b/src/main/java/umc/kkijuk/server/auth/service/KakaoAuthService.java index 0eee8b05..6e3fa187 100644 --- a/src/main/java/umc/kkijuk/server/auth/service/KakaoAuthService.java +++ b/src/main/java/umc/kkijuk/server/auth/service/KakaoAuthService.java @@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.http.*; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; @@ -39,6 +40,7 @@ public class KakaoAuthService { @Value("${spring.security.oauth2.client.registration.kakao.redirect-uri}") private String redirectUri; + @Transactional public String getKakaoAccessToken(String code) { String tokenUri = "https://kauth.kakao.com/oauth/token"; @@ -71,6 +73,7 @@ public String getKakaoAccessToken(String code) { } + @Transactional public Map getKakaoUserInfo(String accessToken) { String userInfoUri = "https://kapi.kakao.com/v2/user/me"; @@ -89,6 +92,7 @@ public Map getKakaoUserInfo(String accessToken) { } } + @Transactional public Member processKakaoUser(String accessToken) { Map kakaoUserInfo = getKakaoUserInfo(accessToken); String kakaoId = kakaoUserInfo.get("id").toString(); @@ -106,6 +110,7 @@ public Member processKakaoUser(String accessToken) { }); } + @Transactional public Map generateTokens(Member member) { String kakaoId = String.valueOf(member.getSocialId()); @@ -114,6 +119,9 @@ public Map generateTokens(Member member) { log.info("JWT 토큰 생성 완료 - 카카오 ID: {}, accessToken: {}, refreshToken: {}", kakaoId, accessToken, refreshToken); + member.setRefreshToken(refreshToken); + memberRepository.save(member); + Map tokens = new HashMap<>(); tokens.put("accessToken", accessToken); tokens.put("refreshToken", refreshToken); diff --git a/src/main/java/umc/kkijuk/server/career/controller/BaseCareerController.java b/src/main/java/umc/kkijuk/server/career/controller/BaseCareerController.java index a817ad2f..02b14f46 100644 --- a/src/main/java/umc/kkijuk/server/career/controller/BaseCareerController.java +++ b/src/main/java/umc/kkijuk/server/career/controller/BaseCareerController.java @@ -22,14 +22,15 @@ public class BaseCareerController { private final BaseCareerService baseCareerService; private final MemberService memberService; + private final LoginUser loginUser; @PostMapping("/activity") @Operation(summary = "커리어(대외활동) 생성", description = "주어진 정보를 바탕으로 활동을 추가합니다.") - public CareerResponse createActivity( + public CareerResponse createActivity(@RequestHeader("Authorization") String token, @RequestBody @Valid ActivityReqDto activityReqDto ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_CREATE_SUCCESS, @@ -41,11 +42,12 @@ public CareerResponse createActivity( @Operation(summary = "커리어(대외활동) 수정", description = "활동 ID에 해당하는 활동을 수정합니다.") @Parameter(name = "activityId", description = "커리어(대외활동) Id, path variable 입니다.", example = "1") public CareerResponse updateActivity( + @RequestHeader("Authorization") String token, @PathVariable Long activityId, @Valid @RequestBody ActivityReqDto activityReqDto ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_UPDATE_SUCCESS, baseCareerService.updateActivity(requestMember, activityId, activityReqDto) @@ -55,10 +57,11 @@ public CareerResponse updateActivity( @PostMapping("/circle") @Operation(summary = "커리어(동아리) 생성", description = "주어진 정보를 바탕으로 활동을 추가합니다.") public CareerResponse createCircle( + @RequestHeader("Authorization") String token, @Valid @RequestBody CircleReqDto circleReqDto ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_CREATE_SUCCESS, baseCareerService.createCircle(requestMember, circleReqDto) @@ -69,11 +72,12 @@ public CareerResponse createCircle( @Operation(summary = "커리어(동아리) 수정", description = "활동 ID에 해당하는 활동을 수정합니다.") @Parameter(name = "circleId", description = "커리어(동아리) Id, path variable 입니다.", example = "1") public CareerResponse updateCircle( + @RequestHeader("Authorization") String token, @PathVariable Long circleId, @Valid @RequestBody CircleReqDto circleReqDto ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_UPDATE_SUCCESS, baseCareerService.updateCircle(requestMember, circleId, circleReqDto) @@ -83,10 +87,11 @@ public CareerResponse updateCircle( @PostMapping("/competition") @Operation(summary = "커리어(대회) 생성", description = "주어진 정보를 바탕으로 활동을 추가합니다.") public CareerResponse createComp( + @RequestHeader("Authorization") String token, @Valid @RequestBody CompetitionReqDto competitionReqDto ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_CREATE_SUCCESS, baseCareerService.createCompetition(requestMember, competitionReqDto) @@ -97,11 +102,12 @@ public CareerResponse createComp( @Operation(summary = "커리어(대회) 수정", description = "활동 ID에 해당하는 활동을 수정합니다.") @Parameter(name = "competitionId", description = "커리어(대회) Id, path variable 입니다.", example = "1") public CareerResponse updateComp( + @RequestHeader("Authorization") String token, @PathVariable Long competitionId, @Valid @RequestBody CompetitionReqDto competitionReqDto ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_UPDATE_SUCCESS, baseCareerService.updateComp(requestMember, competitionId, competitionReqDto) @@ -111,10 +117,11 @@ public CareerResponse updateComp( @PostMapping("/educareer") @Operation(summary = "커리어(교육) 생성", description = "주어진 정보를 바탕으로 활동을 추가합니다.") public CareerResponse createEdu( + @RequestHeader("Authorization") String token, @Valid @RequestBody EduCareerReqDto eduCareerReqDto ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_CREATE_SUCCESS, baseCareerService.crateEduCareer(requestMember, eduCareerReqDto) @@ -125,11 +132,12 @@ public CareerResponse createEdu( @Operation(summary = "커리어(교육) 수정", description = "활동 ID에 해당하는 활동을 수정합니다.") @Parameter(name = "educareerId", description = "커리어(교육) Id, path variable 입니다.", example = "1") public CareerResponse updateEdu( + @RequestHeader("Authorization") String token, @PathVariable Long educareerId, @Valid @RequestBody EduCareerReqDto eduCareerReqDto ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_UPDATE_SUCCESS, baseCareerService.updateEdu(requestMember, educareerId, eduCareerReqDto) @@ -139,10 +147,11 @@ public CareerResponse updateEdu( @PostMapping("/employment") @Operation(summary = "커리어(경력) 생성", description = "주어진 정보를 바탕으로 활동을 추가합니다.") public CareerResponse createEmp( + @RequestHeader("Authorization") String token, @Valid @RequestBody EmploymentReqDto employmentReqDto ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_CREATE_SUCCESS, baseCareerService.createEmployment(requestMember, employmentReqDto) @@ -153,11 +162,12 @@ public CareerResponse createEmp( @Operation(summary = "커리어(경력) 수정", description = "활동 ID에 해당하는 활동을 수정합니다.") @Parameter(name = "employmentId", description = "커리어(아르바이트/인턴) Id, path variable 입니다.", example = "1") public CareerResponse updateEmp( + @RequestHeader("Authorization") String token, @PathVariable Long employmentId, @Valid @RequestBody EmploymentReqDto employmentReqDto ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_UPDATE_SUCCESS, baseCareerService.updateEmp(requestMember, employmentId, employmentReqDto) @@ -167,10 +177,11 @@ public CareerResponse updateEmp( @PostMapping("/project") @Operation(summary = "커리어(프로젝트) 생성", description = "주어진 정보를 바탕으로 활동을 추가합니다.") public CareerResponse createProject( + @RequestHeader("Authorization") String token, @Valid @RequestBody ProjectReqDto projectReqDto ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_CREATE_SUCCESS, baseCareerService.createProject(requestMember, projectReqDto) @@ -181,11 +192,12 @@ public CareerResponse createProject( @Operation(summary = "커리어(프로젝트) 수정", description = "활동 ID에 해당하는 활동을 수정합니다.") @Parameter(name = "projectId", description = "커리어(프로젝트) Id, path variable 입니다.", example = "1") public CareerResponse updateProject( + @RequestHeader("Authorization") String token, @PathVariable Long projectId, @Valid @RequestBody ProjectReqDto projectReqDto ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_UPDATE_SUCCESS, baseCareerService.updateProject(requestMember, projectId, projectReqDto) @@ -197,10 +209,11 @@ public CareerResponse updateProject( summary = "활동 목록", description = "활동을 조회합니다. query 값으로 category(카테고리 기준), year(연도 기준), 또는 all(전체 조회) 중 하나를 선택하여 요청해주세요.") public CareerResponse findAllCareersGroupedYear( + @RequestHeader("Authorization") String token, @RequestParam(name = "status") String value ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); if (value.equals("category")) { return CareerResponse.success( CareerResponseMessage.CAREER_FINDALL_SUCCESS, @@ -221,11 +234,12 @@ public CareerResponse findAllCareersGroupedYear( @DeleteMapping("/{type}/{careerId}") @Operation(summary = "커리어 삭제", description = "활동의 type과 ID에 해당하는 활동을 삭제합니다.") public CareerResponse deleteBaseCareer( + @RequestHeader("Authorization") String token, @PathVariable String type, @PathVariable Long careerId ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); baseCareerService.deleteBaseCareer(requestMember, careerId, type); return CareerResponse.success( CareerResponseMessage.CAREER_DELETE_SUCCESS, @@ -237,11 +251,12 @@ public CareerResponse deleteBaseCareer( @Operation(summary = "활동 상세", description = "활동 ID에 해당하는 활동의 세부 내용과, 활동 기록을 조회합니다.") @Parameter(name = "careerId", description = "활동 Id, path variable 입니다.", example = "1") public CareerResponse findCareer( + @RequestHeader("Authorization") String token, @PathVariable String type, @PathVariable Long careerId ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_FINDALL_SUCCESS, baseCareerService.findCareer(requestMember, careerId, type) @@ -252,11 +267,12 @@ public CareerResponse findCareer( @Operation(summary = "활동 내역 수정", description = "활동 ID에 해당하는 활동에 활동 내역을 추가합니다.") @Parameter(name = "careerId", description = "활동 Id, path variable 입니다.", example = "1") public CareerResponse createSummary( + @RequestHeader("Authorization") String token, @PathVariable Long careerId, @Valid @RequestBody CareerSummaryReqDto request ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_CREATE_SUCCESS, baseCareerService.createSummary(requestMember, careerId, request) @@ -268,11 +284,12 @@ public CareerResponse createSummary( summary = "활동 검색 - 활동 기록", description = "활동기록을 주어진 조건에 맞추어 조회합니다. query 값으로 검색어(keyword)와 정렬 기준(new,old)을 요청해주세요.") public CareerResponse> findDetail( + @RequestHeader("Authorization") String token, @RequestParam(name = "keyword") String keyword, @RequestParam(name = "sort") String sort ) { - Long loginUser = LoginUser.get().getId(); - Member reqeustMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member reqeustMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_FINDALL_SUCCESS, baseCareerService.findAllDetail(reqeustMember, keyword, sort) @@ -285,10 +302,11 @@ public CareerResponse> findDetail( description = "검색어를 포함하는 활동 태그들을 가나다 순으로 조회합니다. " + "query 값으로 검색어(keyword)를 요청해주세요. ") public CareerResponse> findTag( + @RequestHeader("Authorization") String token, @RequestParam(name = "keyword") String keyword ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_SEARCH_SUCCESS, baseCareerService.findAllTag(requestMember, keyword) @@ -301,11 +319,12 @@ public CareerResponse> findTag( description = "선택한 태그를 포함하는 활동 기록들을 조회합니다. " + " query 값으로 태그의 ID 와 정렬 기준(new,old)을 요청해주세요. ") public CareerResponse> findTagAndDetail( + @RequestHeader("Authorization") String token, @RequestParam(name = "tagId") Long tagId, @RequestParam(name = "sort") String sort ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_FINDALL_SUCCESS, baseCareerService.findAllDetailByTag(requestMember, tagId, sort) @@ -317,11 +336,12 @@ public CareerResponse> findTagAndDetail( summary = "활동 검색 - 활동", description = "활동을 주어진 조건에 맞추어 조회합니다. query 값으로 검색어(keyword)와 정렬 기준(new,old)을 요청해주세요.") public CareerResponse> findCareerWithKeyword( + @RequestHeader("Authorization") String token, @RequestParam(name = "keyword") String keyword, @RequestParam(name = "sort") String sort ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_FINDALL_SUCCESS, baseCareerService.findCareerWithKeyword(requestMember, keyword, sort) @@ -332,9 +352,11 @@ public CareerResponse> findCareerWithKeyword( @Operation( summary = "활동 타임라인", description = "타임라인에 필요한 활동 정보들을 조회합니다.") - public CareerResponse> findCareerForTimeline() { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public CareerResponse> findCareerForTimeline( + @RequestHeader("Authorization") String token + ) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerResponse.success( CareerResponseMessage.CAREER_FINDALL_SUCCESS, baseCareerService.findCareerForTimeline(requestMember) diff --git a/src/main/java/umc/kkijuk/server/common/LoginUser.java b/src/main/java/umc/kkijuk/server/common/LoginUser.java index dae65274..861f4091 100644 --- a/src/main/java/umc/kkijuk/server/common/LoginUser.java +++ b/src/main/java/umc/kkijuk/server/common/LoginUser.java @@ -1,29 +1,33 @@ package umc.kkijuk.server.common; import lombok.Getter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import umc.kkijuk.server.auth.jwt.JwtUtil; import umc.kkijuk.server.member.domain.Member; import umc.kkijuk.server.member.service.MemberService; @Getter +@Component public class LoginUser { private final JwtUtil jwtUtil; private final MemberService memberService; private Long id; - public LoginUser(JwtUtil jwtUtil, MemberService memberService, Long id) { + @Autowired + public LoginUser(JwtUtil jwtUtil, MemberService memberService) { this.jwtUtil = jwtUtil; this.memberService = memberService; - this.id = id; } - private static final LoginUser LOGIN_USER = new LoginUser( null, null,1L); +// private static final LoginUser LOGIN_USER = new LoginUser( null, null); - public static LoginUser get() { - return LOGIN_USER; - } +// public static LoginUser get() { +// return LOGIN_USER; +// } public Long extractMemberId(String bearerToken) { if (bearerToken == null || !bearerToken.startsWith("Bearer ")) { diff --git a/src/main/java/umc/kkijuk/server/dashboard/controller/DashBoardController.java b/src/main/java/umc/kkijuk/server/dashboard/controller/DashBoardController.java index 6552838f..0f8a64fe 100644 --- a/src/main/java/umc/kkijuk/server/dashboard/controller/DashBoardController.java +++ b/src/main/java/umc/kkijuk/server/dashboard/controller/DashBoardController.java @@ -6,6 +6,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import umc.kkijuk.server.common.LoginUser; @@ -25,20 +26,22 @@ public class DashBoardController { private final DashBoardService dashBoardService; private final MemberService memberService; + private final LoginUser loginUser; - private final Member requestMember = Member.builder() - .id(LoginUser.get().getId()) - .name("tester") - .build(); +// private final Member requestMember = Member.builder() +// .id(LoginUser.get().getId()) +// .name("tester") +// .build(); @Operation( summary = "메인화면 정보 보드", description = "메인화면에 사용자이름, 가입한 기간, 활동, 지원현황 갯수 데이터를 응답합니다.") @GetMapping("/user-info") public ResponseEntity getUserInfo( + @RequestHeader("Authorization") String token ) { - LoginUser loginUser = LoginUser.get(); - Member requestMember = memberService.getById(loginUser.getId()); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); DashBoardUserInfoResponse response = dashBoardService.getUserInfo(requestMember); return ResponseEntity .ok() @@ -51,9 +54,10 @@ public ResponseEntity getUserInfo( ) @GetMapping("/remind/recruit") public ResponseEntity getRemindRecruits( + @RequestHeader("Authorization") String token ) { - LoginUser loginUser = LoginUser.get(); - Member requestMember = memberService.getById(loginUser.getId()); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); RecruitRemindResponse response = dashBoardService.getTopTwoRecruitsByEndTime(requestMember); return ResponseEntity .ok() @@ -62,10 +66,10 @@ public ResponseEntity getRemindRecruits( @GetMapping("/introduce") @Operation(summary = "홈 자기소개서 작성 알림") - public ResponseEntity get( + public ResponseEntity get(@RequestHeader("Authorization") String token ){ - LoginUser loginUser = LoginUser.get(); - Member requestMember = memberService.getById(loginUser.getId()); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); List homeIntroduceResDtos = dashBoardService.getHomeIntro(requestMember); return ResponseEntity .status(HttpStatus.OK) diff --git a/src/main/java/umc/kkijuk/server/detail/controller/BaseCareerDetailController.java b/src/main/java/umc/kkijuk/server/detail/controller/BaseCareerDetailController.java index af1a8b64..6ecfdfe4 100644 --- a/src/main/java/umc/kkijuk/server/detail/controller/BaseCareerDetailController.java +++ b/src/main/java/umc/kkijuk/server/detail/controller/BaseCareerDetailController.java @@ -24,6 +24,7 @@ public class BaseCareerDetailController { private final MemberService memberService; private final BaseCareerDetailService careerDetailService; + private final LoginUser loginUser; @PostMapping("/{careerId}") @Operation(summary = "활동 기록 생성", description = "주어진 정보를 바탕으로 활동기록을 생성합니다.") @@ -31,11 +32,12 @@ public class BaseCareerDetailController { @Parameter(name = "careerId", description = "활동 Id, path variable 입니다."), }) public CareerDetailResponse create( + @RequestHeader("Authorization") String token, @PathVariable Long careerId, @RequestBody @Valid CareerDetailReqDto request ) { - LoginUser loginUser = LoginUser.get(); - Member requestMember = memberService.getById(loginUser.getId()); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerDetailResponse.success(HttpStatus.CREATED, "활동 기록을 성공적으로 생성했습니다.", careerDetailService.createDetail(requestMember, request, careerId) ); @@ -47,11 +49,12 @@ public CareerDetailResponse create( @Parameter(name = "detailId", description = "활동 기록 Id, path variable 입니다.") }) public CareerDetailResponse delete( + @RequestHeader("Authorization") String token, @PathVariable Long careerId, @PathVariable Long detailId ) { - LoginUser loginUser = LoginUser.get(); - Member requestMember = memberService.getById(loginUser.getId()); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); careerDetailService.deleteDetail(requestMember, careerId ,detailId); return CareerDetailResponse.success(HttpStatus.OK, "활동 기록을 성공적으로 삭제했습니다.",null); } @@ -63,12 +66,13 @@ public CareerDetailResponse delete( @Parameter(name = "detailId", description = "활동 기록 Id, path variable 입니다. ") }) public CareerDetailResponse update( + @RequestHeader("Authorization") String token, @PathVariable Long careerId, @PathVariable Long detailId, @RequestBody @Valid CareerDetailUpdateReqDto request ){ - LoginUser loginUser = LoginUser.get(); - Member requestMember = memberService.getById(loginUser.getId()); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return CareerDetailResponse.success( HttpStatus.OK, "활동 기록을 성공적으로 수정했습니다.", diff --git a/src/main/java/umc/kkijuk/server/introduce/controller/IntroduceController.java b/src/main/java/umc/kkijuk/server/introduce/controller/IntroduceController.java index 1e8a37a3..0a8bea33 100644 --- a/src/main/java/umc/kkijuk/server/introduce/controller/IntroduceController.java +++ b/src/main/java/umc/kkijuk/server/introduce/controller/IntroduceController.java @@ -28,13 +28,14 @@ public class IntroduceController { private final IntroduceService introduceService; private final MasterIntroduceService masterIntroduceService; private final MemberService memberService; + private final LoginUser loginUser; @PostMapping("/{recruitId}") @Operation(summary = "자기소개서 생성") - public ResponseEntity save( + public ResponseEntity save(@RequestHeader("Authorization") String token, @PathVariable("recruitId") Long recruitId, @RequestBody IntroduceReqDto introduceReqDto){ - LoginUser loginUser = LoginUser.get(); - Member requestMember = memberService.getById(loginUser.getId()); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); IntroduceResponse introduceResponse = introduceService.saveIntro(requestMember, recruitId, introduceReqDto); return ResponseEntity .status(HttpStatus.OK) @@ -43,10 +44,10 @@ public ResponseEntity save( @GetMapping("detail/{introId}") @Operation(summary = "자기소개서 개별 조회") - public ResponseEntity get( + public ResponseEntity get(@RequestHeader("Authorization") String token, @PathVariable("introId") Long introId){ - LoginUser loginUser = LoginUser.get(); - Member requestMember = memberService.getById(loginUser.getId()); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); IntroduceResponse introduceResponse = introduceService.getIntro(requestMember, introId); return ResponseEntity .status(HttpStatus.OK) @@ -55,9 +56,9 @@ public ResponseEntity get( @GetMapping("list") @Operation(summary = "자기소개서 목록 조회") - public ResponseEntity getList(){ - LoginUser loginUser = LoginUser.get(); - Member requestMember = memberService.getById(loginUser.getId()); + public ResponseEntity getList(@RequestHeader("Authorization") String token){ + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); List introduceListResponses = introduceService.getIntroList(requestMember); return ResponseEntity .status(HttpStatus.OK) @@ -66,10 +67,10 @@ public ResponseEntity getList(){ @PatchMapping("/{introId}") @Operation(summary = "자기소개서 수정") - public ResponseEntity update( + public ResponseEntity update(@RequestHeader("Authorization") String token, @PathVariable("introId") Long introId, @RequestBody IntroduceReqDto introduceReqDto) throws Exception { - LoginUser loginUser = LoginUser.get(); - Member requestMember = memberService.getById(loginUser.getId()); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); IntroduceResponse introduceResponse = introduceService.updateIntro(requestMember, introId, introduceReqDto); return ResponseEntity .status(HttpStatus.OK) @@ -78,10 +79,10 @@ public ResponseEntity update( @DeleteMapping("/{introId}") @Operation(summary = "자기소개서 삭제") - public ResponseEntity delete( + public ResponseEntity delete(@RequestHeader("Authorization") String token, @PathVariable("introId") Long introId){ - LoginUser loginUser = LoginUser.get(); - Member requestMember = memberService.getById(loginUser.getId()); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); Long intro_Id = introduceService.deleteIntro(requestMember, introId); return ResponseEntity .status(HttpStatus.OK) @@ -90,9 +91,11 @@ public ResponseEntity delete( @GetMapping("/search") @Operation(summary = "키워드로 자기소개서 문단 검색") - public ResponseEntity> searchIntroduceByKeyword(@RequestParam String keyword) { - LoginUser loginUser = LoginUser.get(); - Member requestMember = memberService.getById(loginUser.getId()); + public ResponseEntity> searchIntroduceByKeyword( + @RequestHeader("Authorization") String token, + @RequestParam String keyword) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); Map response = introduceService.searchIntroduceAndMasterByKeyword(keyword, requestMember); return ResponseEntity.status(HttpStatus.OK).body(response); } diff --git a/src/main/java/umc/kkijuk/server/introduce/controller/MasterIntroduceController.java b/src/main/java/umc/kkijuk/server/introduce/controller/MasterIntroduceController.java index 63081032..e8983093 100644 --- a/src/main/java/umc/kkijuk/server/introduce/controller/MasterIntroduceController.java +++ b/src/main/java/umc/kkijuk/server/introduce/controller/MasterIntroduceController.java @@ -25,17 +25,19 @@ public class MasterIntroduceController { private final MasterIntroduceService masterIntroduceService; private final MemberService memberService; + private final LoginUser loginUser; - private final Member requestMember = Member.builder() - .id(LoginUser.get().getId()) - .build(); +// private final Member requestMember = Member.builder() +// .id(LoginUser.get().getId()) +// .build(); @PostMapping @Operation(summary = "마스터 자기소개서 생성") - public ResponseEntity saveMasterIntro(@RequestBody IntroduceReqDto introduceReqDto) throws Exception { - LoginUser loginUser = LoginUser.get(); + public ResponseEntity saveMasterIntro(@RequestHeader("Authorization") String token, + @RequestBody IntroduceReqDto introduceReqDto) throws Exception { + Long memberId = loginUser.extractMemberId(token); MasterIntroduceResponse masterIntroduceResponse = - masterIntroduceService.saveMasterIntro(loginUser.getId(), introduceReqDto); + masterIntroduceService.saveMasterIntro(memberId, introduceReqDto); return ResponseEntity .status(HttpStatus.OK) .body(new BaseResponse<>(HttpStatus.OK.value(), "마스터 자기소개서 생성 완료", masterIntroduceResponse)); @@ -43,9 +45,9 @@ public ResponseEntity saveMasterIntro(@RequestBody IntroduceReqDto intro @GetMapping @Operation(summary = "마스터 자기소개서 조회") - public ResponseEntity getMasterIntro(){ - LoginUser loginUser = LoginUser.get(); - MasterIntroduceResponse masterIntroduceResponse = masterIntroduceService.getMasterIntro(loginUser.getId()); + public ResponseEntity getMasterIntro(@RequestHeader("Authorization") String token){ + Long memberId = loginUser.extractMemberId(token); + MasterIntroduceResponse masterIntroduceResponse = masterIntroduceService.getMasterIntro(memberId); return ResponseEntity .status(HttpStatus.OK) .body(new BaseResponse<>(HttpStatus.OK.value(), "마스터 자기소개서 조회 완료", masterIntroduceResponse)); @@ -53,10 +55,10 @@ public ResponseEntity getMasterIntro(){ @PatchMapping @Operation(summary = "마스터 자기소개서 수정") - public ResponseEntity updateMasterIntro( + public ResponseEntity updateMasterIntro(@RequestHeader("Authorization") String token, @RequestBody IntroduceReqDto introduceReqDto) throws Exception { - LoginUser loginUser = LoginUser.get(); - MasterIntroduceResponse masterIntroduceResponse = masterIntroduceService.updateMasterIntro(loginUser.getId(), introduceReqDto); + Long memberId = loginUser.extractMemberId(token); + MasterIntroduceResponse masterIntroduceResponse = masterIntroduceService.updateMasterIntro(memberId, introduceReqDto); return ResponseEntity .status(HttpStatus.OK) .body(new BaseResponse<>(HttpStatus.OK.value(), "마스터 자기소개서 수정 완료", masterIntroduceResponse)); diff --git a/src/main/java/umc/kkijuk/server/member/controller/MemberController.java b/src/main/java/umc/kkijuk/server/member/controller/MemberController.java index 5877ad89..5722043e 100644 --- a/src/main/java/umc/kkijuk/server/member/controller/MemberController.java +++ b/src/main/java/umc/kkijuk/server/member/controller/MemberController.java @@ -33,6 +33,7 @@ public class MemberController { private final MemberService memberService; private final MailServiceImpl mailService; private final JwtUtil jwtUtil; + private final LoginUser loginUser; // @Operation( // summary = "회원가입 요청", @@ -91,17 +92,17 @@ public class MemberController { // return ResponseEntity.ok(Boolean.TRUE); // } - @Operation( - summary = "내정보 조회 인증 화면 이메일 가져오기", - description = "내 정보를 조회 인증 화면에서 이메일을 가져옵니다.") - @GetMapping("/myPage") - public ResponseEntity getEmail() { - Long loginUser = LoginUser.get().getId(); - MemberEmailResponse memberEmailResponse = memberService.getMemberEmail(loginUser); - return ResponseEntity - .status(HttpStatus.OK) - .body(memberEmailResponse); - } +// @Operation( +// summary = "내정보 조회 인증 화면 이메일 가져오기", +// description = "내 정보를 조회 인증 화면에서 이메일을 가져옵니다.") +// @GetMapping("/myPage") +// public ResponseEntity getEmail() { +// Long loginUser = LoginUser.get().getId(); +// MemberEmailResponse memberEmailResponse = memberService.getMemberEmail(loginUser); +// return ResponseEntity +// .status(HttpStatus.OK) +// .body(memberEmailResponse); +// } // @Operation( @@ -155,9 +156,9 @@ public ResponseEntity refreshToken(@RequestBody RefreshTokenReques summary = "내 정보 조회", description = "마이페이지에서 내 정보들을 가져옵니다.") @GetMapping("/myPage/info") - public ResponseEntity getInfo(@RequestHeader("Authorization") String bearerToken) { - Long loginUser = LoginUser.get().extractMemberId(bearerToken); - MemberInfoResponse memberInfoResponse = memberService.getMemberInfo(String.valueOf(loginUser)); + public ResponseEntity getInfo(@RequestHeader("Authorization") String token) { + Long memberId = loginUser.extractMemberId(token); + MemberInfoResponse memberInfoResponse = memberService.getMemberInfo(memberId); return ResponseEntity .status(HttpStatus.OK) .body(memberInfoResponse); @@ -167,9 +168,10 @@ public ResponseEntity getInfo(@RequestHeader("Authorization" summary = "내 정보 수정", description = "내 정보 수정 요청을 받아 성공/실패를 반환합니다.") @PutMapping("/myPage/info") - public ResponseEntity changeMemberInfo(@RequestBody @Valid MemberInfoChangeDto memberInfoChangeDto) { - Long loginUser = LoginUser.get().getId(); - memberService.updateMemberInfo(loginUser, memberInfoChangeDto); + public ResponseEntity changeMemberInfo(@RequestHeader("Authorization") String token, + @RequestBody @Valid MemberInfoChangeDto memberInfoChangeDto) { + Long memberId = loginUser.extractMemberId(token); + memberService.updateMemberInfo(memberId, memberInfoChangeDto); return ResponseEntity.ok(Boolean.TRUE); } @@ -177,9 +179,9 @@ public ResponseEntity changeMemberInfo(@RequestBody @Valid MemberInfoC summary = "관심분야 조회", description = "마이페이지에서 관심분야를 조회합니다.") @GetMapping("/myPage/field") - public ResponseEntity getField() { - Long loginUser = LoginUser.get().getId(); - List memberField = memberService.getMemberField(loginUser); + public ResponseEntity getField(@RequestHeader("Authorization") String token) { + Long memberId = loginUser.extractMemberId(token); + List memberField = memberService.getMemberField(memberId); return ResponseEntity.ok().body(new MemberFieldResponse(memberField)); } @@ -187,9 +189,10 @@ public ResponseEntity getField() { summary = "관심분야 등록/수정", description = "초기/마이페이지에서 관심분야를 등록/수정합니다.") @PostMapping({"/field", "/myPage/field"}) - public ResponseEntity postField(@RequestBody MemberFieldDto memberFieldDto) { - Long loginUser = LoginUser.get().getId(); - memberService.updateMemberField(loginUser, memberFieldDto); + public ResponseEntity postField(@RequestHeader("Authorization") String token, + @RequestBody MemberFieldDto memberFieldDto) { + Long memberId = loginUser.extractMemberId(token); + memberService.updateMemberField(memberId, memberFieldDto); return ResponseEntity.ok(Boolean.TRUE); } diff --git a/src/main/java/umc/kkijuk/server/member/controller/response/MemberInfoResponse.java b/src/main/java/umc/kkijuk/server/member/controller/response/MemberInfoResponse.java index 7842be3e..d75687e8 100644 --- a/src/main/java/umc/kkijuk/server/member/controller/response/MemberInfoResponse.java +++ b/src/main/java/umc/kkijuk/server/member/controller/response/MemberInfoResponse.java @@ -15,5 +15,4 @@ public class MemberInfoResponse { private String phoneNumber; private LocalDate birthDate; private Role role; - private String refreshToken; } diff --git a/src/main/java/umc/kkijuk/server/member/service/MemberService.java b/src/main/java/umc/kkijuk/server/member/service/MemberService.java index 25b50d14..8dd6776c 100644 --- a/src/main/java/umc/kkijuk/server/member/service/MemberService.java +++ b/src/main/java/umc/kkijuk/server/member/service/MemberService.java @@ -14,7 +14,6 @@ public interface MemberService { Member getById(Long memberId); // Member join(MemberJoinDto memberJoinDto); -// MemberInfoResponse getMemberInfo(Long memberId); List getMemberField(Long memberId); Member updateMemberField(Long memberId, MemberFieldDto memberFieldDto); Member updateMemberInfo(Long memberId, MemberInfoChangeDto memberInfoChangeDto); @@ -29,13 +28,20 @@ public interface MemberService { /** * 소셜로그인 이후 추가된 기능 */ - Member createUserWithKakaoId(String kakaoId, Map kakaoUserInfo); - MemberInfoResponse getMemberInfo(String kakaoId); - void invalidateRefreshToken(String kakaoId); - void updateRefreshToken(String kakaoId, String refreshToken); + Member createUserWithKakaoId(String socialId, Map kakaoUserInfo); + MemberInfoResponse getMemberInfo(Long memberId); + void invalidateRefreshToken(String socialId); + void updateRefreshToken(String socialId, String refreshToken); Long extractMemberId(String bearerToken); public Member findBySocialId(String SocialId); - AuthResponse refreshAuthToken(String refreshToken, String kakaoId); + AuthResponse refreshAuthToken(String refreshToken, String socialId); +// Member createUserWithKakaoId(Long socialId, Map kakaoUserInfo); +// MemberInfoResponse getMemberInfo(Long memberId); +// void invalidateRefreshToken(Long socialId); +// void updateRefreshToken(Long socialId, String refreshToken); +// Long extractMemberId(String bearerToken); +// Member findBySocialId(Long socialId); +// AuthResponse refreshAuthToken(String refreshToken, Long socialId); Member createUserWithNaverId(String naverId, NaverUserResponse.NaverUserDetail naverUserInfo); } diff --git a/src/main/java/umc/kkijuk/server/member/service/MemberServiceImpl.java b/src/main/java/umc/kkijuk/server/member/service/MemberServiceImpl.java index f057c8e3..80225b9e 100644 --- a/src/main/java/umc/kkijuk/server/member/service/MemberServiceImpl.java +++ b/src/main/java/umc/kkijuk/server/member/service/MemberServiceImpl.java @@ -241,7 +241,6 @@ public Member createUserWithKakaoId(String kakaoId, Map kakaoUse log.info("신규 사용자 생성 - Kakao ID: {}, 이메일: {}, 이름: {}, 전화번호: {}, 생년월일: {}", kakaoId, email, name, phoneNumber, birthDate); return memberRepository.save(newMember); } - @Override @Transactional public Member createUserWithNaverId(String naverId, NaverUserResponse.NaverUserDetail naverUserInfo) { @@ -282,8 +281,8 @@ public Member createUserWithNaverId(String naverId, NaverUserResponse.NaverUserD @Override @Transactional - public MemberInfoResponse getMemberInfo(String socialId) { - Member member = this.findBySocialId(socialId); + public MemberInfoResponse getMemberInfo(Long memberId) { + Member member = this.getById(memberId); return MemberInfoResponse.builder() .socialId(member.getSocialId()) .email(member.getEmail()) @@ -291,10 +290,8 @@ public MemberInfoResponse getMemberInfo(String socialId) { .phoneNumber(member.getPhoneNumber()) .birthDate(member.getBirthDate()) .role(member.getRole()) - .refreshToken(member.getRefreshToken()) .build(); } - @Override @Transactional public void invalidateRefreshToken(String socialId) { diff --git a/src/main/java/umc/kkijuk/server/record/controller/FileController.java b/src/main/java/umc/kkijuk/server/record/controller/FileController.java index 75dbf584..5c428569 100644 --- a/src/main/java/umc/kkijuk/server/record/controller/FileController.java +++ b/src/main/java/umc/kkijuk/server/record/controller/FileController.java @@ -26,13 +26,14 @@ public class FileController { private final FileService fileService; private final RecordService recordService; + private final LoginUser loginUser; @GetMapping(value="/file") @Operation(summary = "이력서(S3)-추가 자료<첨부파일> 저장(presignedUrl 생성)", description = "S3에 접근하기 위한 Presigned URL을 반환합니다.") public ResponseEntity>> createFileUrl - (@RequestParam String fileName) { - Long loginUser = LoginUser.get().getId(); - Map response = fileService.getSignUrl(loginUser,fileName); + (@RequestHeader("Authorization") String token, @RequestParam String fileName) { + Long memberId = loginUser.extractMemberId(token); + Map response = fileService.getSignUrl(memberId,fileName); return ResponseEntity .status(HttpStatus.CREATED) .body(new BaseResponse<>(HttpStatus.CREATED.value(), "Presigned URL 반환 완료", response)); @@ -42,10 +43,10 @@ public class FileController { @Operation(summary = "이력서(S3)-추가 자료<첨부파일>(keyName 저장)", description = "주어진 keyName을 바탕으로 해당 파일에 대한 정보를 저장합니다.") public ResponseEntity> createFile - (@Valid @RequestBody FileReqDto request) { - Long loginUser = LoginUser.get().getId(); - FileResponse fileResponse = fileService.saveFile(loginUser, - recordService.findByMemberId(loginUser).getId(), request); + (@RequestHeader("Authorization") String token, @Valid @RequestBody FileReqDto request) { + Long memberId = loginUser.extractMemberId(token); + FileResponse fileResponse = fileService.saveFile(memberId, + recordService.findByMemberId(memberId).getId(), request); return ResponseEntity .status(HttpStatus.CREATED) .body(new BaseResponse<>(HttpStatus.CREATED.value(), "파일 정보 저장 완료",fileResponse)); @@ -55,9 +56,9 @@ public class FileController { @Operation(summary = "이력서(S3)-추가 자료<첨부파일> 조회(presignedUrl 생성)", description = "fileName에 해당하는 presigned URL을 반환합니다.") public ResponseEntity>> getDownloadUrl - (@RequestParam String fileName) { - Long loginUser = LoginUser.get().getId(); - Map response = fileService.getDownloadUrl(loginUser, fileName); + (@RequestHeader("Authorization") String token, @RequestParam String fileName) { + Long memberId = loginUser.extractMemberId(token); + Map response = fileService.getDownloadUrl(memberId, fileName); return ResponseEntity .status(HttpStatus.OK) @@ -66,19 +67,21 @@ public class FileController { @DeleteMapping("/file") @Operation(summary = "이력서(S3)-추가 자료<첨부파일> 삭제", description = "fileName으로 S3 버킷에서 파일을 삭제합니다.") - public ResponseEntity> deleteFile(@RequestParam String fileName){ - Long loginUser = LoginUser.get().getId(); - FileResponse fileResponse = fileService.deleteFile(loginUser, fileName); + public ResponseEntity> deleteFile(@RequestHeader("Authorization") String token, + @RequestParam String fileName){ + Long memberId = loginUser.extractMemberId(token); + FileResponse fileResponse = fileService.deleteFile(memberId, fileName); return ResponseEntity.status(HttpStatus.OK) .body(new BaseResponse<>(HttpStatus.OK.value(), "파일 삭제 완료", fileResponse)); } @PostMapping("/url") @Operation(summary = "이력서-추가 자료 저장", description = "추가자료 중 URL을 저장합니다.") - public ResponseEntity saveUrl(@RequestBody UrlReqDto urlReqDto){ - Long loginUser = LoginUser.get().getId(); - FileResponse fileResponse = fileService.saveUrl(loginUser, - recordService.findByMemberId(loginUser).getId(), urlReqDto); + public ResponseEntity saveUrl(@RequestHeader("Authorization") String token, + @RequestBody UrlReqDto urlReqDto){ + Long memberId = loginUser.extractMemberId(token); + FileResponse fileResponse = fileService.saveUrl(memberId, + recordService.findByMemberId(memberId).getId(), urlReqDto); return ResponseEntity .status(HttpStatus.OK) .body(new BaseResponse<>(HttpStatus.OK.value(), "URL 저장 완료", fileResponse)); @@ -86,9 +89,10 @@ public ResponseEntity saveUrl(@RequestBody UrlReqDto urlReqDto){ @DeleteMapping("/url") @Operation(summary = "이력서-추가 자료 삭제", description = "추가자료 중 URL을 삭제합니다.") - public ResponseEntity deleteUrl(@RequestBody UrlReqDto urlReqDto) { - Long loginUser = LoginUser.get().getId(); - FileResponse fileResponse = fileService.deleteUrl(loginUser, urlReqDto); + public ResponseEntity deleteUrl(@RequestHeader("Authorization") String token, + @RequestBody UrlReqDto urlReqDto) { + Long memberId = loginUser.extractMemberId(token); + FileResponse fileResponse = fileService.deleteUrl(memberId, urlReqDto); return ResponseEntity .status(HttpStatus.OK) .body(new BaseResponse<>(HttpStatus.OK.value(), "URL 제거 완료", fileResponse)); diff --git a/src/main/java/umc/kkijuk/server/record/controller/RecordController.java b/src/main/java/umc/kkijuk/server/record/controller/RecordController.java index b5b9e8a5..d6f9e972 100644 --- a/src/main/java/umc/kkijuk/server/record/controller/RecordController.java +++ b/src/main/java/umc/kkijuk/server/record/controller/RecordController.java @@ -21,12 +21,14 @@ public class RecordController { private final RecordService recordService; private final MemberService memberService; + private final LoginUser loginUser; @PostMapping @Operation(summary = "이력서 생성") - public ResponseEntity save(@RequestBody RecordReqDto recordReqDto) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public ResponseEntity save(@RequestHeader("Authorization") String token, + @RequestBody RecordReqDto recordReqDto) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); RecordResponse recordResponse = recordService.saveRecord(requestMember, recordReqDto); return ResponseEntity .status(HttpStatus.OK) @@ -35,9 +37,9 @@ public ResponseEntity save(@RequestBody RecordReqDto recordReqDto) { @GetMapping @Operation(summary = "이력서 전체 조회") - public ResponseEntity get() { - Long loginUser = LoginUser.get().getId(); - RecordResponse recordResponse = recordService.getRecord(loginUser); + public ResponseEntity get(@RequestHeader("Authorization") String token) { + Long memberId = loginUser.extractMemberId(token); + RecordResponse recordResponse = recordService.getRecord(memberId); return ResponseEntity .status(HttpStatus.OK) .body(new BaseResponse<>(HttpStatus.OK.value(), "이력서 전체 조회 완료", recordResponse)); @@ -45,10 +47,11 @@ public ResponseEntity get() { @PatchMapping @Operation(summary = "이력서 정보 수정") - public ResponseEntity update(@RequestBody RecordReqDto recordReqDto) { - Long loginUser = LoginUser.get().getId(); - RecordResponse recordResponse = recordService.updateRecord(loginUser, - recordService.findByMemberId(loginUser).getId(), recordReqDto); + public ResponseEntity update(@RequestHeader("Authorization") String token, + @RequestBody RecordReqDto recordReqDto) { + Long memberId = loginUser.extractMemberId(token); + RecordResponse recordResponse = recordService.updateRecord(memberId, + recordService.findByMemberId(memberId).getId(), recordReqDto); return ResponseEntity .status(HttpStatus.OK) .body(new BaseResponse<>(HttpStatus.OK.value(), "이력서 수정 완료", recordResponse)); @@ -56,20 +59,21 @@ public ResponseEntity update(@RequestBody RecordReqDto recordReqDto) { @GetMapping("/download") @Operation(summary = "이력서 내보내기", description = "이력서 내보내기에 필요한 정보들을 조회합니다.") - public ResponseEntity downloadResume() { - Long loginUser = LoginUser.get().getId(); - RecordDownResponse response = recordService.downloadResume(recordService.findByMemberId(loginUser).getId(), loginUser); + public ResponseEntity downloadResume(@RequestHeader("Authorization") String token) { + Long memberId = loginUser.extractMemberId(token); + RecordDownResponse response = recordService.downloadResume(recordService.findByMemberId(memberId).getId(), memberId); return ResponseEntity.status(HttpStatus.OK) .body(new BaseResponse<>(HttpStatus.OK.value(), "이력서 내보내기 정보 조회 완료", response)); } @PostMapping("/education") @Operation(summary = "학력 생성") - public ResponseEntity saveEducation(@RequestBody EducationReqDto educationReqDto) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public ResponseEntity saveEducation(@RequestHeader("Authorization") String token, + @RequestBody EducationReqDto educationReqDto) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); EducationResponse educationResponse = recordService.saveEducation(requestMember, - recordService.findByMemberId(loginUser).getId(), educationReqDto); + recordService.findByMemberId(memberId).getId(), educationReqDto); return ResponseEntity .status(HttpStatus.OK) .body(new BaseResponse<>(HttpStatus.OK.value(), "학력 생성 완료", educationResponse)); @@ -77,9 +81,11 @@ public ResponseEntity saveEducation(@RequestBody EducationReqDto educati @PatchMapping("/education") @Operation(summary = "학력 수정") - public ResponseEntity patchEducation(Long educationId, @RequestBody EducationReqDto educationReqDto) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public ResponseEntity patchEducation(@RequestHeader("Authorization") String token, + Long educationId, + @RequestBody EducationReqDto educationReqDto) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); EducationResponse educationResponse = recordService.updateEducation(requestMember, educationId, educationReqDto); return ResponseEntity .status(HttpStatus.OK) @@ -88,9 +94,10 @@ public ResponseEntity patchEducation(Long educationId, @RequestBody Educ @DeleteMapping("/education") @Operation(summary = "학력 삭제") - public ResponseEntity deleteEducation(Long educationId) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public ResponseEntity deleteEducation(@RequestHeader("Authorization") String token, + Long educationId) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); Long id = recordService.deleteEducation(requestMember, educationId); return ResponseEntity .status(HttpStatus.OK) @@ -99,11 +106,12 @@ public ResponseEntity deleteEducation(Long educationId) { @PostMapping("/license") @Operation(summary = "자격증 생성") - public ResponseEntity saveLicense(@RequestBody LicenseReqDto licenseReqDto) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public ResponseEntity saveLicense(@RequestHeader("Authorization") String token, + @RequestBody LicenseReqDto licenseReqDto) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); LicenseResponse licenseResponse = recordService.saveLicense(requestMember, - recordService.findByMemberId(loginUser).getId(), licenseReqDto); + recordService.findByMemberId(memberId).getId(), licenseReqDto); return ResponseEntity .status(HttpStatus.OK) .body(new BaseResponse<>(HttpStatus.OK.value(), "자격증 생성 완료", licenseResponse)); @@ -111,9 +119,11 @@ public ResponseEntity saveLicense(@RequestBody LicenseReqDto licenseReqD @PatchMapping("/license") @Operation(summary = "자격증 수정") - public ResponseEntity patchLicense(Long licenseId, @RequestBody LicenseReqDto licenseReqDto) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public ResponseEntity patchLicense(@RequestHeader("Authorization") String token, + Long licenseId, + @RequestBody LicenseReqDto licenseReqDto) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); LicenseResponse licenseResponse = recordService.updateLicense(requestMember, licenseId, licenseReqDto); return ResponseEntity .status(HttpStatus.OK) @@ -122,9 +132,10 @@ public ResponseEntity patchLicense(Long licenseId, @RequestBody LicenseR @DeleteMapping("/license") @Operation(summary = "자격증 삭제") - public ResponseEntity deleteLicense(Long licenseId) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public ResponseEntity deleteLicense(@RequestHeader("Authorization") String token, + Long licenseId) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); Long id = recordService.deleteLicense(requestMember, licenseId); return ResponseEntity .status(HttpStatus.OK) @@ -133,11 +144,12 @@ public ResponseEntity deleteLicense(Long licenseId) { @PostMapping("/award") @Operation(summary = "수상 생성") - public ResponseEntity saveAward(@RequestBody AwardReqDto awardReqDto) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public ResponseEntity saveAward(@RequestHeader("Authorization") String token, + @RequestBody AwardReqDto awardReqDto) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); AwardResponse awardResponse = recordService.saveAward(requestMember, - recordService.findByMemberId(loginUser).getId(), awardReqDto); + recordService.findByMemberId(memberId).getId(), awardReqDto); return ResponseEntity .status(HttpStatus.OK) .body(new BaseResponse<>(HttpStatus.OK.value(), "수상 생성 완료", awardResponse)); @@ -145,9 +157,11 @@ public ResponseEntity saveAward(@RequestBody AwardReqDto awardReqDto) { @PatchMapping("/award") @Operation(summary = "수상 수정") - public ResponseEntity patchAward(Long awardId, @RequestBody AwardReqDto awardReqDto) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public ResponseEntity patchAward(@RequestHeader("Authorization") String token, + Long awardId, + @RequestBody AwardReqDto awardReqDto) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); AwardResponse awardResponse = recordService.updateAward(requestMember, awardId, awardReqDto); return ResponseEntity .status(HttpStatus.OK) @@ -156,9 +170,10 @@ public ResponseEntity patchAward(Long awardId, @RequestBody AwardReqDto @DeleteMapping("/award") @Operation(summary = "수상 삭제") - public ResponseEntity deleteAward(Long awardId) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public ResponseEntity deleteAward(@RequestHeader("Authorization") String token, + Long awardId) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); Long id = recordService.deleteAward(requestMember, awardId); return ResponseEntity .status(HttpStatus.OK) @@ -167,11 +182,12 @@ public ResponseEntity deleteAward(Long awardId) { @PostMapping("/skill") @Operation(summary = "스킬 생성") - public ResponseEntity saveSkill(@RequestBody SkillReqDto skillReqDto) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public ResponseEntity saveSkill(@RequestHeader("Authorization") String token, + @RequestBody SkillReqDto skillReqDto) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); SkillResponse skillResponse = recordService.saveSkill(requestMember, - recordService.findByMemberId(loginUser).getId(), skillReqDto); + recordService.findByMemberId(memberId).getId(), skillReqDto); return ResponseEntity .status(HttpStatus.OK) .body(new BaseResponse<>(HttpStatus.OK.value(), "스킬 생성 완료", skillResponse)); @@ -179,9 +195,11 @@ public ResponseEntity saveSkill(@RequestBody SkillReqDto skillReqDto) { @PatchMapping("/skill") @Operation(summary = "스킬 수정") - public ResponseEntity patchSkill(Long skillId, @RequestBody SkillReqDto skillReqDto) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public ResponseEntity patchSkill(@RequestHeader("Authorization") String token, + Long skillId, + @RequestBody SkillReqDto skillReqDto) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); SkillResponse skillResponse = recordService.updateSkill(requestMember, skillId, skillReqDto); return ResponseEntity .status(HttpStatus.OK) @@ -190,9 +208,10 @@ public ResponseEntity patchSkill(Long skillId, @RequestBody SkillReqDto @DeleteMapping("/skill") @Operation(summary = "스킬 삭제") - public ResponseEntity deleteSkill(Long skillId) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public ResponseEntity deleteSkill(@RequestHeader("Authorization") String token, + Long skillId) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); Long id = recordService.deleteSkill(requestMember, skillId); return ResponseEntity .status(HttpStatus.OK) diff --git a/src/main/java/umc/kkijuk/server/recruit/controller/RecruitController.java b/src/main/java/umc/kkijuk/server/recruit/controller/RecruitController.java index 50cd151e..9786b286 100644 --- a/src/main/java/umc/kkijuk/server/recruit/controller/RecruitController.java +++ b/src/main/java/umc/kkijuk/server/recruit/controller/RecruitController.java @@ -33,16 +33,17 @@ public class RecruitController { private final RecruitService recruitService; private final ReviewService reviewService; private final MemberService memberService; + private final LoginUser loginUser; @Operation( summary = "지원 공고 생성", description = "주어진 정보를 바탕으로 지원 공고 데이터를 생성합니다.") @PostMapping - public ResponseEntity create( + public ResponseEntity create(@RequestHeader("Authorization") String token, @RequestBody @Valid RecruitCreate recruitCreate ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); Recruit recruit = recruitService.create(requestMember, recruitCreate); return ResponseEntity @@ -55,11 +56,11 @@ public ResponseEntity create( description = "주어진 정보를 바탕으로 지원 공고 데이터를 수정합니다.") @Parameter(name = "recruitId", description = "지원 공고 ID", example = "1") @PutMapping("/{recruitId}") - public ResponseEntity update( + public ResponseEntity update(@RequestHeader("Authorization") String token, @RequestBody @Valid RecruitUpdate recruitUpdate, @PathVariable long recruitId) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); Recruit recruit = recruitService.update(requestMember, recruitId, recruitUpdate); return ResponseEntity .status(HttpStatus.OK) @@ -71,11 +72,11 @@ public ResponseEntity update( description = "다음 중 주어진 상태로 지원 공고의 상태를 수정합니다." + " [UNAPPLIED / PLANNED / APPLYING / REJECTED / ACCEPTED]") @Parameter(name = "recruitId", description = "지원 공고 ID", example = "1") @PatchMapping("/{recruitId}/status") - public ResponseEntity updateState( + public ResponseEntity updateState(@RequestHeader("Authorization") String token, @RequestBody @Valid RecruitStatusUpdate recruitStatusUpdate, @PathVariable long recruitId) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); Recruit recruit = recruitService.updateStatus(requestMember, recruitId, recruitStatusUpdate); return ResponseEntity .ok() @@ -87,10 +88,10 @@ public ResponseEntity updateState( description = "지원 공고 ID에 해당 하는 공고를 삭제합니다") @Parameter(name = "recruitId", description = "지원 공고 ID", example = "1") @DeleteMapping("/{recruitId}") - public ResponseEntity delete( + public ResponseEntity delete(@RequestHeader("Authorization") String token, @PathVariable long recruitId) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); Recruit recruit = recruitService.disable(requestMember, recruitId); return ResponseEntity .ok() @@ -102,10 +103,10 @@ public ResponseEntity delete( description = "지원 공고 ID에 해당하는 공고의 상세 정보를 요청합니다.") @Parameter(name = "recruitId", description = "지원 공고 ID", example = "1") @GetMapping("/{recruitId}") - public ResponseEntity getRecruitInfo( + public ResponseEntity getRecruitInfo(@RequestHeader("Authorization") String token, @PathVariable long recruitId) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); Recruit recruit = recruitService.getById(recruitId); List reviews = reviewService.findAllByRecruit(requestMember, recruit); @@ -119,10 +120,11 @@ public ResponseEntity getRecruitInfo( description = "주어진 날짜에 마감 종료되는 지원 공고들의 목록을 요청합니다.") @GetMapping("/list/end") public ResponseEntity findAllRecruitListByEndTime( + @RequestHeader("Authorization") String token, @Parameter(name = "date", description = "지원 공고 마감 날짜", example = "2024-07-20") @RequestParam LocalDate date) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); List recruits = recruitService.findAllByEndTime(requestMember, date); return ResponseEntity .ok() @@ -134,11 +136,12 @@ public ResponseEntity findAllRecruitListByEndTime( description = "주어진 시간 이후 마감 종료되는 지원 공고들의 목록을 요청합니다.") @GetMapping("/list/after") public ResponseEntity findAllRecruitListByEndTimeAfterNow( + @RequestHeader("Authorization") String token, @Parameter(name = "time", description = "이 시간 이후에 마감되는 공고를 요청", example = "2024-07-20 10:30") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm") @RequestParam LocalDateTime time) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); List recruits = recruitService.findAllByEndTimeAfter(requestMember, time); return ResponseEntity .ok() @@ -151,12 +154,13 @@ public ResponseEntity findAllRecruitListByEnd "상태가 UNAPPLIED 혹은 PLANNED일 경우, 해당 지원 공고의 마감시간이 요청한 시간보다 이후여야 합니다.") @GetMapping("/list/valid") public ResponseEntity findValidRecruit( + @RequestHeader("Authorization") String token, @Parameter(name = "time", description = "이 시간 이후에 유효한 공고 목록 요청", example = "2024-07-20 10:30") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm") @RequestParam LocalDateTime time ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); List ValidRecruitDtoList = recruitService.findAllValidRecruitByMember(requestMember, time); return ResponseEntity .ok() @@ -168,12 +172,13 @@ public ResponseEntity findValidRecruit( description = "요청한 년도와 월에 대해서 해당 월에 마감되는 공고의 종류와 갯수를 요청합니다.") @GetMapping("/calendar") public ResponseEntity getByMonth( + @RequestHeader("Authorization") String token, @Parameter(name = "year", description = "년도", example = "2024") @RequestParam Integer year, @Parameter(name = "month", description = "월", example = "7") @RequestParam Integer month) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); List recruitListByMonthDtoList = recruitService.findAllValidRecruitByYearAndMonth(requestMember, year, month); return ResponseEntity .ok() @@ -185,10 +190,11 @@ public ResponseEntity getByMonth( description = "공고 지원 날짜를 주어진 날짜로 수정합니다.") @PatchMapping("/{recruitId}/apply-date") public ResponseEntity updateApplyDate( + @RequestHeader("Authorization") String token, @RequestBody @Valid RecruitApplyDateUpdate recruitApplyDateUpdate, @PathVariable long recruitId) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); Recruit recruit = recruitService.updateApplyDate(requestMember, recruitId, recruitApplyDateUpdate); return ResponseEntity .ok() diff --git a/src/main/java/umc/kkijuk/server/recruit/controller/RecruitSearchController.java b/src/main/java/umc/kkijuk/server/recruit/controller/RecruitSearchController.java index 3c8b33b7..29045195 100644 --- a/src/main/java/umc/kkijuk/server/recruit/controller/RecruitSearchController.java +++ b/src/main/java/umc/kkijuk/server/recruit/controller/RecruitSearchController.java @@ -21,16 +21,18 @@ public class RecruitSearchController { private final RecruitSearchService recruitSearchService; private final MemberService memberService; + private final LoginUser loginUser; @Operation( summary = "공고 이름 & 태그 / 공고 후기 기준으로 검색", description = "입력받은 텍스트에 대하여, 공고 제목, 공고 태그, 혹은 공고 후기에 포함하는 모든 공고를 검색합니다. 정렬기준은 최신순입니다.") @GetMapping public ResponseEntity findRecruitsByKeyword( + @RequestHeader("Authorization") String token, @RequestParam String keyword) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); RecruitReviewListByKeywordResponse result = recruitSearchService.findRecruitByKeyword(requestMember, keyword); return ResponseEntity diff --git a/src/main/java/umc/kkijuk/server/recruit/controller/RecruitTagController.java b/src/main/java/umc/kkijuk/server/recruit/controller/RecruitTagController.java index 57cad35d..e206e34f 100644 --- a/src/main/java/umc/kkijuk/server/recruit/controller/RecruitTagController.java +++ b/src/main/java/umc/kkijuk/server/recruit/controller/RecruitTagController.java @@ -18,14 +18,15 @@ @RequestMapping("/recruit/tag") public class RecruitTagController { private final MemberService memberService; + private final LoginUser loginUser; @Operation( summary = "지원 공고 태그", description = "사용자의 지원 공고 태그 정보들을 요청합니다") @GetMapping - public ResponseEntity getRecruitTag() { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public ResponseEntity getRecruitTag(@RequestHeader("Authorization") String token) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return ResponseEntity .ok() .body(RecruitTagResponse.from(requestMember.getRecruitTags())); @@ -35,9 +36,10 @@ public ResponseEntity getRecruitTag() { summary = "지원 공고 태그 추가", description = "사용자의 지원 공고 태그를 추가합니다") @PostMapping - public ResponseEntity addRecruitTag(@RequestParam String tag) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public ResponseEntity addRecruitTag(@RequestHeader("Authorization") String token, + @RequestParam String tag) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); List tags = memberService.addRecruitTag(requestMember, tag); return ResponseEntity .ok() @@ -48,9 +50,10 @@ public ResponseEntity addRecruitTag(@RequestParam String tag summary = "지원 공고 태그 제거", description = "사용자의 지원 공고 태그를 제거합니다") @DeleteMapping - public ResponseEntity deleteRecruitTag(@RequestParam String tag) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public ResponseEntity deleteRecruitTag(@RequestHeader("Authorization") String token, + @RequestParam String tag) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); List tags = memberService.deleteRecruitTag(requestMember, tag); return ResponseEntity .ok() diff --git a/src/main/java/umc/kkijuk/server/review/controller/ReviewController.java b/src/main/java/umc/kkijuk/server/review/controller/ReviewController.java index 4415fa4a..c13debd7 100644 --- a/src/main/java/umc/kkijuk/server/review/controller/ReviewController.java +++ b/src/main/java/umc/kkijuk/server/review/controller/ReviewController.java @@ -27,6 +27,7 @@ public class ReviewController { private final ReviewService reviewService; private final RecruitService recruitService; private final MemberService memberService; + private final LoginUser loginUser; @Operation( summary = "지원 공고 후기 추가", @@ -34,11 +35,12 @@ public class ReviewController { @Parameter(name = "recruitId", description = "지원 공고 ID", example = "1") @PostMapping("/review") public ResponseEntity create( + @RequestHeader("Authorization") String token, @PathVariable Long recruitId, @RequestBody @Valid ReviewCreate reviewCreate ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); Recruit recruit = recruitService.getById(recruitId); Review review = reviewService.create(requestMember, recruit, reviewCreate); @@ -54,12 +56,13 @@ public ResponseEntity create( @Parameter(name = "reviewId", description = "지원 공고 후기 ID", example = "1") @PutMapping("/review/{reviewId}") public ResponseEntity update( + @RequestHeader("Authorization") String token, @PathVariable Long recruitId, @PathVariable Long reviewId, @RequestBody @Valid ReviewUpdate reviewUpdate ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); Recruit recruit = recruitService.getById(recruitId); Review review = reviewService.update(requestMember, recruit, reviewId, reviewUpdate); @@ -75,11 +78,12 @@ public ResponseEntity update( @Parameter(name = "reviewId", description = "지원 공고 후기 ID", example = "1") @DeleteMapping("/review/{reviewId}") public ResponseEntity delete( + @RequestHeader("Authorization") String token, @PathVariable Long recruitId, @PathVariable Long reviewId ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); Recruit recruit = recruitService.getById(recruitId); reviewService.delete(requestMember, recruit, reviewId); diff --git a/src/main/java/umc/kkijuk/server/tag/controller/TagController.java b/src/main/java/umc/kkijuk/server/tag/controller/TagController.java index 438e11bc..e17dd806 100644 --- a/src/main/java/umc/kkijuk/server/tag/controller/TagController.java +++ b/src/main/java/umc/kkijuk/server/tag/controller/TagController.java @@ -24,14 +24,16 @@ public class TagController { private final TagService tagService; private final MemberService memberService; + private final LoginUser loginUser; @PostMapping("/tag") @Operation(summary = "태그 추가 API", description = "태그 - 태그를 생성하는 API") public TagResponse create( + @RequestHeader("Authorization") String token, @RequestBody @Valid TagRequestDto.CreateTagDto request ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); Tag tag = tagService.createTag(requestMember, request); return TagResponse.success(HttpStatus.OK, "태그를 성공적으로 생성했습니다.", TagConverter.toTagResult(tag)); @@ -39,20 +41,20 @@ public TagResponse create( @GetMapping("/tag") @Operation(summary = "태그 조회 API", description = "태그 - 태그 조회하는 API") - public TagResponse read() { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + public TagResponse read(@RequestHeader("Authorization") String token) { + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); return TagResponse.success(HttpStatus.OK, "모든 태그를 성공적으로 조회했습니다.", tagService.findAllTags(requestMember)); } @DeleteMapping("/tag/{tagId}") @Operation(summary = "태그 삭제 API", description = "태그 - 태그를 삭제하는 API") @Parameter(name = "tagId", description = "태그 Id, path variable 입니다. 존재하는 태그 Id 값을 넘겨 주세요.", example = "1") - public TagResponse delete( + public TagResponse delete(@RequestHeader("Authorization") String token, @PathVariable Long tagId ) { - Long loginUser = LoginUser.get().getId(); - Member requestMember = memberService.getById(loginUser); + Long memberId = loginUser.extractMemberId(token); + Member requestMember = memberService.getById(memberId); tagService.delete(requestMember, tagId); return TagResponse.success(HttpStatus.OK, "태그 삭제가 성공적으로 이루어졌습니다.", null); }