diff --git a/src/main/java/com/postgraduate/domain/auth/application/dto/req/KakaoCodeRequest.java b/src/main/java/com/postgraduate/domain/auth/application/dto/req/KakaoCodeRequest.java new file mode 100644 index 00000000..c14ffcfb --- /dev/null +++ b/src/main/java/com/postgraduate/domain/auth/application/dto/req/KakaoCodeRequest.java @@ -0,0 +1,12 @@ +package com.postgraduate.domain.auth.application.dto.req; + +import jakarta.validation.constraints.NotNull; +import lombok.*; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class KakaoCodeRequest { + @NotNull + private String code; +} diff --git a/src/main/java/com/postgraduate/domain/auth/application/dto/res/KakaoTokenInfoResponse.java b/src/main/java/com/postgraduate/domain/auth/application/dto/res/KakaoTokenInfoResponse.java new file mode 100644 index 00000000..8636b00e --- /dev/null +++ b/src/main/java/com/postgraduate/domain/auth/application/dto/res/KakaoTokenInfoResponse.java @@ -0,0 +1,20 @@ +package com.postgraduate.domain.auth.application.dto.res; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Builder +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class KakaoTokenInfoResponse { + private String access_token; + private String token_type; + private String refresh_token; + private String id_token; + private int expires_in; + private String cope; + private int refresh_token_expires_in; +} diff --git a/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoAccessTokenUseCase.java b/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoAccessTokenUseCase.java index 05ac257a..aa826d8b 100644 --- a/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoAccessTokenUseCase.java +++ b/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoAccessTokenUseCase.java @@ -1,10 +1,14 @@ package com.postgraduate.domain.auth.application.usecase.kakao; import com.postgraduate.domain.auth.application.dto.res.KakaoAccessTokenResponse; +import com.postgraduate.domain.auth.application.dto.res.KakaoTokenInfoResponse; import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.MediaType; import org.springframework.stereotype.Service; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.web.reactive.function.client.WebClient; @RequiredArgsConstructor @@ -13,13 +17,38 @@ public class KakaoAccessTokenUseCase { @Value("${app-id.kakao}") private String APP_ID; + @Value("${kakao.redirect-uri}") + private String REDRECT_URI; + @Value("${kakao.authorization-grant-type}") + private String AUTHORIZATION_GRANT_TYPE; private final WebClient webClient; + + private static final String KAKAO_TOKEN_URI = "https://kauth.kakao.com/oauth/token"; private static final String USER_INFO_URI = "https://kapi.kakao.com/v2/user/me"; private static final String VALIDATE_TOKEN_URI = "https://kapi.kakao.com/v1/user/access_token_info"; + public KakaoUserInfoResponse getKakaoToken(String code) { + MultiValueMap requestBody = getRequestBody(code); + KakaoTokenInfoResponse tokenInfoResponse = webClient.post() + .uri(KAKAO_TOKEN_URI) + .headers(h -> h.setContentType(MediaType.APPLICATION_FORM_URLENCODED)) + .bodyValue(requestBody) + .retrieve() + .bodyToMono(KakaoTokenInfoResponse.class) + .block(); + return getUserInfo(tokenInfoResponse.getAccess_token()); + } - public KakaoUserInfoResponse getUserInfo(String accessToken) { + private MultiValueMap getRequestBody(String code) { + MultiValueMap requestBody = new LinkedMultiValueMap<>(); + requestBody.add("grant_type", AUTHORIZATION_GRANT_TYPE); + requestBody.add("client_id", APP_ID); + requestBody.add("redirect_uri", REDRECT_URI); + requestBody.add("code", code); + return requestBody; + } + private KakaoUserInfoResponse getUserInfo(String accessToken) { verifyAccessToken(accessToken); return webClient.get() diff --git a/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoSignInUseCase.java b/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoSignInUseCase.java index e8e4f548..f70772d5 100644 --- a/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoSignInUseCase.java +++ b/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoSignInUseCase.java @@ -1,5 +1,6 @@ package com.postgraduate.domain.auth.application.usecase.kakao; +import com.postgraduate.domain.auth.application.dto.req.KakaoCodeRequest; import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse; import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse; import com.postgraduate.domain.auth.application.dto.req.SignUpRequest; @@ -22,8 +23,8 @@ public class KakaoSignInUseCase { private final UserGetService userGetService; @Transactional - public AuthUserResponse getUser(String token) { - KakaoUserInfoResponse userInfo = kakaoTokenUseCase.getUserInfo(token); + public AuthUserResponse getUser(KakaoCodeRequest codeRequest) { + KakaoUserInfoResponse userInfo = kakaoTokenUseCase.getKakaoToken(codeRequest.getCode()); Long socialId = userInfo.getId(); Optional user = userGetService.bySocialId(socialId); return AuthMapper.mapToAuthUser(user, socialId); diff --git a/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java b/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java index ed62a293..74eb0a7a 100644 --- a/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java +++ b/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java @@ -1,6 +1,6 @@ package com.postgraduate.domain.auth.presentation; -import com.postgraduate.domain.auth.application.dto.req.KakaoLoginRequest; +import com.postgraduate.domain.auth.application.dto.req.KakaoCodeRequest; import com.postgraduate.domain.auth.application.dto.req.SignUpRequest; import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse; import com.postgraduate.domain.auth.application.dto.res.JwtTokenResponse; @@ -32,11 +32,10 @@ public class AuthController { @PostMapping("/login") @Operation(summary = "카카오 로그인", description = "회원인 경우 JWT를, 회원이 아닌 경우 socialId를 반환합니다(회원가입은 진행하지 않습니다).") - public ResponseDto authLogin(@RequestBody KakaoLoginRequest request) { - AuthUserResponse authUser = kakaoSignInUseCase.getUser(request.getAccessToken()); + public ResponseDto authLogin(@RequestBody KakaoCodeRequest tokenRequest) { + AuthUserResponse authUser = kakaoSignInUseCase.getUser(tokenRequest); if (authUser.getUser().isEmpty()) return ResponseDto.create(AUTH_NONE.getCode(), NOT_REGISTERED_USER_MESSAGE.getMessage(), authUser); - JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.getUser().get()); return ResponseDto.create(AUTH_ALREADY.getCode(), SUCCESS_AUTH_MESSAGE.getMessage(), jwtToken); } diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java b/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java index dc0bafdf..dfd688d5 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java @@ -19,10 +19,10 @@ public static AppliedMentoringInfo mapToExpectedAppliedInfo(Mentoring mentoring) .dates(dates) .seniorId(senior.getSeniorId()) .nickName(senior.getUser().getNickName()) - .postgradu(senior.getPostgradu()) - .professor(senior.getProfessor()) - .field(senior.getField()) - .chatLink(senior.getChatLink()) + .postgradu(senior.getInfo().getPostgradu()) + .professor(senior.getInfo().getProfessor()) + .field(senior.getInfo().getField()) + .chatLink(senior.getProfile().getChatLink()) .build(); } public static AppliedMentoringInfo mapToWaitingOrDoneAppliedInfo(Mentoring mentoring) { @@ -31,12 +31,12 @@ public static AppliedMentoringInfo mapToWaitingOrDoneAppliedInfo(Mentoring mento return AppliedMentoringInfo.builder() .mentoringId(mentoring.getMentoringId()) .dates(dates) - .term(senior.getTerm()) + .term(senior.getProfile().getTerm()) .seniorId(senior.getSeniorId()) .nickName(senior.getUser().getNickName()) - .postgradu(senior.getPostgradu()) - .professor(senior.getProfessor()) - .field(senior.getField()) + .postgradu(senior.getInfo().getPostgradu()) + .professor(senior.getInfo().getProfessor()) + .field(senior.getInfo().getField()) .build(); } public static AppliedMentoringDetailResponse mapToAppliedDetailInfo(Mentoring mentoring) { @@ -46,8 +46,8 @@ public static AppliedMentoringDetailResponse mapToAppliedDetailInfo(Mentoring me return AppliedMentoringDetailResponse.builder() .seniorId(senior.getSeniorId()) .nickName(senior.getUser().getNickName()) - .field(senior.getField()) - .professor(senior.getProfessor()) + .field(senior.getInfo().getField()) + .professor(senior.getInfo().getProfessor()) .topic(mentoring.getTopic()) .question(mentoring.getQuestion()) .dates(dates) diff --git a/src/main/java/com/postgraduate/domain/auth/application/dto/req/KakaoLoginRequest.java b/src/main/java/com/postgraduate/domain/senior/application/dto/req/SeniorCertificationRequest.java similarity index 59% rename from src/main/java/com/postgraduate/domain/auth/application/dto/req/KakaoLoginRequest.java rename to src/main/java/com/postgraduate/domain/senior/application/dto/req/SeniorCertificationRequest.java index 4378ccc5..cc26e8ee 100644 --- a/src/main/java/com/postgraduate/domain/auth/application/dto/req/KakaoLoginRequest.java +++ b/src/main/java/com/postgraduate/domain/senior/application/dto/req/SeniorCertificationRequest.java @@ -1,4 +1,4 @@ -package com.postgraduate.domain.auth.application.dto.req; +package com.postgraduate.domain.senior.application.dto.req; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; @@ -8,7 +8,7 @@ @Getter @AllArgsConstructor @NoArgsConstructor -public class KakaoLoginRequest { +public class SeniorCertificationRequest { @NotNull - private String accessToken; + private String certification; } diff --git a/src/main/java/com/postgraduate/domain/senior/application/dto/req/SeniorProfileAndAccountRequest.java b/src/main/java/com/postgraduate/domain/senior/application/dto/req/SeniorProfileAndAccountRequest.java new file mode 100644 index 00000000..9ca7266a --- /dev/null +++ b/src/main/java/com/postgraduate/domain/senior/application/dto/req/SeniorProfileAndAccountRequest.java @@ -0,0 +1,26 @@ +package com.postgraduate.domain.senior.application.dto.req; + +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class SeniorProfileAndAccountRequest { + @NotNull + private String info; + @NotNull + private String target; + @NotNull + private String chatLink; + @NotNull + private String time; + @NotNull + private String account; + @NotNull + private String bank; + @NotNull + private String rrn; +} diff --git a/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorInfoResponse.java b/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorInfoResponse.java new file mode 100644 index 00000000..601fb7da --- /dev/null +++ b/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorInfoResponse.java @@ -0,0 +1,16 @@ +package com.postgraduate.domain.senior.application.dto.res; + +import com.postgraduate.domain.senior.domain.entity.constant.Status; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Builder +@Getter +@AllArgsConstructor +public class SeniorInfoResponse { + private String nickName; + private String profile; + private Status certificationRegister; + private boolean profileRegister; +} diff --git a/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorProfileResponse.java b/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorProfileResponse.java new file mode 100644 index 00000000..40c4cc4d --- /dev/null +++ b/src/main/java/com/postgraduate/domain/senior/application/dto/res/SeniorProfileResponse.java @@ -0,0 +1,15 @@ +package com.postgraduate.domain.senior.application.dto.res; + +import com.postgraduate.domain.senior.domain.entity.Account; +import com.postgraduate.domain.senior.domain.entity.Profile; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Builder +@Getter +@AllArgsConstructor +public class SeniorProfileResponse { + private Profile profile; + private Account account; +} diff --git a/src/main/java/com/postgraduate/domain/senior/application/mapper/SeniorMapper.java b/src/main/java/com/postgraduate/domain/senior/application/mapper/SeniorMapper.java index 77315c4c..7a548efc 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/mapper/SeniorMapper.java +++ b/src/main/java/com/postgraduate/domain/senior/application/mapper/SeniorMapper.java @@ -1,7 +1,15 @@ package com.postgraduate.domain.senior.application.mapper; +import com.postgraduate.domain.senior.application.dto.req.SeniorProfileAndAccountRequest; +import com.postgraduate.domain.senior.application.dto.req.SeniorProfileRequest; import com.postgraduate.domain.senior.application.dto.req.SeniorSignUpRequest; +import com.postgraduate.domain.senior.application.dto.res.SeniorInfoResponse; +import com.postgraduate.domain.senior.application.dto.res.SeniorProfileResponse; +import com.postgraduate.domain.senior.domain.entity.Account; +import com.postgraduate.domain.senior.domain.entity.Info; +import com.postgraduate.domain.senior.domain.entity.Profile; import com.postgraduate.domain.senior.domain.entity.Senior; +import com.postgraduate.domain.senior.domain.entity.constant.Status; import com.postgraduate.domain.user.domain.entity.User; public class SeniorMapper { @@ -9,16 +17,70 @@ public class SeniorMapper { public static Senior mapToSenior(User user, SeniorSignUpRequest request) { return Senior.builder() .user(user) + .info(mapToInfo(request)) + .certification(request.getCertification()) + .account(mapToAccount(request)) + .build(); + } + + public static Info mapToInfo(SeniorSignUpRequest request) { + return Info.builder() .college(request.getCollege()) .major(request.getMajor()) .postgradu(request.getPostgradu()) .professor(request.getProfessor()) .lab(request.getLab()) .field(request.getField()) - .certification(request.getCertification()) - .account(request.getAccount()) + .build(); + } + + public static Account mapToAccount(SeniorSignUpRequest request) { + return Account.builder() .bank(request.getBank()) + .account(request.getAccount()) .rrn(request.getRrn()) .build(); } + + public static Account mapToAccount(SeniorProfileAndAccountRequest profileAndAccountPageRequest) { + return Account.builder() + .bank(profileAndAccountPageRequest.getBank()) + .account(profileAndAccountPageRequest.getAccount()) + .rrn(profileAndAccountPageRequest.getRrn()) + .build(); + } + + public static Profile mapToProfile(SeniorProfileAndAccountRequest profileAndAccountPageRequest) { + return Profile.builder() + .info(profileAndAccountPageRequest.getInfo()) + .chatLink(profileAndAccountPageRequest.getChatLink()) + .target(profileAndAccountPageRequest.getTarget()) + .time(profileAndAccountPageRequest.getTime()) + .build(); + } + + public static Profile mapToProfile(SeniorProfileRequest profileRequest) { + return Profile.builder() + .info(profileRequest.getInfo()) + .chatLink(profileRequest.getChatLink()) + .target(profileRequest.getTarget()) + .time(profileRequest.getTime()) + .build(); + } + + public static SeniorInfoResponse mapToSeniorInfo(Senior senior, Status certificationRegister, boolean profileRegister) { + return SeniorInfoResponse.builder() + .nickName(senior.getUser().getNickName()) + .profile(senior.getUser().getProfile()) + .certificationRegister(certificationRegister) + .profileRegister(profileRegister) + .build(); + } + + public static SeniorProfileResponse mapToSeniorProfileInfo(Senior senior) { + return SeniorProfileResponse.builder() + .profile(senior.getProfile()) + .account(senior.getAccount()) + .build(); + } } diff --git a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorMyPageUseCase.java b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorMyPageUseCase.java new file mode 100644 index 00000000..7a6ebb3f --- /dev/null +++ b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorMyPageUseCase.java @@ -0,0 +1,61 @@ +package com.postgraduate.domain.senior.application.usecase; + +import com.postgraduate.domain.senior.application.dto.req.SeniorCertificationRequest; +import com.postgraduate.domain.senior.application.dto.req.SeniorProfileAndAccountRequest; +import com.postgraduate.domain.senior.application.dto.res.SeniorInfoResponse; +import com.postgraduate.domain.senior.application.dto.res.SeniorProfileResponse; +import com.postgraduate.domain.senior.application.mapper.SeniorMapper; +import com.postgraduate.domain.senior.domain.entity.Account; +import com.postgraduate.domain.senior.domain.entity.Profile; +import com.postgraduate.domain.senior.domain.entity.Senior; +import com.postgraduate.domain.senior.domain.entity.constant.Status; +import com.postgraduate.domain.senior.domain.service.SeniorGetService; +import com.postgraduate.domain.senior.domain.service.SeniorUpdateService; +import com.postgraduate.domain.user.domain.entity.User; +import com.postgraduate.global.auth.AuthDetails; +import com.postgraduate.global.config.security.util.SecurityUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; + +import static java.util.Optional.ofNullable; + +@Service +@RequiredArgsConstructor +@Transactional +public class SeniorMyPageUseCase { + private final SeniorGetService seniorGetService; + private final SeniorUpdateService seniorUpdateService; + private final SecurityUtils securityUtils; + + public SeniorInfoResponse seniorInfo(AuthDetails authDetails) { + User user = securityUtils.getLoggedInUser(authDetails); + Senior senior = seniorGetService.byUser(user); + Status status = senior.getStatus(); + Optional profile = ofNullable(senior.getProfile()); + return SeniorMapper.mapToSeniorInfo(senior, status, profile.isPresent()); + } + + public void updateCertification(AuthDetails authDetails, SeniorCertificationRequest certificationRequest) { + User user = securityUtils.getLoggedInUser(authDetails); + Senior senior = seniorGetService.byUser(user); + seniorUpdateService.updateCertification(senior, certificationRequest.getCertification()); + } + + public void updateProfile(AuthDetails authDetails, SeniorProfileAndAccountRequest profileRequest) { + User user = securityUtils.getLoggedInUser(authDetails); + Senior senior = seniorGetService.byUser(user); + Profile profile = SeniorMapper.mapToProfile(profileRequest); + Account account = SeniorMapper.mapToAccount(profileRequest); + seniorUpdateService.updateSeniorProfileAndAccount(senior, profile, account); + } + + public SeniorProfileResponse getSeniorProfile(AuthDetails authDetails) { + User user = securityUtils.getLoggedInUser(authDetails); + Senior senior = seniorGetService.byUser(user); + SeniorProfileResponse seniorProfileResponse = SeniorMapper.mapToSeniorProfileInfo(senior); + return seniorProfileResponse; + } +} diff --git a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorSignUpUseCase.java b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorSignUpUseCase.java index 7dd3e828..d1e7551c 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorSignUpUseCase.java +++ b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorSignUpUseCase.java @@ -1,9 +1,13 @@ package com.postgraduate.domain.senior.application.usecase; +import com.postgraduate.domain.senior.application.dto.req.SeniorProfileRequest; import com.postgraduate.domain.senior.application.dto.req.SeniorSignUpRequest; import com.postgraduate.domain.senior.application.mapper.SeniorMapper; +import com.postgraduate.domain.senior.domain.entity.Profile; import com.postgraduate.domain.senior.domain.entity.Senior; +import com.postgraduate.domain.senior.domain.service.SeniorGetService; import com.postgraduate.domain.senior.domain.service.SeniorSaveService; +import com.postgraduate.domain.senior.domain.service.SeniorUpdateService; import com.postgraduate.domain.user.domain.entity.User; import com.postgraduate.domain.user.domain.entity.constant.Role; import com.postgraduate.domain.user.domain.service.UserUpdateService; @@ -19,6 +23,8 @@ public class SeniorSignUpUseCase { private final UserUpdateService userUpdateService; private final SeniorSaveService seniorSaveService; + private final SeniorGetService seniorGetService; + private final SeniorUpdateService seniorUpdateService; private final SecurityUtils securityUtils; public void signUp(AuthDetails authDetails, SeniorSignUpRequest request) { @@ -27,4 +33,11 @@ public void signUp(AuthDetails authDetails, SeniorSignUpRequest request) { Senior senior = SeniorMapper.mapToSenior(user, request); seniorSaveService.saveSenior(senior); } + + public void updateProfile(AuthDetails authDetails, SeniorProfileRequest profileRequest) { + User user = securityUtils.getLoggedInUser(authDetails); + Senior senior = seniorGetService.byUser(user); + Profile profile = SeniorMapper.mapToProfile(profileRequest); + seniorUpdateService.updateSeniorProfile(senior, profile); + } } diff --git a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorUpdateUseCase.java b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorUpdateUseCase.java deleted file mode 100644 index 964e6695..00000000 --- a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorUpdateUseCase.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.postgraduate.domain.senior.application.usecase; - -import com.postgraduate.domain.senior.application.dto.req.SeniorProfileRequest; -import com.postgraduate.domain.senior.domain.entity.Senior; -import com.postgraduate.domain.senior.domain.service.SeniorGetService; -import com.postgraduate.domain.senior.domain.service.SeniorUpdateService; -import com.postgraduate.domain.user.domain.entity.User; -import com.postgraduate.global.auth.AuthDetails; -import com.postgraduate.global.config.security.util.SecurityUtils; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@Transactional -@RequiredArgsConstructor -public class SeniorUpdateUseCase { - private final SeniorGetService seniorGetService; - private final SeniorUpdateService seniorUpdateService; - private final SecurityUtils securityUtils; - - public void updateProfile(AuthDetails authDetails, SeniorProfileRequest profileRequest) { - User user = securityUtils.getLoggedInUser(authDetails); - Senior senior = seniorGetService.byUser(user); - seniorUpdateService.updateSeniorProfile(senior, profileRequest); - } -} diff --git a/src/main/java/com/postgraduate/domain/senior/domain/entity/Account.java b/src/main/java/com/postgraduate/domain/senior/domain/entity/Account.java new file mode 100644 index 00000000..80e1ef48 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/senior/domain/entity/Account.java @@ -0,0 +1,24 @@ +package com.postgraduate.domain.senior.domain.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Embeddable +public class Account { + @Column(nullable = false) + private String account; + + @Column(nullable = false) + private String bank; + + @Column(nullable = false) + private String rrn; +} diff --git a/src/main/java/com/postgraduate/domain/senior/domain/entity/Info.java b/src/main/java/com/postgraduate/domain/senior/domain/entity/Info.java new file mode 100644 index 00000000..30b5952c --- /dev/null +++ b/src/main/java/com/postgraduate/domain/senior/domain/entity/Info.java @@ -0,0 +1,33 @@ +package com.postgraduate.domain.senior.domain.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +@Builder +@Embeddable +public class Info { + @Column(nullable = false) + private String college; + + @Column(nullable = false) + private String major; + + @Column(nullable = false) + private String postgradu; + + @Column(nullable = false) + private String professor; + + @Column(nullable = false) + private String lab; + + @Column(nullable = false) + private String field; +} diff --git a/src/main/java/com/postgraduate/domain/senior/domain/entity/Profile.java b/src/main/java/com/postgraduate/domain/senior/domain/entity/Profile.java new file mode 100644 index 00000000..41fd4a33 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/senior/domain/entity/Profile.java @@ -0,0 +1,24 @@ +package com.postgraduate.domain.senior.domain.entity; + +import jakarta.persistence.Embeddable; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +@Builder +@Embeddable +public class Profile { + private String info; + + private String target; + + private String chatLink; + + private String time; + + private Integer term; +} diff --git a/src/main/java/com/postgraduate/domain/senior/domain/entity/Senior.java b/src/main/java/com/postgraduate/domain/senior/domain/entity/Senior.java index 1fdd32c4..35bf55b6 100644 --- a/src/main/java/com/postgraduate/domain/senior/domain/entity/Senior.java +++ b/src/main/java/com/postgraduate/domain/senior/domain/entity/Senior.java @@ -1,18 +1,22 @@ package com.postgraduate.domain.senior.domain.entity; -import com.postgraduate.domain.senior.application.dto.req.SeniorProfileRequest; +import com.postgraduate.domain.senior.domain.entity.constant.Status; import com.postgraduate.domain.user.domain.entity.User; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.DynamicInsert; + +import static com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING; @Entity @Builder @AllArgsConstructor @NoArgsConstructor @Getter +@DynamicInsert public class Senior { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -22,55 +26,36 @@ public class Senior { private User user; @Column(nullable = false) - private String college; - - @Column(nullable = false) - private String major; - - @Column(nullable = false) - private String postgradu; - - @Column(nullable = false) - private String professor; + private String certification; @Column(nullable = false) - private String lab; + @Enumerated(EnumType.STRING) + @Builder.Default + private Status status = WAITING; @Column(nullable = false) - private String field; - - private String info; - - private String target; - - private String chatLink; - - private String time; - - private int term; - - @Column(nullable = false) - private String account; + private int hit; - @Column(nullable = false) - private String bank; + @Embedded + private Info info; - @Column(nullable = false) - private String certification; + @Embedded + private Account account; - @Column(nullable = false) - private String rrn; + @Embedded + private Profile profile; - @Column(nullable = false) - private boolean status; + public void updateProfile(Profile profile) { + this.profile = profile; + } - @Column(nullable = false) - private int hit; + public void updateProfileAndAccount(Profile profile, Account account) { + this.profile = profile; + this.account = account; + } - public void updateProfile(SeniorProfileRequest profileRequest) { - this.info = profileRequest.getInfo(); - this.target = profileRequest.getTarget(); - this.chatLink = profileRequest.getChatLink(); - this.time = profileRequest.getTime(); + public void updateCertification(String certification) { + this.certification = certification; + this.status = WAITING; } } diff --git a/src/main/java/com/postgraduate/domain/senior/domain/entity/constant/Status.java b/src/main/java/com/postgraduate/domain/senior/domain/entity/constant/Status.java new file mode 100644 index 00000000..6b4eda11 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/senior/domain/entity/constant/Status.java @@ -0,0 +1,10 @@ +package com.postgraduate.domain.senior.domain.entity.constant; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter +public enum Status { + NOT_APPROVE, WAITING, APPROVE +} diff --git a/src/main/java/com/postgraduate/domain/senior/domain/entity/repository/SeniorRepository.java b/src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorRepository.java similarity index 83% rename from src/main/java/com/postgraduate/domain/senior/domain/entity/repository/SeniorRepository.java rename to src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorRepository.java index 7c5a0eeb..1af1bfb5 100644 --- a/src/main/java/com/postgraduate/domain/senior/domain/entity/repository/SeniorRepository.java +++ b/src/main/java/com/postgraduate/domain/senior/domain/repository/SeniorRepository.java @@ -1,4 +1,4 @@ -package com.postgraduate.domain.senior.domain.entity.repository; +package com.postgraduate.domain.senior.domain.repository; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; diff --git a/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorGetService.java b/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorGetService.java index fe5b8171..6c83b6e2 100644 --- a/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorGetService.java +++ b/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorGetService.java @@ -1,7 +1,7 @@ package com.postgraduate.domain.senior.domain.service; import com.postgraduate.domain.senior.domain.entity.Senior; -import com.postgraduate.domain.senior.domain.entity.repository.SeniorRepository; +import com.postgraduate.domain.senior.domain.repository.SeniorRepository; import com.postgraduate.domain.user.domain.entity.User; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorSaveService.java b/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorSaveService.java index 24c39a5e..6c3d5b63 100644 --- a/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorSaveService.java +++ b/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorSaveService.java @@ -1,7 +1,7 @@ package com.postgraduate.domain.senior.domain.service; import com.postgraduate.domain.senior.domain.entity.Senior; -import com.postgraduate.domain.senior.domain.entity.repository.SeniorRepository; +import com.postgraduate.domain.senior.domain.repository.SeniorRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorUpdateService.java b/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorUpdateService.java index 2f940181..e58305f2 100644 --- a/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorUpdateService.java +++ b/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorUpdateService.java @@ -1,6 +1,8 @@ package com.postgraduate.domain.senior.domain.service; import com.postgraduate.domain.senior.application.dto.req.SeniorProfileRequest; +import com.postgraduate.domain.senior.domain.entity.Account; +import com.postgraduate.domain.senior.domain.entity.Profile; import com.postgraduate.domain.senior.domain.entity.Senior; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -9,7 +11,15 @@ @Service public class SeniorUpdateService { - public void updateSeniorProfile(Senior senior, SeniorProfileRequest profileRequest) { - senior.updateProfile(profileRequest); + public void updateSeniorProfile(Senior senior, Profile profile) { + senior.updateProfile(profile); + } + + public void updateSeniorProfileAndAccount(Senior senior, Profile profile, Account account) { + senior.updateProfileAndAccount(profile, account); + } + + public void updateCertification(Senior senior, String imageUrl) { + senior.updateCertification(imageUrl); } } diff --git a/src/main/java/com/postgraduate/domain/senior/presentation/SeniorController.java b/src/main/java/com/postgraduate/domain/senior/presentation/SeniorController.java index 7b382edc..ceb914c7 100644 --- a/src/main/java/com/postgraduate/domain/senior/presentation/SeniorController.java +++ b/src/main/java/com/postgraduate/domain/senior/presentation/SeniorController.java @@ -1,9 +1,13 @@ package com.postgraduate.domain.senior.presentation; +import com.postgraduate.domain.senior.application.dto.req.SeniorCertificationRequest; +import com.postgraduate.domain.senior.application.dto.req.SeniorProfileAndAccountRequest; import com.postgraduate.domain.senior.application.dto.req.SeniorProfileRequest; import com.postgraduate.domain.senior.application.dto.req.SeniorSignUpRequest; +import com.postgraduate.domain.senior.application.dto.res.SeniorInfoResponse; +import com.postgraduate.domain.senior.application.dto.res.SeniorProfileResponse; +import com.postgraduate.domain.senior.application.usecase.SeniorMyPageUseCase; import com.postgraduate.domain.senior.application.usecase.SeniorSignUpUseCase; -import com.postgraduate.domain.senior.application.usecase.SeniorUpdateUseCase; import com.postgraduate.global.auth.AuthDetails; import com.postgraduate.global.dto.ResponseDto; import io.swagger.v3.oas.annotations.Operation; @@ -12,10 +16,8 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; -import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode.SENIOR_CREATE; -import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode.SENIOR_UPDATE; -import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage.SUCCESS_SENIOR_SIGN_UP_MESSAGE; -import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage.SUCCESS_UPDATE_PROFILE_MESSAGE; +import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode.*; +import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage.*; @RestController @@ -24,21 +26,52 @@ @Tag(name = "SENIOR Controller") public class SeniorController { private final SeniorSignUpUseCase signUpUseCase; - private final SeniorUpdateUseCase updateUseCase; + private final SeniorMyPageUseCase myPageUseCase; @PostMapping("/signup") @Operation(summary = "대학원생 가입 - 필수 과정만", description = "대학원생 회원가입 - 필수 과정만") public ResponseDto singUpSenior(@AuthenticationPrincipal AuthDetails authDetails, @RequestBody SeniorSignUpRequest signUpRequest) { signUpUseCase.signUp(authDetails, signUpRequest); - return ResponseDto.create(SENIOR_CREATE.getCode(), SUCCESS_SENIOR_SIGN_UP_MESSAGE.getMessage()); + return ResponseDto.create(SENIOR_CREATE.getCode(), CREATE_SENIOR.getMessage()); } @PatchMapping("/profile") - @Operation(summary = "대학원생 프로필 등록", description = "소개글, 추천대상, 오픈채팅방 링크, 가능 시간대, 소통시간") + @Operation(summary = "대학원생 프로필 등록") public ResponseDto singUpSenior(@AuthenticationPrincipal AuthDetails authDetails, - @RequestBody SeniorProfileRequest profileRequest) { - updateUseCase.updateProfile(authDetails, profileRequest); - return ResponseDto.create(SENIOR_UPDATE.getCode(), SUCCESS_UPDATE_PROFILE_MESSAGE.getMessage()); + @RequestBody SeniorProfileRequest profileRequest) { + signUpUseCase.updateProfile(authDetails, profileRequest); + return ResponseDto.create(SENIOR_UPDATE.getCode(), UPDATE_PROFILE.getMessage()); } + + @PatchMapping("/certification") + @Operation(summary = "대학원생 인증", description = "이미지 업로드 이후 url 담아서 요청") + public ResponseDto updateCertification(@AuthenticationPrincipal AuthDetails authDetails, + @RequestBody SeniorCertificationRequest certificationRequest) { + myPageUseCase.updateCertification(authDetails, certificationRequest); + return ResponseDto.create(SENIOR_UPDATE.getCode(), UPDATE_CERTIFICATION.getMessage()); + } + + @GetMapping("/me") + @Operation(summary = "대학원생 마이페이지 기본 정보", description = "닉네임, 프로필 사진, 인증 여부") + public ResponseDto getSeniorInfo(@AuthenticationPrincipal AuthDetails authDetails) { + SeniorInfoResponse seniorInfoResponse = myPageUseCase.seniorInfo(authDetails); + return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_INFO.getMessage(), seniorInfoResponse); + } + + @GetMapping("/me/profile") + @Operation(summary = "대학원생 마이페이지 프로필 보기") + public ResponseDto getSeniorProfile(@AuthenticationPrincipal AuthDetails authDetails) { + SeniorProfileResponse seniorProfile = myPageUseCase.getSeniorProfile(authDetails); + return ResponseDto.create(SENIOR_FIND.getCode(), GET_SENIOR_PROFILE.getMessage(), seniorProfile); + } + + @PatchMapping("/me/profile") + @Operation(summary = "대학원생 프로필 수정") + public ResponseDto updateProfile(@AuthenticationPrincipal AuthDetails authDetails, + @RequestBody SeniorProfileAndAccountRequest profileAndAccountPageRequest) { + myPageUseCase.updateProfile(authDetails, profileAndAccountPageRequest); + return ResponseDto.create(SENIOR_UPDATE.getCode(), UPDATE_PROFILE.getMessage()); + } + } diff --git a/src/main/java/com/postgraduate/domain/senior/presentation/constant/SeniorResponseMessage.java b/src/main/java/com/postgraduate/domain/senior/presentation/constant/SeniorResponseMessage.java index d13825bf..e25770c7 100644 --- a/src/main/java/com/postgraduate/domain/senior/presentation/constant/SeniorResponseMessage.java +++ b/src/main/java/com/postgraduate/domain/senior/presentation/constant/SeniorResponseMessage.java @@ -6,8 +6,11 @@ @Getter @RequiredArgsConstructor public enum SeniorResponseMessage { - SUCCESS_SENIOR_SIGN_UP_MESSAGE("대학원생 가입에 성공하였습니다."), - SUCCESS_UPDATE_PROFILE_MESSAGE("대학원생 프로필 등록에 성공하였습니다"); + CREATE_SENIOR("대학원생 가입에 성공하였습니다."), + UPDATE_PROFILE("대학원생 프로필 등록에 성공하였습니다"), + GET_SENIOR_INFO("대학원생 정보 조회에 성공하였습니다"), + GET_SENIOR_PROFILE("대학원생 프로필 조회에 성공하였습니다"), + UPDATE_CERTIFICATION("대학원생 인증사진 업로드에 성공하였습니다"); private final String message; } diff --git a/src/test/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoSignInUseCaseTest.java b/src/test/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoSignInUseCaseTest.java index 720a77c1..cdce4070 100644 --- a/src/test/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoSignInUseCaseTest.java +++ b/src/test/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoSignInUseCaseTest.java @@ -1,5 +1,6 @@ package com.postgraduate.domain.auth.application.usecase.kakao; +import com.postgraduate.domain.auth.application.dto.req.KakaoCodeRequest; import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse; import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse; import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse.KakaoAccount; @@ -26,20 +27,22 @@ class KakaoSignInUseCaseTest { KakaoSignInUseCase kakaoSignInUseCase; @Test void 첫_로그인_socialId_반환() { - String token = "abcd"; - given(kakaoAccessTokenUseCase.getUserInfo(token)).willReturn(new KakaoUserInfoResponse(10000L, new KakaoAccount())); + String code = "abcdefg"; + KakaoCodeRequest kakaoCodeRequest = new KakaoCodeRequest(code); + given(kakaoAccessTokenUseCase.getKakaoToken(code)).willReturn(new KakaoUserInfoResponse(10000L, new KakaoAccount())); given(userGetService.bySocialId(10000L)).willReturn(Optional.ofNullable(null)); - AuthUserResponse authUserResponse = kakaoSignInUseCase.getUser(token); + AuthUserResponse authUserResponse = kakaoSignInUseCase.getUser(kakaoCodeRequest); Assertions.assertThat(authUserResponse.getSocialId()).isEqualTo(10000L); Assertions.assertThat(authUserResponse.getUser().isEmpty()).isTrue(); } @Test void 기존_유저_로그인_user반환() { - String token = "abcd"; - given(kakaoAccessTokenUseCase.getUserInfo(token)).willReturn(new KakaoUserInfoResponse(10000L, new KakaoAccount())); + String code = "abcdefg"; + KakaoCodeRequest kakaoCodeRequest = new KakaoCodeRequest(code); + given(kakaoAccessTokenUseCase.getKakaoToken(code)).willReturn(new KakaoUserInfoResponse(10000L, new KakaoAccount())); given(userGetService.bySocialId(10000L)).willReturn(Optional.ofNullable(new User())); - AuthUserResponse authUserResponse = kakaoSignInUseCase.getUser(token); + AuthUserResponse authUserResponse = kakaoSignInUseCase.getUser(kakaoCodeRequest); Assertions.assertThat(authUserResponse.getSocialId()).isEqualTo(10000L); Assertions.assertThat(authUserResponse.getUser().isEmpty()).isFalse(); }