Skip to content

Commit

Permalink
Fix(merge) : feature/security 브랜치와의 충돌 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonda02 committed Dec 20, 2024
2 parents f4ad899 + d6aafd6 commit a7cf34f
Show file tree
Hide file tree
Showing 18 changed files with 347 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -71,6 +73,7 @@ public String getKakaoAccessToken(String code) {
}


@Transactional
public Map<String, Object> getKakaoUserInfo(String accessToken) {
String userInfoUri = "https://kapi.kakao.com/v2/user/me";

Expand All @@ -89,6 +92,7 @@ public Map<String, Object> getKakaoUserInfo(String accessToken) {
}
}

@Transactional
public Member processKakaoUser(String accessToken) {
Map<String, Object> kakaoUserInfo = getKakaoUserInfo(accessToken);
String kakaoId = kakaoUserInfo.get("id").toString();
Expand All @@ -106,6 +110,7 @@ public Member processKakaoUser(String accessToken) {
});
}

@Transactional
public Map<String, String> generateTokens(Member member) {
String kakaoId = String.valueOf(member.getSocialId());

Expand All @@ -114,6 +119,9 @@ public Map<String, String> generateTokens(Member member) {

log.info("JWT 토큰 생성 완료 - 카카오 ID: {}, accessToken: {}, refreshToken: {}", kakaoId, accessToken, refreshToken);

member.setRefreshToken(refreshToken);
memberRepository.save(member);

Map<String, String> tokens = new HashMap<>();
tokens.put("accessToken", accessToken);
tokens.put("refreshToken", refreshToken);
Expand Down

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions src/main/java/umc/kkijuk/server/common/LoginUser.java
Original file line number Diff line number Diff line change
@@ -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 ")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<DashBoardUserInfoResponse> 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()
Expand All @@ -51,9 +54,10 @@ public ResponseEntity<DashBoardUserInfoResponse> getUserInfo(
)
@GetMapping("/remind/recruit")
public ResponseEntity<RecruitRemindResponse> 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()
Expand All @@ -62,10 +66,10 @@ public ResponseEntity<RecruitRemindResponse> getRemindRecruits(

@GetMapping("/introduce")
@Operation(summary = "홈 자기소개서 작성 알림")
public ResponseEntity<Object> get(
public ResponseEntity<Object> 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<IntroduceRemindResponse> homeIntroduceResDtos = dashBoardService.getHomeIntro(requestMember);
return ResponseEntity
.status(HttpStatus.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@
public class BaseCareerDetailController {
private final MemberService memberService;
private final BaseCareerDetailService careerDetailService;
private final LoginUser loginUser;

@PostMapping("/{careerId}")
@Operation(summary = "활동 기록 생성", description = "주어진 정보를 바탕으로 활동기록을 생성합니다.")
@Parameters({
@Parameter(name = "careerId", description = "활동 Id, path variable 입니다."),
})
public CareerDetailResponse<BaseCareerDetailResponse> 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)
);
Expand All @@ -47,11 +49,12 @@ public CareerDetailResponse<BaseCareerDetailResponse> create(
@Parameter(name = "detailId", description = "활동 기록 Id, path variable 입니다.")
})
public CareerDetailResponse<Object> 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);
}
Expand All @@ -63,12 +66,13 @@ public CareerDetailResponse<Object> delete(
@Parameter(name = "detailId", description = "활동 기록 Id, path variable 입니다. ")
})
public CareerDetailResponse<BaseCareerDetailResponse> 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,
"활동 기록을 성공적으로 수정했습니다.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> save(
public ResponseEntity<Object> 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)
Expand All @@ -43,10 +44,10 @@ public ResponseEntity<Object> save(

@GetMapping("detail/{introId}")
@Operation(summary = "자기소개서 개별 조회")
public ResponseEntity<Object> get(
public ResponseEntity<Object> 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)
Expand All @@ -55,9 +56,9 @@ public ResponseEntity<Object> get(

@GetMapping("list")
@Operation(summary = "자기소개서 목록 조회")
public ResponseEntity<Object> getList(){
LoginUser loginUser = LoginUser.get();
Member requestMember = memberService.getById(loginUser.getId());
public ResponseEntity<Object> getList(@RequestHeader("Authorization") String token){
Long memberId = loginUser.extractMemberId(token);
Member requestMember = memberService.getById(memberId);
List<IntroduceListResponse> introduceListResponses = introduceService.getIntroList(requestMember);
return ResponseEntity
.status(HttpStatus.OK)
Expand All @@ -66,10 +67,10 @@ public ResponseEntity<Object> getList(){

@PatchMapping("/{introId}")
@Operation(summary = "자기소개서 수정")
public ResponseEntity<Object> update(
public ResponseEntity<Object> 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)
Expand All @@ -78,10 +79,10 @@ public ResponseEntity<Object> update(

@DeleteMapping("/{introId}")
@Operation(summary = "자기소개서 삭제")
public ResponseEntity<Object> delete(
public ResponseEntity<Object> 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)
Expand All @@ -90,9 +91,11 @@ public ResponseEntity<Object> delete(

@GetMapping("/search")
@Operation(summary = "키워드로 자기소개서 문단 검색")
public ResponseEntity<Map<String, Object>> searchIntroduceByKeyword(@RequestParam String keyword) {
LoginUser loginUser = LoginUser.get();
Member requestMember = memberService.getById(loginUser.getId());
public ResponseEntity<Map<String, Object>> searchIntroduceByKeyword(
@RequestHeader("Authorization") String token,
@RequestParam String keyword) {
Long memberId = loginUser.extractMemberId(token);
Member requestMember = memberService.getById(memberId);
Map<String, Object> response = introduceService.searchIntroduceAndMasterByKeyword(keyword, requestMember);
return ResponseEntity.status(HttpStatus.OK).body(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,40 @@
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<Object> saveMasterIntro(@RequestBody IntroduceReqDto introduceReqDto) throws Exception {
LoginUser loginUser = LoginUser.get();
public ResponseEntity<Object> 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));
}

@GetMapping
@Operation(summary = "마스터 자기소개서 조회")
public ResponseEntity<Object> getMasterIntro(){
LoginUser loginUser = LoginUser.get();
MasterIntroduceResponse masterIntroduceResponse = masterIntroduceService.getMasterIntro(loginUser.getId());
public ResponseEntity<Object> 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));
}

@PatchMapping
@Operation(summary = "마스터 자기소개서 수정")
public ResponseEntity<Object> updateMasterIntro(
public ResponseEntity<Object> 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));
Expand Down
Loading

0 comments on commit a7cf34f

Please sign in to comment.