Skip to content

Commit

Permalink
Merge pull request #63 from WE-ARE-RACCOONS/RAC-219
Browse files Browse the repository at this point in the history
RAC-129 refactor : ๊ธฐ์กด ๊ตฌํ˜„ ์ ๊ฒ€ ๋ฐ ์ˆ˜์ • ์‚ฌํ•ญ ์ ์šฉ
  • Loading branch information
ywj9811 authored Dec 10, 2023
2 parents 1e964c4 + bd92e26 commit a562733
Show file tree
Hide file tree
Showing 28 changed files with 278 additions and 279 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.postgraduate.domain.auth.application.dto.req;

import jakarta.validation.constraints.NotNull;

public record CodeRequest(@NotNull String code) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.postgraduate.domain.auth.application.usecase;

import com.postgraduate.domain.auth.application.dto.req.CodeRequest;
import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse;

public interface SignInUseCase {
AuthUserResponse getUser(CodeRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.postgraduate.domain.auth.application.usecase.oauth;

import com.postgraduate.domain.auth.application.usecase.SignInUseCase;
import com.postgraduate.domain.auth.application.usecase.oauth.kakao.KakaoSignInUseCase;
import com.postgraduate.domain.auth.exception.OauthException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@RequiredArgsConstructor
@Component
public class SelectOauth {
private final KakaoSignInUseCase kakaoSignInUseCase;

public SignInUseCase selectStrategy(String provider) {
switch (provider) {
case "KAKAO" : return kakaoSignInUseCase;
default: throw new OauthException();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.postgraduate.domain.auth.application.usecase.kakao;
package com.postgraduate.domain.auth.application.usecase.oauth.kakao;

import com.postgraduate.domain.auth.application.dto.req.KakaoCodeRequest;
import com.postgraduate.domain.auth.application.dto.req.CodeRequest;
import com.postgraduate.domain.auth.application.dto.res.KakaoTokenInfoResponse;
import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse;
import com.postgraduate.domain.auth.exception.KakaoCodeException;
Expand Down Expand Up @@ -31,8 +31,8 @@ public class KakaoAccessTokenUseCase {
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";

public KakaoUserInfoResponse getKakaoToken(KakaoCodeRequest codeRequest) {
MultiValueMap<String, String> requestBody = getRequestBody(codeRequest.getCode());
public KakaoUserInfoResponse getAccessToken (CodeRequest codeRequest) {
MultiValueMap<String, String> requestBody = getRequestBody(codeRequest.code());
try {
KakaoTokenInfoResponse tokenInfoResponse = webClient.post()
.uri(KAKAO_TOKEN_URI)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.postgraduate.domain.auth.application.usecase.kakao;
package com.postgraduate.domain.auth.application.usecase.oauth.kakao;

import com.postgraduate.domain.auth.application.dto.req.KakaoCodeRequest;
import com.postgraduate.domain.auth.application.dto.req.CodeRequest;
import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse;
import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse;
import com.postgraduate.domain.auth.application.mapper.AuthMapper;
import com.postgraduate.domain.auth.application.usecase.SignInUseCase;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.domain.service.UserGetService;
import lombok.RequiredArgsConstructor;
Expand All @@ -15,12 +16,13 @@
@Service
@RequiredArgsConstructor
@Transactional
public class KakaoSignInUseCase {
public class KakaoSignInUseCase implements SignInUseCase {
private final KakaoAccessTokenUseCase kakaoTokenUseCase;
private final UserGetService userGetService;

public AuthUserResponse getUser(KakaoCodeRequest codeRequest) {
KakaoUserInfoResponse userInfo = kakaoTokenUseCase.getKakaoToken(codeRequest);
@Override
public AuthUserResponse getUser(CodeRequest codeRequest) {
KakaoUserInfoResponse userInfo = kakaoTokenUseCase.getAccessToken(codeRequest);
Long socialId = userInfo.getId();
Optional<User> user = userGetService.bySocialId(socialId);
return AuthMapper.mapToAuthUser(user, socialId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.postgraduate.domain.auth.exception;

import static com.postgraduate.domain.auth.presentation.contant.AuthResponseCode.NONE_PROVIDER;
import static com.postgraduate.domain.auth.presentation.contant.AuthResponseMessage.PROVIDER_NONE;

public class OauthException extends AuthException{
public OauthException() {
super(PROVIDER_NONE.getMessage(), NONE_PROVIDER.getCode());
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.postgraduate.domain.auth.presentation;

import com.postgraduate.domain.auth.application.dto.req.KakaoCodeRequest;
import com.postgraduate.domain.auth.application.dto.req.CodeRequest;
import com.postgraduate.domain.auth.application.dto.req.SeniorChangeRequest;
import com.postgraduate.domain.auth.application.dto.req.SeniorSignUpRequest;
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;
import com.postgraduate.domain.auth.application.usecase.oauth.SelectOauth;
import com.postgraduate.domain.auth.application.usecase.SignUpUseCase;
import com.postgraduate.domain.auth.application.usecase.jwt.JwtUseCase;
import com.postgraduate.domain.auth.application.usecase.kakao.KakaoSignInUseCase;
import com.postgraduate.domain.auth.application.usecase.SignInUseCase;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.dto.ResponseDto;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -28,20 +29,27 @@
@RequestMapping("/auth")
@Tag(name = "AUTH Controller")
public class AuthController {
private final KakaoSignInUseCase kakaoSignInUseCase;
private final SelectOauth selectOauth;
private final SignUpUseCase signUpUseCase;
private final JwtUseCase jwtUseCase;

@PostMapping("/login")
@Operation(summary = "์นด์นด์˜ค ๋กœ๊ทธ์ธ", description = "ํšŒ์›์ธ ๊ฒฝ์šฐ JWT๋ฅผ, ํšŒ์›์ด ์•„๋‹Œ ๊ฒฝ์šฐ socialId๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค(ํšŒ์›๊ฐ€์ž…์€ ์ง„ํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค).")
public ResponseDto<?> authLogin(@RequestBody KakaoCodeRequest request) {
AuthUserResponse authUser = kakaoSignInUseCase.getUser(request);
@PostMapping("/login/{provider}")
@Operation(summary = "์†Œ์…œ ๋กœ๊ทธ์ธ", description = "ํšŒ์›์ธ ๊ฒฝ์šฐ JWT๋ฅผ, ํšŒ์›์ด ์•„๋‹Œ ๊ฒฝ์šฐ socialId๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค(ํšŒ์›๊ฐ€์ž…์€ ์ง„ํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค).")
public ResponseDto<?> authLogin(@RequestBody CodeRequest request, @PathVariable String provider) {
SignInUseCase signInUseCase = selectOauth.selectStrategy(provider);
AuthUserResponse authUser = signInUseCase.getUser(request);
if (authUser.getUser().isEmpty())
return ResponseDto.create(AUTH_NONE.getCode(), NOT_REGISTERED_USER.getMessage(), authUser);
JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.getUser().get());
return ResponseDto.create(AUTH_ALREADY.getCode(), SUCCESS_AUTH.getMessage(), jwtToken);
}

// @PostMapping("/logout")
// @Operation(summary = "๋กœ๊ทธ์•„์›ƒ", description = "ํ† ํฐ ๊ฐ™์ด ๋ณด๋‚ด์ฃผ์„ธ์š”")
// public ResponseDto logout() {
// return ResponseDto.create(AUTH_CREATE.getCode(), SUCCESS_AUTH.getMessage());
// }

@PostMapping("/user/signup")
@Operation(summary = "๋Œ€ํ•™์ƒ ํšŒ์›๊ฐ€์ž…", description = "๋กœ๊ทธ์ธ API์—์„œ ๋ฐ˜ํ™˜ํ•œ socialId, ๋‹‰๋„ค์ž„, ๋ฒˆํ˜ธ, ๋งˆ์ผ€ํŒ… ์ˆ˜์‹ ์—ฌ๋ถ€, ํฌ๋ง ํ•™๊ณผ, ํฌ๋ง ๋ถ„์•ผ, ๋งค์นญ ํฌ๋ง ์—ฌ๋ถ€")
public ResponseDto<JwtTokenResponse> signUpUser(@RequestBody SignUpRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum AuthResponseCode {
AUTH_DENIED("EX900"),
AUTH_INVALID_KAKAO("EX901"),
AUTH_KAKAO_CODE("EX902"),
AUTH_FAILED("EX903");
AUTH_FAILED("EX903"),
NONE_PROVIDER("EX904");
private final String code;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum AuthResponseMessage {
PERMISSION_DENIED("๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค."),
KAKAO_INVALID("์นด์นด์˜ค ์ •๋ณด๊ฐ€ ์œ ํšจํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
KAKAO_CODE("์นด์นด์˜ค ์ฝ”๋“œ๊ฐ€ ์œ ํšจํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
FAILED_AUTH("์‚ฌ์šฉ์ž ์ธ์ฆ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.");
FAILED_AUTH("์‚ฌ์šฉ์ž ์ธ์ฆ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค."),
PROVIDER_NONE("PROVIDER๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.");
private final String message;
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
package com.postgraduate.domain.mentoring.application.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;


@Getter
@Builder
@AllArgsConstructor
public class DoneMentoringInfo {
private Long mentoringId;
private Long seniorId;
private String profile;
private String nickName;
private String postgradu;
private String major;
private String lab;
private String date;
private int term;
public record DoneMentoringInfo(Long mentoringId, Long seniorId, String profile, String nickName, String postgradu,
String major, String lab, String date, int term) {
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
package com.postgraduate.domain.mentoring.application.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDate;

@Getter
@Builder
@AllArgsConstructor
public class DoneSeniorMentoringInfo {
private Long mentoringId;
private String profile;
private String nickname;
private int term;
private String date;
private LocalDate salaryDate;
private Boolean status;
public record DoneSeniorMentoringInfo(Long mentoringId, String profile, String nickName, int term, String date,
LocalDate salaryDate, Boolean status) {
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
package com.postgraduate.domain.mentoring.application.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;


@Getter
@Builder
@AllArgsConstructor
public class ExpectedMentoringInfo {
private Long mentoringId;
private Long seniorId;
private String profile;
private String nickName;
private String postgradu;
private String major;
private String lab;
private String date;
private int term;
private String chatLink;
public record ExpectedMentoringInfo(Long mentoringId, Long seniorId, String profile, String nickName, String postgradu,
String major, String lab, String date, int term, String chatLink) {
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
package com.postgraduate.domain.mentoring.application.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@AllArgsConstructor
public class ExpectedSeniorMentoringInfo {
private Long mentoringId;
private String profile;
private String nickname;
private int term;
private String date;
public record ExpectedSeniorMentoringInfo(Long mentoringId, String profile, String nickName, int term, String date) {
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
package com.postgraduate.domain.mentoring.application.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;


@Getter
@Builder
@AllArgsConstructor
public class WaitingMentoringInfo {
private Long mentoringId;
private Long seniorId;
private String profile;
private String nickName;
private String postgradu;
private String major;
private String lab;
private int term;
public record WaitingMentoringInfo(Long mentoringId, Long seniorId, String profile, String nickName, String postgradu,
String major, String lab, int term) {
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
package com.postgraduate.domain.mentoring.application.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@AllArgsConstructor
public class WaitingSeniorMentoringInfo {
private Long mentoringId;
private String profile;
private String nickname;
private int term;
private long remainTime;
public record WaitingSeniorMentoringInfo(Long mentoringId, String profile, String nickName, int term, long remainTime) {
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
package com.postgraduate.domain.mentoring.application.dto.res;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Builder
@AllArgsConstructor
@Getter
public class SeniorMentoringDetailResponse {
private String profile;
private String nickName;
private String topic;
private String question;
private String[] dates;
private int term;
public record SeniorMentoringDetailResponse(String profile, String nickName, String topic, String question,
String[] dates, int term) {
}
Loading

0 comments on commit a562733

Please sign in to comment.