Skip to content

Commit

Permalink
Merge pull request #46 from Genti2024/feat/pgres-status
Browse files Browse the repository at this point in the history
Oauth kakao, apple, 기능개발 및 문서화 #26 #42 #43 #44 #45 #47
  • Loading branch information
LeeJae-H authored Jul 16, 2024
2 parents 6be717d + d996373 commit 8baa7e7
Show file tree
Hide file tree
Showing 81 changed files with 354 additions and 344 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ subprojects {
// redis 사용간 localdatetime json 직렬화 위해
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.1'


// swagger( auth, external dto가 문서화되지 않아서 임시로 프로젝트 전체에 추가
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'


// lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
3 changes: 0 additions & 3 deletions genti-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ dependencies {
// testRuntimeOnly 'com.h2database:h2'
runtimeOnly 'com.h2database:h2'

// swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

implementation project(":genti-domain")
implementation project(":genti-external")
implementation project(":genti-common")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,30 @@

import com.gt.genti.auth.dto.request.AppleLoginRequestDto;
import com.gt.genti.auth.service.AuthService;
import com.gt.genti.error.ResponseCode;
import com.gt.genti.jwt.JwtTokenProvider;
import com.gt.genti.jwt.TokenGenerateCommand;
import com.gt.genti.jwt.TokenResponse;
import com.gt.genti.model.LogAction;
import com.gt.genti.model.LogItem;
import com.gt.genti.model.LogRequester;
import com.gt.genti.model.Logging;
import com.gt.genti.user.dto.request.AppleLoginRequest;
import com.gt.genti.user.dto.request.SocialLoginRequestImpl;
import com.gt.genti.user.dto.response.SocialLoginResponse;
import com.gt.genti.swagger.EnumResponse;
import com.gt.genti.swagger.EnumResponses;
import com.gt.genti.auth.dto.request.AppleLoginRequest;
import com.gt.genti.auth.dto.request.SocialLoginRequestImpl;
import com.gt.genti.auth.dto.response.SocialLoginResponse;
import com.gt.genti.user.model.AuthUser;
import com.gt.genti.user.model.OauthPlatform;
import com.gt.genti.user.model.UserRole;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
Expand All @@ -42,38 +52,69 @@ public class AuthController {
private final JwtTokenProvider jwtTokenProvider;
private final AuthService authService;

@GetMapping("/login/v1/oauth")
@Operation(summary = "oauth 로그인 페이지 호출", description = "구글, 카카오 oauth로그인페이지 로 Redirect 됩니다. url은 HttpHeader에 포함되어있습니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "303", description = "리디렉션을 위한 응답 헤더를 포함합니다.", headers = {
@Header(name = "Location", description = "리디렉션 URL", schema = @Schema(type = "string"))
}, content = @Content(schema = @Schema(hidden = true)))
})
@GetMapping("/login/v1/oauth2")
@Logging(item = LogItem.OAUTH, action = LogAction.LOGIN, requester = LogRequester.ANONYMOUS)
public ResponseEntity<Object> login(
@Parameter(description = "호출할 Oauth platform 종류", example = "KAKAO", schema = @Schema(allowableValues = {
"KAKAO"}))
@RequestParam(name = "oauthPlatform") OauthPlatform oauthPlatform) {
HttpHeaders httpHeaders = authService.getOauthRedirect(oauthPlatform);
return new ResponseEntity<>(httpHeaders, HttpStatus.SEE_OTHER);
}

@Operation(summary = "apple 로그인 후 토큰으로 로그인", description = "앱에서 apple 로그인을 수행한 후 받은 token을 전달받아 apple auth 서버와 통신 후 로그인 처리")
@EnumResponses(value = {
@EnumResponse(ResponseCode.OK),
@EnumResponse(ResponseCode.AppleOauthClaimInvalid),
@EnumResponse(ResponseCode.AppleOauthIdTokenExpired),
@EnumResponse(ResponseCode.AppleOauthIdTokenIncorrect),
@EnumResponse(ResponseCode.AppleOauthIdTokenInvalid),
@EnumResponse(ResponseCode.AppleOauthJwtValueInvalid),
@EnumResponse(ResponseCode.AppleOauthPublicKeyInvalid),
})
@PostMapping("/login/v1/oauth2/code/apple")
@Logging(item = LogItem.OAUTH_APPLE, action = LogAction.LOGIN, requester = LogRequester.ANONYMOUS)
public ResponseEntity<ApiResult<SocialLoginResponse>> loginApple(@RequestBody @Valid AppleLoginRequestDto request) {
public ResponseEntity<ApiResult<SocialLoginResponse>> loginApple(
@RequestBody @Valid AppleLoginRequestDto request) {
return success(authService.login(AppleLoginRequest.of(OauthPlatform.APPLE, request.getToken())));
}

@Operation(summary = "kakao 로그인 후 redirect url", description = "FE에서 직접 호출할 일은 없습니다.")
@EnumResponses(value = {
@EnumResponse(ResponseCode.OK),
})
@GetMapping("/login/v1/oauth2/code/kakao")
@Logging(item = LogItem.OAUTH_KAKAO, action = LogAction.LOGIN, requester = LogRequester.ANONYMOUS)
public ResponseEntity<ApiResult<SocialLoginResponse>> kakaoLogin(
@RequestParam(name = "code") final String code) {
return success(authService.login(SocialLoginRequestImpl.of(OauthPlatform.KAKAO, code)));
}

@Deprecated
@Operation(summary = "google 로그인 후 redirect url", description = "FE에서 직접 호출할 일은 없습니다.")
@EnumResponses(value = {
@EnumResponse(ResponseCode.OK),
})
@GetMapping("/login/v1/oauth2/code/google")
@Logging(item = LogItem.OAUTH_GOOGLE, action = LogAction.LOGIN, requester = LogRequester.ANONYMOUS)
public ResponseEntity<ApiResult<SocialLoginResponse>> googleLogin(
@RequestParam(name = "code") final String code) {
return success(authService.login(SocialLoginRequestImpl.of(OauthPlatform.GOOGLE, code)));
}

@Operation(summary = "테스트용 jwt 토큰 발급", description = "")
@EnumResponses(value = {
@EnumResponse(ResponseCode.OK)
})
@GetMapping("/login/testjwt")
public ResponseEntity<ApiResult<TokenResponse>> getTestJwt(
@NotNull @RequestParam(name = "role", value = "role") UserRole role) {
log.info("요청 ");
Map<UserRole, String> userIdMapper = Map.of(UserRole.USER, "2", UserRole.ADMIN, "1", UserRole.CREATOR, "4");
String userId = userIdMapper.get(role);
TokenGenerateCommand command = TokenGenerateCommand.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gt.genti.user.dto.request;
package com.gt.genti.auth.dto.request;

import com.gt.genti.user.model.OauthPlatform;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gt.genti.auth.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand All @@ -9,8 +10,9 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Getter
@Schema(name = "[Auth][Anonymous] 애플 로그인 요청 dto", description = "토큰 전달")
public class AppleLoginRequestDto {

@NotBlank
@Schema(description = "애플로그인 성공후 받은 토큰", example = "cvoeEIrnf23.4122")
private String token;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gt.genti.user.dto.request;
package com.gt.genti.auth.dto.request;

import com.gt.genti.user.model.OauthPlatform;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gt.genti.user.dto.request;
package com.gt.genti.auth.dto.request;

import com.gt.genti.user.model.OauthPlatform;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@Getter
@RequiredArgsConstructor
@Schema(description = "인증 토큰 Refresh 요청 Dto")
@Schema(name = "[Auth][Anonymous] Genti 인증토큰 Refresh 요청 Dto", description = "토큰 전달")
public class TokenRefreshRequestDto {
@NotBlank
@Schema(description = "refreshToken")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.gt.genti.auth.dto.response;

import com.gt.genti.jwt.TokenResponse;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(name = "[Auth][Anonymous] 소셜 로그인 응답 Dto")
public record SocialLoginResponse(
@Schema(description = "유저 Db Id", example = "1")
Long userId,
@Schema(description = "유저 이름 (애플의 경우에는 공백(\"\"))", example = "서병렬", allowableValues = {"", "서병렬"})
String userName,
@Schema(description = "oauth platform 이메일", example = "[email protected]")
String email,
@Schema(description = "신규가입시 true", example = "true")
boolean isNewUser,

TokenResponse token
) {
public static SocialLoginResponse of(Long userId, String userName, String email, boolean isNewUser, TokenResponse token) {
return new SocialLoginResponse(userId, userName, email, isNewUser, TokenResponse.of(token.accessToken(), token.refreshToken()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.gt.genti.error.ExpectedException;
import com.gt.genti.error.ResponseCode;
import com.gt.genti.jwt.JwtTokenProvider;
import com.gt.genti.user.dto.request.SocialLoginRequest;
import com.gt.genti.user.dto.response.SocialLoginResponse;
import com.gt.genti.auth.dto.request.SocialLoginRequest;
import com.gt.genti.auth.dto.response.SocialLoginResponse;
import com.gt.genti.user.model.OauthPlatform;
import com.gt.genti.user.model.User;
import com.gt.genti.user.repository.UserRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.gt.genti.swagger.SwaggerEnumOperationCustomizer;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gt.genti.swagger;
package com.gt.genti.config;

import static com.gt.genti.response.GentiResponse.*;
import static org.springframework.util.MimeTypeUtils.*;

import java.lang.reflect.ParameterizedType;
Expand All @@ -14,8 +15,9 @@

import com.gt.genti.error.ExpectedException;
import com.gt.genti.error.ResponseCode;
import com.gt.genti.response.GentiResponse;
import com.gt.genti.response.GentiResponse.ApiResult;
import com.gt.genti.swagger.EnumResponseGroup;
import com.gt.genti.swagger.EnumResponses;
import com.gt.genti.swagger.RequireImageUpload;

import io.swagger.v3.core.converter.ModelConverters;
import io.swagger.v3.oas.models.Operation;
Expand All @@ -33,7 +35,7 @@ public class SwaggerEnumOperationCustomizer implements OperationCustomizer {

@SuppressWarnings("rawtypes")
private final Schema errorEntitySchema = ModelConverters.getInstance()
.readAllAsResolvedSchema(GentiResponse.ApiResult.class).schema;
.readAllAsResolvedSchema(ApiResult.class).schema;

@Override
public Operation customize(Operation operation, HandlerMethod handlerMethod) {
Expand Down Expand Up @@ -88,7 +90,7 @@ private ApiResponse convertErrorResponse(ResponseCode code) {
return convertResponseInner(
errorEntitySchema.description(code.getErrorMessage()),
code,
GentiResponse.error(code)
error(code)
);
}

Expand All @@ -104,14 +106,12 @@ private Schema customizeSchema(ResponseCode responseCode, Type dtoType) {
Schema schema = ModelConverters.getInstance().readAllAsResolvedSchema(dtoType).schema;
Map<String, Schema> properties = schema.getProperties();
Boolean success = responseCode.isSuccess();
Integer status = responseCode.getHttpStatusCode().value();
String code = responseCode.getErrorCode();
String message = responseCode.getErrorMessage();
String errorCode = responseCode.getErrorCode();
String errorMessage = responseCode.getErrorMessage();

properties.get("success").setDefault(success);
properties.get("status").setDefault(status);
properties.get("code").setDefault(code);
properties.get("message").setDefault(message);
properties.get("errorCode").setDefault(errorCode);
properties.get("errorMessage").setDefault(errorMessage);

return schema;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

// @Tag(name = "RequestDtos", description = "RequestDtos")
@Schema(description = "계좌정보 수정 요청 Dto")
@Getter
@NoArgsConstructor
@Schema(name = "[Creator][Creator] 공급자 계좌정보 수정 요청 Dto", description = "계좌 정보 수정")
public class AccountUpdateRequestDto {

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@Getter
@NoArgsConstructor
@Schema(description = "공급자 작업가능상태 수정 요청 dto")
@Schema(name = "[Creator][Creator] 공급자 작업가능상태 수정 요청 dto", description = "작업가능상태 수정")
public class CreatorStatusUpdateRequestDto {
@NotNull
@Schema(description = "변경하고자 하는 작업가능여부")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

@Schema(description = "어드민의 공급자 조회 응답 dto")
@Getter
@NoArgsConstructor
@Schema(name = "[Creator][Admin] 어드민의 공급자 조회 응답 dto")
public class CreatorFindByAdminResponseDto {
@Schema(description = "공급자 DB Id", example = "1")
Long creatorId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

@Schema(description = "공급자 조회 응답 dto")
@Getter
@NoArgsConstructor
@Schema(name = "[Creator][Creator] 공급자 조회 응답 dto")
public class CreatorFindResponseDto {
@Schema(description = "공급자 DB Id", example = "1")
Long creatorId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

@Schema(description = "공급자 작업가능상태 변경 후 응답 dto")

@Getter
@NoArgsConstructor
@Schema(name = "[Creator][Creator] 공급자 작업가능상태 변경 성공 응답 dto")
public class CreatorStatusUpdateResponseDto {
@Schema(description = "작업가능 여부")
Boolean workable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

@Schema(description = "잔액 조회 dto")
@Getter
@NoArgsConstructor
@Schema(name = "[Deposit][Admin] 공급자 잔액 조회 by 어드민 dto")
public class DepositFindByAdminResponseDto {
@Schema(description = "잔액 테이블 Id", example = "1")
Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

@Schema(description = "잔액 조회 dto")
@Getter
@NoArgsConstructor
@Schema(name = "[Deposit][Creator] 공급자 잔액 조회 by 공급자 dto")
public class DepositFindByCreatorResponseDto {
@Schema(description = "잔액 테이블 Id", example = "1")
Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "사진 Key 업데이트 요청 dto")
@Schema(name = "[Picture][Anonymous] 사진 업로드 결과 Key 업데이트 요청 dto", description = "사진을 업로드 한 이후 저장한 경로(s3)가 어디인지 서버에 알림")
public class CommonPictureKeyUpdateRequestDto {

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

@Schema(description = "공통 사진 응답 dto")

@Getter
@NoArgsConstructor
@Schema(name = "[Picture][Anonymous] 공통 사진 응답 dto")
public class CommonPictureResponseDto {
@Schema(description = "해당 사진의 Entity id", example = "1")
Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public PictureGenerateRequest save(PictureGenerateRequest pictureGenerateRequest
@Override
public Optional<PictureGenerateRequest> findByUserAndStatusInOrderByCreatedByDesc(User user,
List<PictureGenerateRequestStatus> statusList) {
return pictureGenerateRequestRepository.findByUserIdAndRequestStatusIn(user, statusList);
return pictureGenerateRequestRepository.findByUserAndRequestStatusIn(user, statusList);
}

@Override
Expand Down
Loading

0 comments on commit 8baa7e7

Please sign in to comment.