diff --git a/src/main/java/com/nexters/keyme/auth/application/AuthService.java b/src/main/java/com/nexters/keyme/auth/application/AuthService.java deleted file mode 100644 index ea38f8e5..00000000 --- a/src/main/java/com/nexters/keyme/auth/application/AuthService.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.nexters.keyme.auth.application; - - -import com.nexters.keyme.auth.presentation.dto.request.LoginRequest; -import com.nexters.keyme.member.presentation.dto.response.MemberWithTokenResponse; - -public interface AuthService { - MemberWithTokenResponse getMemberWithToken(LoginRequest request); -} diff --git a/src/main/java/com/nexters/keyme/clienttest/application/ClientTestService.java b/src/main/java/com/nexters/keyme/clienttest/application/ClientTestService.java deleted file mode 100644 index 00ad25e6..00000000 --- a/src/main/java/com/nexters/keyme/clienttest/application/ClientTestService.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.nexters.keyme.clienttest.application; - -public interface ClientTestService { - void deleteIssuedOnboardingTest(Long memberId); - void deleteIssuedDailyTest(Long memberId); - void clearMember(Long memberId); -} diff --git a/src/main/java/com/nexters/keyme/clienttest/presentation/controller/ClientTestController.java b/src/main/java/com/nexters/keyme/clienttest/presentation/controller/ClientTestController.java deleted file mode 100644 index 84c87016..00000000 --- a/src/main/java/com/nexters/keyme/clienttest/presentation/controller/ClientTestController.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.nexters.keyme.clienttest.presentation.controller; - -import com.nexters.keyme.auth.domain.internaldto.UserInfo; -import com.nexters.keyme.clienttest.application.ClientTestService; -import com.nexters.keyme.common.annotation.RequestUser; -import com.nexters.keyme.common.dto.response.ApiResponse; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.v3.oas.annotations.security.SecurityRequirement; -import lombok.RequiredArgsConstructor; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import static com.nexters.keyme.common.config.SwaggerConfig.SWAGGER_AUTHORIZATION_SCHEME; - -@Api(tags = "클라이언트 테스트 API", description = "테스트를 위한 초기화 API") -@RestController -@RequestMapping("/clienttest") -@RequiredArgsConstructor -public class ClientTestController { - private final ClientTestService clientTestService; - - @GetMapping - public void hi() { } - - @DeleteMapping("/tests/onboarding") - @ApiOperation(value = "제출한 onboarding 삭제") - @SecurityRequirement(name = SWAGGER_AUTHORIZATION_SCHEME) - public ResponseEntity deleteOnboardingTest(@RequestUser UserInfo requestUser) { - // 발급받은 온보딩 - test 삭제(test result도 삭 - return null; - } - - @DeleteMapping("/tests/daily") - @ApiOperation(value = "오늘 발급받은 테스트 삭제") - @SecurityRequirement(name = SWAGGER_AUTHORIZATION_SCHEME) - public ResponseEntity deleteDailyTest(@RequestUser UserInfo requestUser) { - // 제출한 테스트도 삭제 - return null; - } - - @PostMapping("/questions") - @ApiOperation(value = "백엔드용") - public ResponseEntity addMockQuesetion() { - return null; - } - - @DeleteMapping("/member") - @ApiOperation(value = "멤버 정보 삭제") - @SecurityRequirement(name = SWAGGER_AUTHORIZATION_SCHEME) - public ResponseEntity deleteMember(@RequestUser UserInfo userInfo) { - clientTestService.clearMember(userInfo.getMemberId()); - return ResponseEntity.ok(new ApiResponse(200, "멤버가 삭제되었습니다.", null)); - } -} diff --git a/src/main/java/com/nexters/keyme/common/exceptions/AccessDeniedException.java b/src/main/java/com/nexters/keyme/common/exceptions/AccessDeniedException.java deleted file mode 100644 index fbc9b0e5..00000000 --- a/src/main/java/com/nexters/keyme/common/exceptions/AccessDeniedException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.nexters.keyme.common.exceptions; - -import com.nexters.keyme.common.exceptions.errorcode.ErrorCode; - -public class AccessDeniedException extends RuntimeException { - public AccessDeniedException() { - super(ErrorCode.ACCESS_DENIED.getMessage()); - } -} diff --git a/src/main/java/com/nexters/keyme/common/exceptions/AuthenticationFailedException.java b/src/main/java/com/nexters/keyme/common/exceptions/AuthenticationFailedException.java deleted file mode 100644 index 07c7a474..00000000 --- a/src/main/java/com/nexters/keyme/common/exceptions/AuthenticationFailedException.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.nexters.keyme.common.exceptions; - -import com.nexters.keyme.common.exceptions.errorcode.ErrorCode; - -public class AuthenticationFailedException extends RuntimeException { - public AuthenticationFailedException() { - super(ErrorCode.UNAUTHORIZED.getMessage()); - } - - public AuthenticationFailedException(ErrorCode errorCode) { - super(errorCode.getMessage()); - } -} diff --git a/src/main/java/com/nexters/keyme/common/exceptions/InvalidRequestException.java b/src/main/java/com/nexters/keyme/common/exceptions/InvalidRequestException.java deleted file mode 100644 index 6d2ed215..00000000 --- a/src/main/java/com/nexters/keyme/common/exceptions/InvalidRequestException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.nexters.keyme.common.exceptions; - -import com.nexters.keyme.common.exceptions.errorcode.ErrorCode; - -public class InvalidRequestException extends RuntimeException { - public InvalidRequestException() { - super(ErrorCode.INVALID_REQUEST.getMessage()); - } -} diff --git a/src/main/java/com/nexters/keyme/common/exceptions/ResourceAlreadyExistsException.java b/src/main/java/com/nexters/keyme/common/exceptions/ResourceAlreadyExistsException.java deleted file mode 100644 index 684dbab6..00000000 --- a/src/main/java/com/nexters/keyme/common/exceptions/ResourceAlreadyExistsException.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.nexters.keyme.common.exceptions; - -import com.nexters.keyme.common.exceptions.errorcode.ErrorCode; - -public class ResourceAlreadyExistsException extends RuntimeException { - - public ResourceAlreadyExistsException() { - super(ErrorCode.RESOURCE_ALREADY_EXIST.getMessage()); - } - public ResourceAlreadyExistsException(ErrorCode errorCode) { - super(errorCode.getMessage()); - } -} diff --git a/src/main/java/com/nexters/keyme/common/exceptions/ResourceNotFoundException.java b/src/main/java/com/nexters/keyme/common/exceptions/ResourceNotFoundException.java deleted file mode 100644 index 5257f9e6..00000000 --- a/src/main/java/com/nexters/keyme/common/exceptions/ResourceNotFoundException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.nexters.keyme.common.exceptions; - -import com.nexters.keyme.common.exceptions.errorcode.ErrorCode; - -public class ResourceNotFoundException extends RuntimeException { - public ResourceNotFoundException() { - super(ErrorCode.RESOURCE_NOT_FOUND.getMessage()); - } -} diff --git a/src/main/java/com/nexters/keyme/common/exceptions/errorcode/ErrorCode.java b/src/main/java/com/nexters/keyme/common/exceptions/errorcode/ErrorCode.java deleted file mode 100644 index 487d3979..00000000 --- a/src/main/java/com/nexters/keyme/common/exceptions/errorcode/ErrorCode.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.nexters.keyme.common.exceptions.errorcode; - -public enum ErrorCode { - INVALID_REQUEST(400, "올바르지 않은 요청입니다. 요청 형식 등을 확인하세요."), - - TOKEN_EXPIRED(401, "액세스 토큰이 만료되었습니다."), - ACCESS_TOKEN_NOT_EXIST(401, "액세스 토큰이 존재하지 않습니다."), - REFRESH_TOKEN_NOT_EXIST(401, "리프레시 토큰이 존재하지 않습니다."), - TOKEN_INVALID(401, "올바르지 않은 토큰입니다."), - UNAUTHORIZED(401, "인증되지 않은 사용자입니다."), - - ACCESS_DENIED(403, "접근 권한이 없습니다."), - - RESOURCE_NOT_FOUND(404, "대상을 찾을 수 없습니다."), - FILE_UPLOAD_FAILED(500, "파일 업로드에 실패하였습니다. 재시도해 주세요."), - - RESOURCE_ALREADY_EXIST(409, "리소스가 이미 존재합니다."), - - SERVER_ERROR(500, "서버 에러 발생! 문의주세요."); - - - private final int code; - private final String message; - - ErrorCode(int code, String message) { - this.code = code; - this.message = message; - } - - public int getCode() { - return this.code; - } - - public String getMessage() { - return this.message; - } -} diff --git a/src/main/java/com/nexters/keyme/common/exceptions/handler/GlobalExceptionHandler.java b/src/main/java/com/nexters/keyme/common/exceptions/handler/GlobalExceptionHandler.java deleted file mode 100644 index 859d21f3..00000000 --- a/src/main/java/com/nexters/keyme/common/exceptions/handler/GlobalExceptionHandler.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.nexters.keyme.common.exceptions.handler; - -import com.nexters.keyme.common.dto.response.ApiResponse; -import com.nexters.keyme.common.exceptions.*; -import com.nexters.keyme.common.exceptions.errorcode.ErrorCode; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.HttpRequestMethodNotSupportedException; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; - -import java.util.Arrays; - -@Slf4j -@ControllerAdvice -public class GlobalExceptionHandler { - @ExceptionHandler(AccessDeniedException.class) - public ResponseEntity handleAccessDeniedException(AccessDeniedException e) { - log.error("접근이 허용되지 않은 리소스에 접근"); - return ResponseEntity.status(HttpStatus.FORBIDDEN).body(new ApiResponse<>(ErrorCode.ACCESS_DENIED)); - } - - @ExceptionHandler(AuthenticationFailedException.class) - public ResponseEntity handleAuthorizationFailedException(AuthenticationFailedException e) { - log.error("인증 실패"); - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new ApiResponse(ErrorCode.UNAUTHORIZED.getCode(), e.getMessage(), null)); - } - - @ExceptionHandler(InvalidRequestException.class) - public ResponseEntity handleInvalidRequestException(InvalidRequestException e) { - log.error("잘못된 요청"); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ApiResponse<>(ErrorCode.INVALID_REQUEST)); - } - - @ExceptionHandler(ResourceNotFoundException.class) - public ResponseEntity handleResourceNotFoundException(ResourceNotFoundException e) { - log.error("해당 리소스가 존재하지 않음"); - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ApiResponse(ErrorCode.RESOURCE_NOT_FOUND)); - } - - @ExceptionHandler(ResourceAlreadyExistsException.class) - public ResponseEntity handleResourceAlreadyExistsException(ResourceAlreadyExistsException e) { - log.error("해당 리소스가 이미 존재함"); - return ResponseEntity.status(HttpStatus.CONFLICT).body(new ApiResponse(ErrorCode.RESOURCE_ALREADY_EXIST)); - } - - // 잘못된 형식의 요청 - @ExceptionHandler({ - IllegalArgumentException.class, - MethodArgumentTypeMismatchException.class, - HttpRequestMethodNotSupportedException.class - }) - public ResponseEntity handleNotFulfilledException(Exception e) { - log.error("요청 형식이 잘못되었음"); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ApiResponse(ErrorCode.INVALID_REQUEST)); - } - - @ExceptionHandler(Exception.class) - public ResponseEntity handleUnHandleException(Exception e) { - log.error("예상치 못한 에러발생! 😭 {} {} {}", e.getCause(), e.getMessage(), Arrays.toString(e.getStackTrace())); - return ResponseEntity.internalServerError().body(new ApiResponse(ErrorCode.SERVER_ERROR)); - } -} diff --git a/src/main/java/com/nexters/keyme/domain/auth/application/AuthService.java b/src/main/java/com/nexters/keyme/domain/auth/application/AuthService.java new file mode 100644 index 00000000..5a4549f3 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/auth/application/AuthService.java @@ -0,0 +1,9 @@ +package com.nexters.keyme.domain.auth.application; + + +import com.nexters.keyme.domain.auth.presentation.dto.request.LoginRequest; +import com.nexters.keyme.domain.member.presentation.dto.response.MemberWithTokenResponse; + +public interface AuthService { + MemberWithTokenResponse getMemberWithToken(LoginRequest request); +} diff --git a/src/main/java/com/nexters/keyme/auth/application/AuthServiceImpl.java b/src/main/java/com/nexters/keyme/domain/auth/application/AuthServiceImpl.java similarity index 65% rename from src/main/java/com/nexters/keyme/auth/application/AuthServiceImpl.java rename to src/main/java/com/nexters/keyme/domain/auth/application/AuthServiceImpl.java index e5ecff19..6e472a54 100644 --- a/src/main/java/com/nexters/keyme/auth/application/AuthServiceImpl.java +++ b/src/main/java/com/nexters/keyme/domain/auth/application/AuthServiceImpl.java @@ -1,20 +1,21 @@ -package com.nexters.keyme.auth.application; +package com.nexters.keyme.domain.auth.application; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.nexters.keyme.auth.domain.client.AppleClient; -import com.nexters.keyme.auth.domain.client.KakaoClient; -import com.nexters.keyme.auth.domain.internaldto.AppleJwtBodyInfo; -import com.nexters.keyme.auth.domain.internaldto.OAuthUserInfo; -import com.nexters.keyme.auth.presentation.dto.request.LoginRequest; -import com.nexters.keyme.auth.presentation.dto.response.AppleAuthKeysResponse; -import com.nexters.keyme.auth.presentation.dto.response.KakaoUserInfoResponse; -import com.nexters.keyme.auth.presentation.dto.response.TokenResponse; -import com.nexters.keyme.auth.domain.helper.ApplePublicKeyProvider; -import com.nexters.keyme.common.util.JwtTokenProvider; -import com.nexters.keyme.common.enums.OAuthType; -import com.nexters.keyme.member.application.MemberService; -import com.nexters.keyme.member.presentation.dto.response.MemberWithTokenResponse; +import com.nexters.keyme.domain.auth.domain.client.AppleClient; +import com.nexters.keyme.domain.auth.domain.client.KakaoClient; +import com.nexters.keyme.domain.auth.domain.exceptions.InvalidAppleTokenException; +import com.nexters.keyme.domain.auth.domain.internaldto.AppleJwtBodyInfo; +import com.nexters.keyme.domain.auth.domain.internaldto.OAuthUserInfo; +import com.nexters.keyme.domain.auth.presentation.dto.request.LoginRequest; +import com.nexters.keyme.domain.auth.presentation.dto.response.AppleAuthKeysResponse; +import com.nexters.keyme.domain.auth.presentation.dto.response.KakaoUserInfoResponse; +import com.nexters.keyme.domain.auth.presentation.dto.response.TokenResponse; +import com.nexters.keyme.domain.auth.domain.helper.ApplePublicKeyProvider; +import com.nexters.keyme.global.util.JwtTokenProvider; +import com.nexters.keyme.global.enums.OAuthType; +import com.nexters.keyme.domain.member.application.MemberService; +import com.nexters.keyme.domain.member.presentation.dto.response.MemberWithTokenResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -49,8 +50,6 @@ public MemberWithTokenResponse getMemberWithToken(LoginRequest request) { TokenResponse tokenObject = new TokenResponse(jwtToken); memberResponse.setToken(tokenObject); - // refresh 토큰정책 있으면 member에 저장 - return memberResponse; } @@ -60,10 +59,12 @@ private OAuthUserInfo getOAuthInfoOfApple(String identityToken) { PublicKey key = applePublicKeyProvider.getPublicKey(jwtHeaderString, authKeys); Boolean isVerified = jwtTokenProvider.verifyToken(identityToken, key); - if (!isVerified) { throw new RuntimeException(); } + if (!isVerified) { + throw new InvalidAppleTokenException(); + } + String jwtBodyString = jwtTokenProvider.extractJwtBodyString(identityToken); try { - String jwtBodyString = jwtTokenProvider.extractJwtBodyString(identityToken); AppleJwtBodyInfo jwtBody = objectMapper.readValue(jwtBodyString, AppleJwtBodyInfo.class); return OAuthUserInfo.builder() @@ -71,7 +72,7 @@ private OAuthUserInfo getOAuthInfoOfApple(String identityToken) { .oauthType(OAuthType.APPLE) .build(); } catch(JsonProcessingException e) { - throw new RuntimeException(); + throw new InvalidAppleTokenException(); } } diff --git a/src/main/java/com/nexters/keyme/auth/domain/client/AppleClient.java b/src/main/java/com/nexters/keyme/domain/auth/domain/client/AppleClient.java similarity index 66% rename from src/main/java/com/nexters/keyme/auth/domain/client/AppleClient.java rename to src/main/java/com/nexters/keyme/domain/auth/domain/client/AppleClient.java index e794ed81..0e3e65f7 100644 --- a/src/main/java/com/nexters/keyme/auth/domain/client/AppleClient.java +++ b/src/main/java/com/nexters/keyme/domain/auth/domain/client/AppleClient.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.auth.domain.client; +package com.nexters.keyme.domain.auth.domain.client; -import com.nexters.keyme.auth.presentation.dto.response.AppleAuthKeysResponse; +import com.nexters.keyme.domain.auth.presentation.dto.response.AppleAuthKeysResponse; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; diff --git a/src/main/java/com/nexters/keyme/auth/domain/client/KakaoClient.java b/src/main/java/com/nexters/keyme/domain/auth/domain/client/KakaoClient.java similarity index 74% rename from src/main/java/com/nexters/keyme/auth/domain/client/KakaoClient.java rename to src/main/java/com/nexters/keyme/domain/auth/domain/client/KakaoClient.java index 42c4bf47..c1e63a83 100644 --- a/src/main/java/com/nexters/keyme/auth/domain/client/KakaoClient.java +++ b/src/main/java/com/nexters/keyme/domain/auth/domain/client/KakaoClient.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.auth.domain.client; +package com.nexters.keyme.domain.auth.domain.client; -import com.nexters.keyme.auth.presentation.dto.response.KakaoUserInfoResponse; +import com.nexters.keyme.domain.auth.presentation.dto.response.KakaoUserInfoResponse; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader; diff --git a/src/main/java/com/nexters/keyme/domain/auth/domain/exceptions/InvalidAppleKeyException.java b/src/main/java/com/nexters/keyme/domain/auth/domain/exceptions/InvalidAppleKeyException.java new file mode 100644 index 00000000..0c49e666 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/auth/domain/exceptions/InvalidAppleKeyException.java @@ -0,0 +1,10 @@ +package com.nexters.keyme.domain.auth.domain.exceptions; + +import com.nexters.keyme.domain.auth.domain.exceptions.code.AuthErrorCode; +import com.nexters.keyme.global.exceptions.KeymeBadRequestException; + +public class InvalidAppleKeyException extends KeymeBadRequestException { + public InvalidAppleKeyException() { + super(AuthErrorCode.INVALID_APPLE_KEY.getMessage(), AuthErrorCode.INVALID_APPLE_KEY.getCode()); + } +} diff --git a/src/main/java/com/nexters/keyme/domain/auth/domain/exceptions/InvalidAppleTokenException.java b/src/main/java/com/nexters/keyme/domain/auth/domain/exceptions/InvalidAppleTokenException.java new file mode 100644 index 00000000..66db3fdb --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/auth/domain/exceptions/InvalidAppleTokenException.java @@ -0,0 +1,11 @@ +package com.nexters.keyme.domain.auth.domain.exceptions; + +import com.nexters.keyme.domain.auth.domain.exceptions.code.AuthErrorCode; +import com.nexters.keyme.global.exceptions.KeymeBadRequestException; +import org.springframework.http.HttpStatus; + +public class InvalidAppleTokenException extends KeymeBadRequestException { + public InvalidAppleTokenException() { + super(AuthErrorCode.INVALID_APPLE_TOKEN.getMessage(), AuthErrorCode.INVALID_APPLE_TOKEN.getCode()); + } +} diff --git a/src/main/java/com/nexters/keyme/domain/auth/domain/exceptions/code/AuthErrorCode.java b/src/main/java/com/nexters/keyme/domain/auth/domain/exceptions/code/AuthErrorCode.java new file mode 100644 index 00000000..9a494f0c --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/auth/domain/exceptions/code/AuthErrorCode.java @@ -0,0 +1,15 @@ +package com.nexters.keyme.domain.auth.domain.exceptions.code; + + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum AuthErrorCode { + INVALID_APPLE_TOKEN(400, "잘못된 IdentityToken 입니다."), + INVALID_APPLE_KEY(400, "IdentityToken 검증에 실패하였습니다."); + + private final int code; + private final String message; +} diff --git a/src/main/java/com/nexters/keyme/auth/domain/helper/ApplePublicKeyProvider.java b/src/main/java/com/nexters/keyme/domain/auth/domain/helper/ApplePublicKeyProvider.java similarity index 64% rename from src/main/java/com/nexters/keyme/auth/domain/helper/ApplePublicKeyProvider.java rename to src/main/java/com/nexters/keyme/domain/auth/domain/helper/ApplePublicKeyProvider.java index 2f23e4bf..16e4f67a 100644 --- a/src/main/java/com/nexters/keyme/auth/domain/helper/ApplePublicKeyProvider.java +++ b/src/main/java/com/nexters/keyme/domain/auth/domain/helper/ApplePublicKeyProvider.java @@ -1,10 +1,11 @@ -package com.nexters.keyme.auth.domain.helper; +package com.nexters.keyme.domain.auth.domain.helper; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.nexters.keyme.auth.domain.internaldto.JwtHeaderInfo; -import com.nexters.keyme.auth.presentation.dto.response.AppleAuthKeysResponse; +import com.nexters.keyme.domain.auth.domain.exceptions.InvalidAppleKeyException; +import com.nexters.keyme.domain.auth.domain.internaldto.JwtHeaderInfo; +import com.nexters.keyme.domain.auth.presentation.dto.response.AppleAuthKeysResponse; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; import org.springframework.util.Base64Utils; @@ -19,8 +20,7 @@ @Component @RequiredArgsConstructor public class ApplePublicKeyProvider { - private final String ALG_HEADER_KEY = "alg"; - private final String KID_HEADER_KEY = "kid"; + private final int POSITIVE_SIGNUM = 1; private final ObjectMapper objectMapper; @@ -34,30 +34,18 @@ public PublicKey getPublicKey(String jwtHeader, AppleAuthKeysResponse authKeys) .findAny() .orElseThrow(); return createPublicKey(publicKey); - } catch (JsonMappingException e) { - System.out.println("jwt 역직렬화 실패"); - } catch (JsonProcessingException e) { - System.out.println("JSON 문제"); - } catch (Exception e) { - System.out.println("일치하는 키 없음"); + } catch (JsonProcessingException | NoSuchAlgorithmException | InvalidKeySpecException e) { + throw new InvalidAppleKeyException(); } - - return null; } - private PublicKey createPublicKey(AppleAuthKeysResponse.Key publicKey) { + private PublicKey createPublicKey(AppleAuthKeysResponse.Key publicKey) throws NoSuchAlgorithmException, InvalidKeySpecException { byte[] n = Base64Utils.decodeFromUrlSafeString(publicKey.getN()); byte[] e = Base64Utils.decodeFromUrlSafeString(publicKey.getE()); RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(new BigInteger(POSITIVE_SIGNUM, n), new BigInteger(POSITIVE_SIGNUM, e)); - try { - KeyFactory keyFactory = KeyFactory.getInstance(publicKey.getKty()); - return keyFactory.generatePublic(publicKeySpec); - } catch (NoSuchAlgorithmException | InvalidKeySpecException exception) { - System.out.println("PublicKey 생성불가"); - } - - return null; + KeyFactory keyFactory = KeyFactory.getInstance(publicKey.getKty()); + return keyFactory.generatePublic(publicKeySpec); } } diff --git a/src/main/java/com/nexters/keyme/auth/domain/internaldto/AppleJwtBodyInfo.java b/src/main/java/com/nexters/keyme/domain/auth/domain/internaldto/AppleJwtBodyInfo.java similarity index 65% rename from src/main/java/com/nexters/keyme/auth/domain/internaldto/AppleJwtBodyInfo.java rename to src/main/java/com/nexters/keyme/domain/auth/domain/internaldto/AppleJwtBodyInfo.java index 92d1ff95..9ef013a0 100644 --- a/src/main/java/com/nexters/keyme/auth/domain/internaldto/AppleJwtBodyInfo.java +++ b/src/main/java/com/nexters/keyme/domain/auth/domain/internaldto/AppleJwtBodyInfo.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.auth.domain.internaldto; +package com.nexters.keyme.domain.auth.domain.internaldto; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/auth/domain/internaldto/JwtHeaderInfo.java b/src/main/java/com/nexters/keyme/domain/auth/domain/internaldto/JwtHeaderInfo.java similarity index 64% rename from src/main/java/com/nexters/keyme/auth/domain/internaldto/JwtHeaderInfo.java rename to src/main/java/com/nexters/keyme/domain/auth/domain/internaldto/JwtHeaderInfo.java index daabee8c..353b43c4 100644 --- a/src/main/java/com/nexters/keyme/auth/domain/internaldto/JwtHeaderInfo.java +++ b/src/main/java/com/nexters/keyme/domain/auth/domain/internaldto/JwtHeaderInfo.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.auth.domain.internaldto; +package com.nexters.keyme.domain.auth.domain.internaldto; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/auth/domain/internaldto/OAuthUserInfo.java b/src/main/java/com/nexters/keyme/domain/auth/domain/internaldto/OAuthUserInfo.java similarity index 62% rename from src/main/java/com/nexters/keyme/auth/domain/internaldto/OAuthUserInfo.java rename to src/main/java/com/nexters/keyme/domain/auth/domain/internaldto/OAuthUserInfo.java index fc286e1c..64c0b22c 100644 --- a/src/main/java/com/nexters/keyme/auth/domain/internaldto/OAuthUserInfo.java +++ b/src/main/java/com/nexters/keyme/domain/auth/domain/internaldto/OAuthUserInfo.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.auth.domain.internaldto; +package com.nexters.keyme.domain.auth.domain.internaldto; -import com.nexters.keyme.common.enums.OAuthType; +import com.nexters.keyme.global.enums.OAuthType; import lombok.Builder; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/nexters/keyme/auth/presentation/controller/AuthController.java b/src/main/java/com/nexters/keyme/domain/auth/presentation/controller/AuthController.java similarity index 69% rename from src/main/java/com/nexters/keyme/auth/presentation/controller/AuthController.java rename to src/main/java/com/nexters/keyme/domain/auth/presentation/controller/AuthController.java index d0844671..74c21b95 100644 --- a/src/main/java/com/nexters/keyme/auth/presentation/controller/AuthController.java +++ b/src/main/java/com/nexters/keyme/domain/auth/presentation/controller/AuthController.java @@ -1,12 +1,11 @@ -package com.nexters.keyme.auth.presentation.controller; +package com.nexters.keyme.domain.auth.presentation.controller; -import com.nexters.keyme.auth.presentation.dto.request.LoginRequest; -import com.nexters.keyme.auth.application.AuthService; -import com.nexters.keyme.common.annotation.ApiSecurityIgnore; -import com.nexters.keyme.common.dto.response.ApiResponse; -import com.nexters.keyme.member.presentation.dto.response.MemberWithTokenResponse; -import com.nexters.keyme.test.presentation.dto.response.TestDetailResponse; +import com.nexters.keyme.domain.auth.presentation.dto.request.LoginRequest; +import com.nexters.keyme.domain.auth.application.AuthService; +import com.nexters.keyme.global.annotation.ApiSecurityIgnore; +import com.nexters.keyme.global.dto.response.ApiResponse; +import com.nexters.keyme.domain.member.presentation.dto.response.MemberWithTokenResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/auth/presentation/dto/request/LoginRequest.java b/src/main/java/com/nexters/keyme/domain/auth/presentation/dto/request/LoginRequest.java similarity index 83% rename from src/main/java/com/nexters/keyme/auth/presentation/dto/request/LoginRequest.java rename to src/main/java/com/nexters/keyme/domain/auth/presentation/dto/request/LoginRequest.java index eb10cf2f..f40e68cc 100644 --- a/src/main/java/com/nexters/keyme/auth/presentation/dto/request/LoginRequest.java +++ b/src/main/java/com/nexters/keyme/domain/auth/presentation/dto/request/LoginRequest.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.auth.presentation.dto.request; +package com.nexters.keyme.domain.auth.presentation.dto.request; -import com.nexters.keyme.common.enums.OAuthType; +import com.nexters.keyme.global.enums.OAuthType; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/auth/presentation/dto/response/AppleAuthKeysResponse.java b/src/main/java/com/nexters/keyme/domain/auth/presentation/dto/response/AppleAuthKeysResponse.java similarity index 82% rename from src/main/java/com/nexters/keyme/auth/presentation/dto/response/AppleAuthKeysResponse.java rename to src/main/java/com/nexters/keyme/domain/auth/presentation/dto/response/AppleAuthKeysResponse.java index 0c21d0b4..e5e90fbd 100644 --- a/src/main/java/com/nexters/keyme/auth/presentation/dto/response/AppleAuthKeysResponse.java +++ b/src/main/java/com/nexters/keyme/domain/auth/presentation/dto/response/AppleAuthKeysResponse.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.auth.presentation.dto.response; +package com.nexters.keyme.domain.auth.presentation.dto.response; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/auth/presentation/dto/response/KakaoUserInfoResponse.java b/src/main/java/com/nexters/keyme/domain/auth/presentation/dto/response/KakaoUserInfoResponse.java similarity index 94% rename from src/main/java/com/nexters/keyme/auth/presentation/dto/response/KakaoUserInfoResponse.java rename to src/main/java/com/nexters/keyme/domain/auth/presentation/dto/response/KakaoUserInfoResponse.java index bb39d741..1f43fcb3 100644 --- a/src/main/java/com/nexters/keyme/auth/presentation/dto/response/KakaoUserInfoResponse.java +++ b/src/main/java/com/nexters/keyme/domain/auth/presentation/dto/response/KakaoUserInfoResponse.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.auth.presentation.dto.response; +package com.nexters.keyme.domain.auth.presentation.dto.response; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/com/nexters/keyme/auth/presentation/dto/response/TokenResponse.java b/src/main/java/com/nexters/keyme/domain/auth/presentation/dto/response/TokenResponse.java similarity index 78% rename from src/main/java/com/nexters/keyme/auth/presentation/dto/response/TokenResponse.java rename to src/main/java/com/nexters/keyme/domain/auth/presentation/dto/response/TokenResponse.java index 3fb3a21b..4d684c30 100644 --- a/src/main/java/com/nexters/keyme/auth/presentation/dto/response/TokenResponse.java +++ b/src/main/java/com/nexters/keyme/domain/auth/presentation/dto/response/TokenResponse.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.auth.presentation.dto.response; +package com.nexters.keyme.domain.auth.presentation.dto.response; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/domain/clienttest/application/ClientTestService.java b/src/main/java/com/nexters/keyme/domain/clienttest/application/ClientTestService.java new file mode 100644 index 00000000..bc404edb --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/clienttest/application/ClientTestService.java @@ -0,0 +1,5 @@ +package com.nexters.keyme.domain.clienttest.application; + +public interface ClientTestService { + void clearMember(Long memberId); +} diff --git a/src/main/java/com/nexters/keyme/clienttest/application/ClientTestServiceImpl.java b/src/main/java/com/nexters/keyme/domain/clienttest/application/ClientTestServiceImpl.java similarity index 50% rename from src/main/java/com/nexters/keyme/clienttest/application/ClientTestServiceImpl.java rename to src/main/java/com/nexters/keyme/domain/clienttest/application/ClientTestServiceImpl.java index c68eb8c2..11a5f107 100644 --- a/src/main/java/com/nexters/keyme/clienttest/application/ClientTestServiceImpl.java +++ b/src/main/java/com/nexters/keyme/domain/clienttest/application/ClientTestServiceImpl.java @@ -1,8 +1,8 @@ -package com.nexters.keyme.clienttest.application; +package com.nexters.keyme.domain.clienttest.application; -import com.nexters.keyme.common.exceptions.ResourceNotFoundException; -import com.nexters.keyme.member.domain.model.MemberEntity; -import com.nexters.keyme.member.domain.repository.MemberRepository; +import com.nexters.keyme.domain.member.domain.exceptions.NotFoundMemberException; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.member.domain.repository.MemberRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -11,22 +11,13 @@ @RequiredArgsConstructor public class ClientTestServiceImpl implements ClientTestService { - @Override - public void deleteIssuedOnboardingTest(Long memberId) { - // 삭제 - } - - @Override - public void deleteIssuedDailyTest(Long memberId) { - // 삭제 - } private final MemberRepository memberRepository; @Transactional @Override public void clearMember(Long memberId) { MemberEntity member = memberRepository.findById(memberId) - .orElseThrow(ResourceNotFoundException::new); + .orElseThrow(NotFoundMemberException::new); memberRepository.delete(member); } diff --git a/src/main/java/com/nexters/keyme/domain/clienttest/presentation/controller/ClientTestController.java b/src/main/java/com/nexters/keyme/domain/clienttest/presentation/controller/ClientTestController.java new file mode 100644 index 00000000..7b0f3513 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/clienttest/presentation/controller/ClientTestController.java @@ -0,0 +1,30 @@ +package com.nexters.keyme.domain.clienttest.presentation.controller; + +import com.nexters.keyme.global.dto.internal.UserInfo; +import com.nexters.keyme.domain.clienttest.application.ClientTestService; +import com.nexters.keyme.global.annotation.RequestUser; +import com.nexters.keyme.global.dto.response.ApiResponse; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import static com.nexters.keyme.global.config.SwaggerConfig.SWAGGER_AUTHORIZATION_SCHEME; + +@Api(tags = "클라이언트 테스트 API", description = "테스트를 위한 초기화 API") +@RestController +@RequestMapping("/clienttest") +@RequiredArgsConstructor +public class ClientTestController { + private final ClientTestService clientTestService; + + @DeleteMapping("/member") + @ApiOperation(value = "멤버 정보 삭제") + @SecurityRequirement(name = SWAGGER_AUTHORIZATION_SCHEME) + public ResponseEntity deleteMember(@RequestUser UserInfo userInfo) { + clientTestService.clearMember(userInfo.getMemberId()); + return ResponseEntity.ok(new ApiResponse(200, "멤버가 삭제되었습니다.", null)); + } +} diff --git a/src/main/java/com/nexters/keyme/friend/presentation/controller/FriendController.java b/src/main/java/com/nexters/keyme/domain/friend/presentation/controller/FriendController.java similarity index 65% rename from src/main/java/com/nexters/keyme/friend/presentation/controller/FriendController.java rename to src/main/java/com/nexters/keyme/domain/friend/presentation/controller/FriendController.java index 9e1bb296..24337ad4 100644 --- a/src/main/java/com/nexters/keyme/friend/presentation/controller/FriendController.java +++ b/src/main/java/com/nexters/keyme/domain/friend/presentation/controller/FriendController.java @@ -1,14 +1,14 @@ -package com.nexters.keyme.friend.presentation.controller; - -import com.nexters.keyme.auth.domain.internaldto.UserInfo; -import com.nexters.keyme.common.annotation.RequestUser; -import com.nexters.keyme.common.dto.response.ApiResponse; -import com.nexters.keyme.friend.presentation.dto.request.FriendAcceptRequest; -import com.nexters.keyme.friend.presentation.dto.request.FriendAddRequest; -import com.nexters.keyme.friend.presentation.dto.response.FriendResponse; +package com.nexters.keyme.domain.friend.presentation.controller; + +import com.nexters.keyme.domain.friend.presentation.dto.request.FriendAcceptRequest; +import com.nexters.keyme.domain.friend.presentation.dto.request.FriendAddRequest; +import com.nexters.keyme.domain.friend.presentation.dto.response.FriendResponse; +import com.nexters.keyme.global.annotation.RequestUser; +import com.nexters.keyme.global.dto.internal.UserInfo; +import com.nexters.keyme.global.dto.response.ApiResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import io.swagger.v3.oas.annotations.security.SecurityRequirement; + import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -18,8 +18,6 @@ import java.util.List; -import static com.nexters.keyme.common.config.SwaggerConfig.SWAGGER_AUTHORIZATION_SCHEME; - @RestController @RequestMapping("/friends") @RequiredArgsConstructor @@ -28,7 +26,6 @@ public class FriendController { @GetMapping @ApiOperation(value = "친구 리스트 보기") - @SecurityRequirement(name = SWAGGER_AUTHORIZATION_SCHEME) public ResponseEntity>> getFriendsList(@RequestUser UserInfo userInfo) { FriendResponse response = FriendResponse.builder() @@ -42,14 +39,12 @@ public ResponseEntity>> getFriendsList(@Request @PostMapping("/request") @ApiOperation(value = "친구 추가 요청 보내기") - @SecurityRequirement(name = SWAGGER_AUTHORIZATION_SCHEME) public ResponseEntity addFriend(FriendAddRequest request) { return ResponseEntity.ok(new ApiResponse<>(null)); } @PostMapping("/response") @ApiOperation(value = "친구 추가 요청 응답하기") - @SecurityRequirement(name = SWAGGER_AUTHORIZATION_SCHEME) public ResponseEntity acceptFriend(FriendAcceptRequest request) { return ResponseEntity.ok(new ApiResponse<>(null)); } diff --git a/src/main/java/com/nexters/keyme/friend/presentation/dto/request/FriendAcceptRequest.java b/src/main/java/com/nexters/keyme/domain/friend/presentation/dto/request/FriendAcceptRequest.java similarity index 86% rename from src/main/java/com/nexters/keyme/friend/presentation/dto/request/FriendAcceptRequest.java rename to src/main/java/com/nexters/keyme/domain/friend/presentation/dto/request/FriendAcceptRequest.java index bdaae4fc..faa39452 100644 --- a/src/main/java/com/nexters/keyme/friend/presentation/dto/request/FriendAcceptRequest.java +++ b/src/main/java/com/nexters/keyme/domain/friend/presentation/dto/request/FriendAcceptRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.friend.presentation.dto.request; +package com.nexters.keyme.domain.friend.presentation.dto.request; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; @@ -13,4 +13,4 @@ public class FriendAcceptRequest { private Long acceptFriendId; @ApiModelProperty(value="수락 여부", example = "true") private boolean isAccept; -} +} \ No newline at end of file diff --git a/src/main/java/com/nexters/keyme/friend/presentation/dto/request/FriendAddRequest.java b/src/main/java/com/nexters/keyme/domain/friend/presentation/dto/request/FriendAddRequest.java similarity index 82% rename from src/main/java/com/nexters/keyme/friend/presentation/dto/request/FriendAddRequest.java rename to src/main/java/com/nexters/keyme/domain/friend/presentation/dto/request/FriendAddRequest.java index 574b41ca..f3096d25 100644 --- a/src/main/java/com/nexters/keyme/friend/presentation/dto/request/FriendAddRequest.java +++ b/src/main/java/com/nexters/keyme/domain/friend/presentation/dto/request/FriendAddRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.friend.presentation.dto.request; +package com.nexters.keyme.domain.friend.presentation.dto.request; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; @@ -11,4 +11,4 @@ public class FriendAddRequest { @ApiModelProperty(value="문제 ID", example = "22") private String friendCode; -} +} \ No newline at end of file diff --git a/src/main/java/com/nexters/keyme/friend/presentation/dto/response/FriendResponse.java b/src/main/java/com/nexters/keyme/domain/friend/presentation/dto/response/FriendResponse.java similarity index 86% rename from src/main/java/com/nexters/keyme/friend/presentation/dto/response/FriendResponse.java rename to src/main/java/com/nexters/keyme/domain/friend/presentation/dto/response/FriendResponse.java index 1605777a..42d3bc1b 100644 --- a/src/main/java/com/nexters/keyme/friend/presentation/dto/response/FriendResponse.java +++ b/src/main/java/com/nexters/keyme/domain/friend/presentation/dto/response/FriendResponse.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.friend.presentation.dto.response; +package com.nexters.keyme.domain.friend.presentation.dto.response; import io.swagger.annotations.ApiModelProperty; import lombok.*; @@ -13,4 +13,4 @@ public class FriendResponse { private final String nickname; @ApiModelProperty(value="섬네일 URL", example = "thumbnail url") private final String thumbnailUrl; -} +} \ No newline at end of file diff --git a/src/main/java/com/nexters/keyme/domain/member/application/MemberService.java b/src/main/java/com/nexters/keyme/domain/member/application/MemberService.java new file mode 100644 index 00000000..2afdcb52 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/member/application/MemberService.java @@ -0,0 +1,31 @@ +package com.nexters.keyme.domain.member.application; + +import com.nexters.keyme.domain.auth.domain.internaldto.OAuthUserInfo; +import com.nexters.keyme.global.dto.internal.UserInfo; +import com.nexters.keyme.domain.member.presentation.dto.request.AddTokenRequest; +import com.nexters.keyme.domain.member.presentation.dto.request.DeleteTokenRequest; +import com.nexters.keyme.domain.member.presentation.dto.request.MemberModificationRequest; +import com.nexters.keyme.domain.member.presentation.dto.request.NicknameVerificationRequest; +import com.nexters.keyme.domain.member.presentation.dto.response.ImageResponse; +import com.nexters.keyme.domain.member.presentation.dto.response.NicknameVerificationResponse; +import com.nexters.keyme.domain.member.presentation.dto.response.MemberResponse; +import com.nexters.keyme.domain.member.presentation.dto.response.MemberWithTokenResponse; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +public interface MemberService { + MemberWithTokenResponse getOrCreateMember(OAuthUserInfo oauthUserInfo); + + MemberResponse getMemberInfo(Long memberId); + + NicknameVerificationResponse verifyNickname(NicknameVerificationRequest request); + + MemberResponse modifyMemberInfo(MemberModificationRequest request, UserInfo userInfo); + + ImageResponse uploadImage(MultipartFile image); + + @Transactional + void registerDeviceToken(long userId, AddTokenRequest request); + + void deleteDeviceToken(long memberId, DeleteTokenRequest request); +} diff --git a/src/main/java/com/nexters/keyme/member/application/MemberServiceImpl.java b/src/main/java/com/nexters/keyme/domain/member/application/MemberServiceImpl.java similarity index 66% rename from src/main/java/com/nexters/keyme/member/application/MemberServiceImpl.java rename to src/main/java/com/nexters/keyme/domain/member/application/MemberServiceImpl.java index 309ee044..97b36a77 100644 --- a/src/main/java/com/nexters/keyme/member/application/MemberServiceImpl.java +++ b/src/main/java/com/nexters/keyme/domain/member/application/MemberServiceImpl.java @@ -1,25 +1,25 @@ -package com.nexters.keyme.member.application; - -import com.nexters.keyme.auth.domain.internaldto.OAuthUserInfo; -import com.nexters.keyme.auth.domain.internaldto.UserInfo; -import com.nexters.keyme.common.exceptions.ResourceNotFoundException; -import com.nexters.keyme.member.domain.internaldto.ImageInfo; -import com.nexters.keyme.member.domain.internaldto.MemberModificationInfo; -import com.nexters.keyme.member.domain.internaldto.ValidationInfo; -import com.nexters.keyme.member.domain.model.*; -import com.nexters.keyme.member.domain.repository.MemberDeviceRepository; -import com.nexters.keyme.member.domain.repository.MemberOAuthRepository; -import com.nexters.keyme.member.domain.repository.MemberRepository; -import com.nexters.keyme.member.domain.service.ImageUploader; -import com.nexters.keyme.member.domain.service.NicknameValidator; -import com.nexters.keyme.member.presentation.dto.request.AddTokenRequest; -import com.nexters.keyme.member.presentation.dto.request.DeleteTokenRequest; -import com.nexters.keyme.member.presentation.dto.request.MemberModificationRequest; -import com.nexters.keyme.member.presentation.dto.request.NicknameVerificationRequest; -import com.nexters.keyme.member.presentation.dto.response.ImageResponse; -import com.nexters.keyme.member.presentation.dto.response.MemberResponse; -import com.nexters.keyme.member.presentation.dto.response.MemberWithTokenResponse; -import com.nexters.keyme.member.presentation.dto.response.NicknameVerificationResponse; +package com.nexters.keyme.domain.member.application; + +import com.nexters.keyme.domain.auth.domain.internaldto.OAuthUserInfo; +import com.nexters.keyme.domain.member.domain.exceptions.NotFoundMemberException; +import com.nexters.keyme.global.dto.internal.UserInfo; +import com.nexters.keyme.domain.member.domain.model.*; +import com.nexters.keyme.domain.member.domain.internaldto.ImageInfo; +import com.nexters.keyme.domain.member.domain.internaldto.MemberModificationInfo; +import com.nexters.keyme.domain.member.domain.internaldto.ValidationInfo; +import com.nexters.keyme.domain.member.domain.repository.MemberDeviceRepository; +import com.nexters.keyme.domain.member.domain.repository.MemberOAuthRepository; +import com.nexters.keyme.domain.member.domain.repository.MemberRepository; +import com.nexters.keyme.domain.member.domain.service.ImageUploader; +import com.nexters.keyme.domain.member.domain.service.NicknameValidator; +import com.nexters.keyme.domain.member.presentation.dto.request.AddTokenRequest; +import com.nexters.keyme.domain.member.presentation.dto.request.DeleteTokenRequest; +import com.nexters.keyme.domain.member.presentation.dto.request.MemberModificationRequest; +import com.nexters.keyme.domain.member.presentation.dto.request.NicknameVerificationRequest; +import com.nexters.keyme.domain.member.presentation.dto.response.ImageResponse; +import com.nexters.keyme.domain.member.presentation.dto.response.MemberResponse; +import com.nexters.keyme.domain.member.presentation.dto.response.MemberWithTokenResponse; +import com.nexters.keyme.domain.member.presentation.dto.response.NicknameVerificationResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -29,7 +29,7 @@ import java.util.List; import java.util.Optional; -import static com.nexters.keyme.common.config.ConstantConfig.DEFAULT_IMAGE_URL; +import static com.nexters.keyme.global.constant.ConstantString.DEFAULT_IMAGE_URL; @Service @RequiredArgsConstructor @@ -73,7 +73,7 @@ public MemberWithTokenResponse getOrCreateMember(OAuthUserInfo oauthUserInfo) { @Transactional public MemberResponse getMemberInfo(Long memberId) { MemberEntity member = memberRepository.findById(memberId) - .orElseThrow(ResourceNotFoundException::new); + .orElseThrow(NotFoundMemberException::new); return new MemberResponse(member); } @@ -98,7 +98,7 @@ public MemberResponse modifyMemberInfo(MemberModificationRequest request, UserIn nicknameValidator.validateNickname(modificationInfo.getNickname()); MemberEntity member = memberRepository.findById(userInfo.getMemberId()) - .orElseThrow(ResourceNotFoundException::new); + .orElseThrow(NotFoundMemberException::new); member.modifyMemberInfo(modificationInfo); return new MemberResponse(member); @@ -115,7 +115,7 @@ public ImageResponse uploadImage(MultipartFile image) { @Override public void registerDeviceToken(long userId, AddTokenRequest request) { MemberEntity member = memberRepository.findById(userId) - .orElseThrow(ResourceNotFoundException::new); + .orElseThrow(NotFoundMemberException::new); if (isAlreadyExists(member.getMemberDevice(), request.getToken())) { log.info("Registering FCM token --- token already exists: {}", request.getToken()); @@ -143,9 +143,9 @@ private boolean isAlreadyExists(List memberDevice, String token) { @Transactional @Override public void deleteDeviceToken(long memberId, DeleteTokenRequest request) { - MemberDevice device = memberDeviceRepository.findByMemberIdAndToken(memberId, request.getToken()) - .orElseThrow(ResourceNotFoundException::new); - - memberDeviceRepository.delete(device); + Optional device = memberDeviceRepository.findByMemberIdAndToken(memberId, request.getToken()); + if (device.isPresent()) { + memberDeviceRepository.delete(device.get()); + } } } diff --git a/src/main/java/com/nexters/keyme/domain/member/domain/exceptions/NicknameDuplicateException.java b/src/main/java/com/nexters/keyme/domain/member/domain/exceptions/NicknameDuplicateException.java new file mode 100644 index 00000000..6424df73 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/member/domain/exceptions/NicknameDuplicateException.java @@ -0,0 +1,10 @@ +package com.nexters.keyme.domain.member.domain.exceptions; + +import com.nexters.keyme.domain.member.domain.exceptions.code.MemberErrorCode; +import com.nexters.keyme.global.exceptions.KeymeSuccessInfoException; + +public class NicknameDuplicateException extends KeymeSuccessInfoException { + public NicknameDuplicateException() { + super(MemberErrorCode.DUPLICATED_NICKNAME.getMessage(), MemberErrorCode.DUPLICATED_NICKNAME.getCode()); + } +} diff --git a/src/main/java/com/nexters/keyme/domain/member/domain/exceptions/NicknameTooLongException.java b/src/main/java/com/nexters/keyme/domain/member/domain/exceptions/NicknameTooLongException.java new file mode 100644 index 00000000..8881cff3 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/member/domain/exceptions/NicknameTooLongException.java @@ -0,0 +1,10 @@ +package com.nexters.keyme.domain.member.domain.exceptions; + +import com.nexters.keyme.domain.member.domain.exceptions.code.MemberErrorCode; +import com.nexters.keyme.global.exceptions.KeymeSuccessInfoException; + +public class NicknameTooLongException extends KeymeSuccessInfoException { + public NicknameTooLongException() { + super(MemberErrorCode.NICKNAME_TOO_LONG.getMessage(), MemberErrorCode.NICKNAME_TOO_LONG.getCode()); + } +} diff --git a/src/main/java/com/nexters/keyme/domain/member/domain/exceptions/NotFoundMemberException.java b/src/main/java/com/nexters/keyme/domain/member/domain/exceptions/NotFoundMemberException.java new file mode 100644 index 00000000..2b21f530 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/member/domain/exceptions/NotFoundMemberException.java @@ -0,0 +1,10 @@ +package com.nexters.keyme.domain.member.domain.exceptions; + +import com.nexters.keyme.domain.member.domain.exceptions.code.MemberErrorCode; +import com.nexters.keyme.global.exceptions.KeymeNotFoundException; + +public class NotFoundMemberException extends KeymeNotFoundException { + public NotFoundMemberException() { + super(MemberErrorCode.NOT_FOUND_MEMBER.getMessage(), MemberErrorCode.NOT_FOUND_MEMBER.getCode()); + } +} \ No newline at end of file diff --git a/src/main/java/com/nexters/keyme/domain/member/domain/exceptions/code/MemberErrorCode.java b/src/main/java/com/nexters/keyme/domain/member/domain/exceptions/code/MemberErrorCode.java new file mode 100644 index 00000000..1bec0f09 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/member/domain/exceptions/code/MemberErrorCode.java @@ -0,0 +1,15 @@ +package com.nexters.keyme.domain.member.domain.exceptions.code; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum MemberErrorCode { + NOT_FOUND_MEMBER(404, "Member를 찾을 수 없습니다."), + DUPLICATED_NICKNAME(200,"이미 사용 중인 닉네임입니다."), + NICKNAME_TOO_LONG(200,"닉네임은 7자 이하여야 합니다."); + + private final int code; + private final String message; +} diff --git a/src/main/java/com/nexters/keyme/member/domain/internaldto/ImageInfo.java b/src/main/java/com/nexters/keyme/domain/member/domain/internaldto/ImageInfo.java similarity index 76% rename from src/main/java/com/nexters/keyme/member/domain/internaldto/ImageInfo.java rename to src/main/java/com/nexters/keyme/domain/member/domain/internaldto/ImageInfo.java index 28b73be2..995f2d0e 100644 --- a/src/main/java/com/nexters/keyme/member/domain/internaldto/ImageInfo.java +++ b/src/main/java/com/nexters/keyme/domain/member/domain/internaldto/ImageInfo.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.member.domain.internaldto; +package com.nexters.keyme.domain.member.domain.internaldto; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/member/domain/internaldto/MemberModificationInfo.java b/src/main/java/com/nexters/keyme/domain/member/domain/internaldto/MemberModificationInfo.java similarity index 81% rename from src/main/java/com/nexters/keyme/member/domain/internaldto/MemberModificationInfo.java rename to src/main/java/com/nexters/keyme/domain/member/domain/internaldto/MemberModificationInfo.java index 53bdd758..5ef41a9c 100644 --- a/src/main/java/com/nexters/keyme/member/domain/internaldto/MemberModificationInfo.java +++ b/src/main/java/com/nexters/keyme/domain/member/domain/internaldto/MemberModificationInfo.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.member.domain.internaldto; +package com.nexters.keyme.domain.member.domain.internaldto; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/nexters/keyme/member/domain/internaldto/ValidationInfo.java b/src/main/java/com/nexters/keyme/domain/member/domain/internaldto/ValidationInfo.java similarity index 80% rename from src/main/java/com/nexters/keyme/member/domain/internaldto/ValidationInfo.java rename to src/main/java/com/nexters/keyme/domain/member/domain/internaldto/ValidationInfo.java index 54c54203..bc2558c7 100644 --- a/src/main/java/com/nexters/keyme/member/domain/internaldto/ValidationInfo.java +++ b/src/main/java/com/nexters/keyme/domain/member/domain/internaldto/ValidationInfo.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.member.domain.internaldto; +package com.nexters.keyme.domain.member.domain.internaldto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/member/domain/model/MemberDevice.java b/src/main/java/com/nexters/keyme/domain/member/domain/model/MemberDevice.java similarity index 90% rename from src/main/java/com/nexters/keyme/member/domain/model/MemberDevice.java rename to src/main/java/com/nexters/keyme/domain/member/domain/model/MemberDevice.java index d642ab2d..49bc56ec 100644 --- a/src/main/java/com/nexters/keyme/member/domain/model/MemberDevice.java +++ b/src/main/java/com/nexters/keyme/domain/member/domain/model/MemberDevice.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.member.domain.model; +package com.nexters.keyme.domain.member.domain.model; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/nexters/keyme/member/domain/model/MemberEntity.java b/src/main/java/com/nexters/keyme/domain/member/domain/model/MemberEntity.java similarity index 88% rename from src/main/java/com/nexters/keyme/member/domain/model/MemberEntity.java rename to src/main/java/com/nexters/keyme/domain/member/domain/model/MemberEntity.java index 622284e9..f1343317 100644 --- a/src/main/java/com/nexters/keyme/member/domain/model/MemberEntity.java +++ b/src/main/java/com/nexters/keyme/domain/member/domain/model/MemberEntity.java @@ -1,7 +1,7 @@ -package com.nexters.keyme.member.domain.model; +package com.nexters.keyme.domain.member.domain.model; -import com.nexters.keyme.common.model.BaseTimeEntity; -import com.nexters.keyme.member.domain.internaldto.MemberModificationInfo; +import com.nexters.keyme.global.model.BaseTimeEntity; +import com.nexters.keyme.domain.member.domain.internaldto.MemberModificationInfo; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/member/domain/model/MemberOAuth.java b/src/main/java/com/nexters/keyme/domain/member/domain/model/MemberOAuth.java similarity index 90% rename from src/main/java/com/nexters/keyme/member/domain/model/MemberOAuth.java rename to src/main/java/com/nexters/keyme/domain/member/domain/model/MemberOAuth.java index 2f553fbc..6ea5978d 100644 --- a/src/main/java/com/nexters/keyme/member/domain/model/MemberOAuth.java +++ b/src/main/java/com/nexters/keyme/domain/member/domain/model/MemberOAuth.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.member.domain.model; +package com.nexters.keyme.domain.member.domain.model; import lombok.*; diff --git a/src/main/java/com/nexters/keyme/member/domain/model/MemberOAuthId.java b/src/main/java/com/nexters/keyme/domain/member/domain/model/MemberOAuthId.java similarity index 77% rename from src/main/java/com/nexters/keyme/member/domain/model/MemberOAuthId.java rename to src/main/java/com/nexters/keyme/domain/member/domain/model/MemberOAuthId.java index f4430ceb..005f166a 100644 --- a/src/main/java/com/nexters/keyme/member/domain/model/MemberOAuthId.java +++ b/src/main/java/com/nexters/keyme/domain/member/domain/model/MemberOAuthId.java @@ -1,8 +1,8 @@ -package com.nexters.keyme.member.domain.model; +package com.nexters.keyme.domain.member.domain.model; -import com.nexters.keyme.auth.domain.internaldto.OAuthUserInfo; -import com.nexters.keyme.common.enums.OAuthType; +import com.nexters.keyme.domain.auth.domain.internaldto.OAuthUserInfo; +import com.nexters.keyme.global.enums.OAuthType; import lombok.*; import javax.persistence.Column; diff --git a/src/main/java/com/nexters/keyme/domain/member/domain/model/MemberStatus.java b/src/main/java/com/nexters/keyme/domain/member/domain/model/MemberStatus.java new file mode 100644 index 00000000..60d9ec8d --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/member/domain/model/MemberStatus.java @@ -0,0 +1,5 @@ +package com.nexters.keyme.domain.member.domain.model; + +public enum MemberStatus { + ACTIVE +} diff --git a/src/main/java/com/nexters/keyme/member/domain/model/ProfileImage.java b/src/main/java/com/nexters/keyme/domain/member/domain/model/ProfileImage.java similarity index 83% rename from src/main/java/com/nexters/keyme/member/domain/model/ProfileImage.java rename to src/main/java/com/nexters/keyme/domain/member/domain/model/ProfileImage.java index f5da03e8..e649645e 100644 --- a/src/main/java/com/nexters/keyme/member/domain/model/ProfileImage.java +++ b/src/main/java/com/nexters/keyme/domain/member/domain/model/ProfileImage.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.member.domain.model; +package com.nexters.keyme.domain.member.domain.model; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/member/domain/repository/MemberDeviceRepository.java b/src/main/java/com/nexters/keyme/domain/member/domain/repository/MemberDeviceRepository.java similarity index 87% rename from src/main/java/com/nexters/keyme/member/domain/repository/MemberDeviceRepository.java rename to src/main/java/com/nexters/keyme/domain/member/domain/repository/MemberDeviceRepository.java index ecd70f96..3319a94a 100644 --- a/src/main/java/com/nexters/keyme/member/domain/repository/MemberDeviceRepository.java +++ b/src/main/java/com/nexters/keyme/domain/member/domain/repository/MemberDeviceRepository.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.member.domain.repository; +package com.nexters.keyme.domain.member.domain.repository; -import com.nexters.keyme.member.domain.model.MemberDevice; +import com.nexters.keyme.domain.member.domain.model.MemberDevice; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; diff --git a/src/main/java/com/nexters/keyme/domain/member/domain/repository/MemberOAuthRepository.java b/src/main/java/com/nexters/keyme/domain/member/domain/repository/MemberOAuthRepository.java new file mode 100644 index 00000000..b5480d76 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/member/domain/repository/MemberOAuthRepository.java @@ -0,0 +1,8 @@ +package com.nexters.keyme.domain.member.domain.repository; + +import com.nexters.keyme.domain.member.domain.model.MemberOAuth; +import com.nexters.keyme.domain.member.domain.model.MemberOAuthId; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MemberOAuthRepository extends JpaRepository { +} diff --git a/src/main/java/com/nexters/keyme/member/domain/repository/MemberRepository.java b/src/main/java/com/nexters/keyme/domain/member/domain/repository/MemberRepository.java similarity index 70% rename from src/main/java/com/nexters/keyme/member/domain/repository/MemberRepository.java rename to src/main/java/com/nexters/keyme/domain/member/domain/repository/MemberRepository.java index 81df40be..932b01c3 100644 --- a/src/main/java/com/nexters/keyme/member/domain/repository/MemberRepository.java +++ b/src/main/java/com/nexters/keyme/domain/member/domain/repository/MemberRepository.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.member.domain.repository; +package com.nexters.keyme.domain.member.domain.repository; -import com.nexters.keyme.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; diff --git a/src/main/java/com/nexters/keyme/member/domain/service/ImageUploader.java b/src/main/java/com/nexters/keyme/domain/member/domain/service/ImageUploader.java similarity index 53% rename from src/main/java/com/nexters/keyme/member/domain/service/ImageUploader.java rename to src/main/java/com/nexters/keyme/domain/member/domain/service/ImageUploader.java index b269c813..968768d2 100644 --- a/src/main/java/com/nexters/keyme/member/domain/service/ImageUploader.java +++ b/src/main/java/com/nexters/keyme/domain/member/domain/service/ImageUploader.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.member.domain.service; +package com.nexters.keyme.domain.member.domain.service; -import com.nexters.keyme.member.domain.internaldto.ImageInfo; +import com.nexters.keyme.domain.member.domain.internaldto.ImageInfo; import org.springframework.web.multipart.MultipartFile; diff --git a/src/main/java/com/nexters/keyme/member/domain/service/NicknameValidator.java b/src/main/java/com/nexters/keyme/domain/member/domain/service/NicknameValidator.java similarity index 59% rename from src/main/java/com/nexters/keyme/member/domain/service/NicknameValidator.java rename to src/main/java/com/nexters/keyme/domain/member/domain/service/NicknameValidator.java index 7521b50b..78bd1786 100644 --- a/src/main/java/com/nexters/keyme/member/domain/service/NicknameValidator.java +++ b/src/main/java/com/nexters/keyme/domain/member/domain/service/NicknameValidator.java @@ -1,10 +1,10 @@ -package com.nexters.keyme.member.domain.service; +package com.nexters.keyme.domain.member.domain.service; -import com.nexters.keyme.member.domain.exceptions.NicknameVerificationException; -import com.nexters.keyme.member.domain.internaldto.ValidationInfo; -import com.nexters.keyme.member.domain.model.MemberEntity; -import com.nexters.keyme.member.domain.repository.MemberRepository; -import com.nexters.keyme.member.domain.state.MemberStateCode; +import com.nexters.keyme.domain.member.domain.exceptions.NicknameDuplicateException; +import com.nexters.keyme.domain.member.domain.exceptions.NicknameTooLongException; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.member.domain.internaldto.ValidationInfo; +import com.nexters.keyme.domain.member.domain.repository.MemberRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -18,10 +18,10 @@ public class NicknameValidator { public ValidationInfo validateNickname(String nickname) { if (!checkLength(nickname)) { - throw new NicknameVerificationException(MemberStateCode.NICKNAME_TOO_LONG); + throw new NicknameTooLongException(); } if (!isUnique(nickname)) { - throw new NicknameVerificationException(MemberStateCode.DUPLICATED_NICKNAME); + throw new NicknameDuplicateException(); } return new ValidationInfo(true, "사용 가능한 닉네임입니다"); diff --git a/src/main/java/com/nexters/keyme/member/infrastructure/S3ImageUploader.java b/src/main/java/com/nexters/keyme/domain/member/infrastructure/S3ImageUploader.java similarity index 90% rename from src/main/java/com/nexters/keyme/member/infrastructure/S3ImageUploader.java rename to src/main/java/com/nexters/keyme/domain/member/infrastructure/S3ImageUploader.java index 288fb51e..6058c1ff 100644 --- a/src/main/java/com/nexters/keyme/member/infrastructure/S3ImageUploader.java +++ b/src/main/java/com/nexters/keyme/domain/member/infrastructure/S3ImageUploader.java @@ -1,10 +1,10 @@ -package com.nexters.keyme.member.infrastructure; +package com.nexters.keyme.domain.member.infrastructure; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.ObjectMetadata; -import com.nexters.keyme.common.exceptions.FileUploadFailedException; -import com.nexters.keyme.member.domain.internaldto.ImageInfo; -import com.nexters.keyme.member.domain.service.ImageUploader; +import com.nexters.keyme.global.exceptions.FileUploadFailedException; +import com.nexters.keyme.domain.member.domain.internaldto.ImageInfo; +import com.nexters.keyme.domain.member.domain.service.ImageUploader; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import net.coobird.thumbnailator.Thumbnails; diff --git a/src/main/java/com/nexters/keyme/member/presentation/controller/MemberController.java b/src/main/java/com/nexters/keyme/domain/member/presentation/controller/MemberController.java similarity index 74% rename from src/main/java/com/nexters/keyme/member/presentation/controller/MemberController.java rename to src/main/java/com/nexters/keyme/domain/member/presentation/controller/MemberController.java index 5bfdd2cf..d33e2592 100644 --- a/src/main/java/com/nexters/keyme/member/presentation/controller/MemberController.java +++ b/src/main/java/com/nexters/keyme/domain/member/presentation/controller/MemberController.java @@ -1,16 +1,16 @@ -package com.nexters.keyme.member.presentation.controller; +package com.nexters.keyme.domain.member.presentation.controller; -import com.nexters.keyme.auth.domain.internaldto.UserInfo; -import com.nexters.keyme.common.annotation.ApiSecurityIgnore; -import com.nexters.keyme.common.annotation.RequestUser; -import com.nexters.keyme.common.dto.response.ApiResponse; -import com.nexters.keyme.member.application.MemberService; -import com.nexters.keyme.member.presentation.dto.request.AddTokenRequest; -import com.nexters.keyme.member.presentation.dto.request.DeleteTokenRequest; -import com.nexters.keyme.member.presentation.dto.request.MemberModificationRequest; -import com.nexters.keyme.member.presentation.dto.request.NicknameVerificationRequest; -import com.nexters.keyme.member.presentation.dto.response.MemberResponse; -import com.nexters.keyme.member.presentation.dto.response.NicknameVerificationResponse; +import com.nexters.keyme.global.dto.internal.UserInfo; +import com.nexters.keyme.domain.member.application.MemberService; +import com.nexters.keyme.domain.member.presentation.dto.request.AddTokenRequest; +import com.nexters.keyme.domain.member.presentation.dto.request.DeleteTokenRequest; +import com.nexters.keyme.domain.member.presentation.dto.request.MemberModificationRequest; +import com.nexters.keyme.domain.member.presentation.dto.request.NicknameVerificationRequest; +import com.nexters.keyme.global.annotation.ApiSecurityIgnore; +import com.nexters.keyme.global.annotation.RequestUser; +import com.nexters.keyme.global.dto.response.ApiResponse; +import com.nexters.keyme.domain.member.presentation.dto.response.MemberResponse; +import com.nexters.keyme.domain.member.presentation.dto.response.NicknameVerificationResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/member/presentation/controller/ProfileImageController.java b/src/main/java/com/nexters/keyme/domain/member/presentation/controller/ProfileImageController.java similarity index 71% rename from src/main/java/com/nexters/keyme/member/presentation/controller/ProfileImageController.java rename to src/main/java/com/nexters/keyme/domain/member/presentation/controller/ProfileImageController.java index b758f538..6a78a1f8 100644 --- a/src/main/java/com/nexters/keyme/member/presentation/controller/ProfileImageController.java +++ b/src/main/java/com/nexters/keyme/domain/member/presentation/controller/ProfileImageController.java @@ -1,11 +1,10 @@ -package com.nexters.keyme.member.presentation.controller; +package com.nexters.keyme.domain.member.presentation.controller; -import com.nexters.keyme.common.dto.response.ApiResponse; -import com.nexters.keyme.member.application.MemberService; -import com.nexters.keyme.member.presentation.dto.response.ImageResponse; +import com.nexters.keyme.domain.member.application.MemberService; +import com.nexters.keyme.domain.member.presentation.dto.response.ImageResponse; +import com.nexters.keyme.global.dto.response.ApiResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; @@ -14,8 +13,6 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import static com.nexters.keyme.common.config.SwaggerConfig.SWAGGER_AUTHORIZATION_SCHEME; - @RestController @RequestMapping("/images") @RequiredArgsConstructor diff --git a/src/main/java/com/nexters/keyme/member/presentation/dto/request/AddTokenRequest.java b/src/main/java/com/nexters/keyme/domain/member/presentation/dto/request/AddTokenRequest.java similarity index 82% rename from src/main/java/com/nexters/keyme/member/presentation/dto/request/AddTokenRequest.java rename to src/main/java/com/nexters/keyme/domain/member/presentation/dto/request/AddTokenRequest.java index 626100a7..8d832079 100644 --- a/src/main/java/com/nexters/keyme/member/presentation/dto/request/AddTokenRequest.java +++ b/src/main/java/com/nexters/keyme/domain/member/presentation/dto/request/AddTokenRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.member.presentation.dto.request; +package com.nexters.keyme.domain.member.presentation.dto.request; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/member/presentation/dto/request/DeleteTokenRequest.java b/src/main/java/com/nexters/keyme/domain/member/presentation/dto/request/DeleteTokenRequest.java similarity index 82% rename from src/main/java/com/nexters/keyme/member/presentation/dto/request/DeleteTokenRequest.java rename to src/main/java/com/nexters/keyme/domain/member/presentation/dto/request/DeleteTokenRequest.java index b8ef1c94..b8de139d 100644 --- a/src/main/java/com/nexters/keyme/member/presentation/dto/request/DeleteTokenRequest.java +++ b/src/main/java/com/nexters/keyme/domain/member/presentation/dto/request/DeleteTokenRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.member.presentation.dto.request; +package com.nexters.keyme.domain.member.presentation.dto.request; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/member/presentation/dto/request/MemberModificationRequest.java b/src/main/java/com/nexters/keyme/domain/member/presentation/dto/request/MemberModificationRequest.java similarity index 89% rename from src/main/java/com/nexters/keyme/member/presentation/dto/request/MemberModificationRequest.java rename to src/main/java/com/nexters/keyme/domain/member/presentation/dto/request/MemberModificationRequest.java index 22e3f162..96334ca0 100644 --- a/src/main/java/com/nexters/keyme/member/presentation/dto/request/MemberModificationRequest.java +++ b/src/main/java/com/nexters/keyme/domain/member/presentation/dto/request/MemberModificationRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.member.presentation.dto.request; +package com.nexters.keyme.domain.member.presentation.dto.request; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/member/presentation/dto/request/NicknameVerificationRequest.java b/src/main/java/com/nexters/keyme/domain/member/presentation/dto/request/NicknameVerificationRequest.java similarity index 84% rename from src/main/java/com/nexters/keyme/member/presentation/dto/request/NicknameVerificationRequest.java rename to src/main/java/com/nexters/keyme/domain/member/presentation/dto/request/NicknameVerificationRequest.java index 7ba50304..d77c35bd 100644 --- a/src/main/java/com/nexters/keyme/member/presentation/dto/request/NicknameVerificationRequest.java +++ b/src/main/java/com/nexters/keyme/domain/member/presentation/dto/request/NicknameVerificationRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.member.presentation.dto.request; +package com.nexters.keyme.domain.member.presentation.dto.request; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/member/presentation/dto/response/ImageResponse.java b/src/main/java/com/nexters/keyme/domain/member/presentation/dto/response/ImageResponse.java similarity index 80% rename from src/main/java/com/nexters/keyme/member/presentation/dto/response/ImageResponse.java rename to src/main/java/com/nexters/keyme/domain/member/presentation/dto/response/ImageResponse.java index f2a1b8b4..931fc6e2 100644 --- a/src/main/java/com/nexters/keyme/member/presentation/dto/response/ImageResponse.java +++ b/src/main/java/com/nexters/keyme/domain/member/presentation/dto/response/ImageResponse.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.member.presentation.dto.response; +package com.nexters.keyme.domain.member.presentation.dto.response; -import com.nexters.keyme.member.domain.internaldto.ImageInfo; +import com.nexters.keyme.domain.member.domain.internaldto.ImageInfo; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/member/presentation/dto/response/MemberResponse.java b/src/main/java/com/nexters/keyme/domain/member/presentation/dto/response/MemberResponse.java similarity index 89% rename from src/main/java/com/nexters/keyme/member/presentation/dto/response/MemberResponse.java rename to src/main/java/com/nexters/keyme/domain/member/presentation/dto/response/MemberResponse.java index 20e72d93..ff41d409 100644 --- a/src/main/java/com/nexters/keyme/member/presentation/dto/response/MemberResponse.java +++ b/src/main/java/com/nexters/keyme/domain/member/presentation/dto/response/MemberResponse.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.member.presentation.dto.response; +package com.nexters.keyme.domain.member.presentation.dto.response; -import com.nexters.keyme.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/nexters/keyme/member/presentation/dto/response/MemberWithTokenResponse.java b/src/main/java/com/nexters/keyme/domain/member/presentation/dto/response/MemberWithTokenResponse.java similarity index 82% rename from src/main/java/com/nexters/keyme/member/presentation/dto/response/MemberWithTokenResponse.java rename to src/main/java/com/nexters/keyme/domain/member/presentation/dto/response/MemberWithTokenResponse.java index 525aac9d..29b5cc75 100644 --- a/src/main/java/com/nexters/keyme/member/presentation/dto/response/MemberWithTokenResponse.java +++ b/src/main/java/com/nexters/keyme/domain/member/presentation/dto/response/MemberWithTokenResponse.java @@ -1,7 +1,7 @@ -package com.nexters.keyme.member.presentation.dto.response; +package com.nexters.keyme.domain.member.presentation.dto.response; -import com.nexters.keyme.auth.presentation.dto.response.TokenResponse; -import com.nexters.keyme.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.auth.presentation.dto.response.TokenResponse; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/nexters/keyme/member/presentation/dto/response/NicknameVerificationResponse.java b/src/main/java/com/nexters/keyme/domain/member/presentation/dto/response/NicknameVerificationResponse.java similarity index 86% rename from src/main/java/com/nexters/keyme/member/presentation/dto/response/NicknameVerificationResponse.java rename to src/main/java/com/nexters/keyme/domain/member/presentation/dto/response/NicknameVerificationResponse.java index 97aa2922..e6ebc79f 100644 --- a/src/main/java/com/nexters/keyme/member/presentation/dto/response/NicknameVerificationResponse.java +++ b/src/main/java/com/nexters/keyme/domain/member/presentation/dto/response/NicknameVerificationResponse.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.member.presentation.dto.response; +package com.nexters.keyme.domain.member.presentation.dto.response; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/notification/config/FirebaseConfig.java b/src/main/java/com/nexters/keyme/domain/notification/config/FirebaseConfig.java similarity index 96% rename from src/main/java/com/nexters/keyme/notification/config/FirebaseConfig.java rename to src/main/java/com/nexters/keyme/domain/notification/config/FirebaseConfig.java index f07718da..947907c1 100644 --- a/src/main/java/com/nexters/keyme/notification/config/FirebaseConfig.java +++ b/src/main/java/com/nexters/keyme/domain/notification/config/FirebaseConfig.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.notification.config; +package com.nexters.keyme.domain.notification.config; import com.google.auth.oauth2.GoogleCredentials; import com.google.firebase.FirebaseApp; diff --git a/src/main/java/com/nexters/keyme/notification/config/NotificationThreadPoolConfig.java b/src/main/java/com/nexters/keyme/domain/notification/config/NotificationThreadPoolConfig.java similarity index 93% rename from src/main/java/com/nexters/keyme/notification/config/NotificationThreadPoolConfig.java rename to src/main/java/com/nexters/keyme/domain/notification/config/NotificationThreadPoolConfig.java index 448980af..f09a4204 100644 --- a/src/main/java/com/nexters/keyme/notification/config/NotificationThreadPoolConfig.java +++ b/src/main/java/com/nexters/keyme/domain/notification/config/NotificationThreadPoolConfig.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.notification.config; +package com.nexters.keyme.domain.notification.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/com/nexters/keyme/notification/dto/TopicNotificationRequest.java b/src/main/java/com/nexters/keyme/domain/notification/dto/TopicNotificationRequest.java similarity index 90% rename from src/main/java/com/nexters/keyme/notification/dto/TopicNotificationRequest.java rename to src/main/java/com/nexters/keyme/domain/notification/dto/TopicNotificationRequest.java index fef22c2d..1295ce3e 100644 --- a/src/main/java/com/nexters/keyme/notification/dto/TopicNotificationRequest.java +++ b/src/main/java/com/nexters/keyme/domain/notification/dto/TopicNotificationRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.notification.dto; +package com.nexters.keyme.domain.notification.dto; import lombok.*; diff --git a/src/main/java/com/nexters/keyme/notification/dto/UserNotificationRequest.java b/src/main/java/com/nexters/keyme/domain/notification/dto/UserNotificationRequest.java similarity index 90% rename from src/main/java/com/nexters/keyme/notification/dto/UserNotificationRequest.java rename to src/main/java/com/nexters/keyme/domain/notification/dto/UserNotificationRequest.java index b9f1e48b..61a0a15e 100644 --- a/src/main/java/com/nexters/keyme/notification/dto/UserNotificationRequest.java +++ b/src/main/java/com/nexters/keyme/domain/notification/dto/UserNotificationRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.notification.dto; +package com.nexters.keyme.domain.notification.dto; import lombok.*; diff --git a/src/main/java/com/nexters/keyme/notification/handler/NotificationRequestHandler.java b/src/main/java/com/nexters/keyme/domain/notification/handler/NotificationRequestHandler.java similarity index 68% rename from src/main/java/com/nexters/keyme/notification/handler/NotificationRequestHandler.java rename to src/main/java/com/nexters/keyme/domain/notification/handler/NotificationRequestHandler.java index e32b5786..862d9108 100644 --- a/src/main/java/com/nexters/keyme/notification/handler/NotificationRequestHandler.java +++ b/src/main/java/com/nexters/keyme/domain/notification/handler/NotificationRequestHandler.java @@ -1,8 +1,8 @@ -package com.nexters.keyme.notification.handler; +package com.nexters.keyme.domain.notification.handler; -import com.nexters.keyme.notification.dto.TopicNotificationRequest; -import com.nexters.keyme.notification.dto.UserNotificationRequest; -import com.nexters.keyme.notification.service.NotificationService; +import com.nexters.keyme.domain.notification.dto.TopicNotificationRequest; +import com.nexters.keyme.domain.notification.dto.UserNotificationRequest; +import com.nexters.keyme.domain.notification.service.NotificationService; import lombok.RequiredArgsConstructor; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/nexters/keyme/notification/helper/FCMNotificationSender.java b/src/main/java/com/nexters/keyme/domain/notification/helper/FCMNotificationSender.java similarity index 98% rename from src/main/java/com/nexters/keyme/notification/helper/FCMNotificationSender.java rename to src/main/java/com/nexters/keyme/domain/notification/helper/FCMNotificationSender.java index 0f8cfc98..eaf3131e 100644 --- a/src/main/java/com/nexters/keyme/notification/helper/FCMNotificationSender.java +++ b/src/main/java/com/nexters/keyme/domain/notification/helper/FCMNotificationSender.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.notification.helper; +package com.nexters.keyme.domain.notification.helper; import com.google.firebase.messaging.*; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/notification/helper/NotificationSender.java b/src/main/java/com/nexters/keyme/domain/notification/helper/NotificationSender.java similarity index 83% rename from src/main/java/com/nexters/keyme/notification/helper/NotificationSender.java rename to src/main/java/com/nexters/keyme/domain/notification/helper/NotificationSender.java index 0b6521bb..41b2bc16 100644 --- a/src/main/java/com/nexters/keyme/notification/helper/NotificationSender.java +++ b/src/main/java/com/nexters/keyme/domain/notification/helper/NotificationSender.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.notification.helper; +package com.nexters.keyme.domain.notification.helper; import java.util.List; import java.util.Map; diff --git a/src/main/java/com/nexters/keyme/notification/presentation/controller/NotificationController.java b/src/main/java/com/nexters/keyme/domain/notification/presentation/controller/NotificationController.java similarity index 79% rename from src/main/java/com/nexters/keyme/notification/presentation/controller/NotificationController.java rename to src/main/java/com/nexters/keyme/domain/notification/presentation/controller/NotificationController.java index 90e42c7c..c6410b7d 100644 --- a/src/main/java/com/nexters/keyme/notification/presentation/controller/NotificationController.java +++ b/src/main/java/com/nexters/keyme/domain/notification/presentation/controller/NotificationController.java @@ -1,7 +1,7 @@ -package com.nexters.keyme.notification.presentation.controller; +package com.nexters.keyme.domain.notification.presentation.controller; -import com.nexters.keyme.common.dto.response.ApiResponse; -import com.nexters.keyme.notification.presentation.dto.NotificationResponse; +import com.nexters.keyme.global.dto.response.ApiResponse; +import com.nexters.keyme.domain.notification.presentation.dto.NotificationResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.v3.oas.annotations.security.SecurityRequirement; @@ -15,7 +15,7 @@ import java.time.LocalDateTime; import java.util.List; -import static com.nexters.keyme.common.config.SwaggerConfig.SWAGGER_AUTHORIZATION_SCHEME; +import static com.nexters.keyme.global.config.SwaggerConfig.SWAGGER_AUTHORIZATION_SCHEME; @RestController @RequestMapping("/notifications") @@ -35,6 +35,6 @@ public ResponseEntity>> getMemberInfo(@Pa .isRead(false) .build(); - return ResponseEntity.ok(new ApiResponse<>(List.of(notification))); + return ResponseEntity.ok(ApiResponse.success(List.of(notification))); } } diff --git a/src/main/java/com/nexters/keyme/notification/presentation/dto/NotificationResponse.java b/src/main/java/com/nexters/keyme/domain/notification/presentation/dto/NotificationResponse.java similarity index 93% rename from src/main/java/com/nexters/keyme/notification/presentation/dto/NotificationResponse.java rename to src/main/java/com/nexters/keyme/domain/notification/presentation/dto/NotificationResponse.java index 04ee3d64..4be11a82 100644 --- a/src/main/java/com/nexters/keyme/notification/presentation/dto/NotificationResponse.java +++ b/src/main/java/com/nexters/keyme/domain/notification/presentation/dto/NotificationResponse.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.notification.presentation.dto; +package com.nexters.keyme.domain.notification.presentation.dto; import io.swagger.annotations.ApiModelProperty; diff --git a/src/main/java/com/nexters/keyme/notification/service/NotificationService.java b/src/main/java/com/nexters/keyme/domain/notification/service/NotificationService.java similarity index 52% rename from src/main/java/com/nexters/keyme/notification/service/NotificationService.java rename to src/main/java/com/nexters/keyme/domain/notification/service/NotificationService.java index ccde85ae..87560bd4 100644 --- a/src/main/java/com/nexters/keyme/notification/service/NotificationService.java +++ b/src/main/java/com/nexters/keyme/domain/notification/service/NotificationService.java @@ -1,7 +1,7 @@ -package com.nexters.keyme.notification.service; +package com.nexters.keyme.domain.notification.service; -import com.nexters.keyme.notification.dto.TopicNotificationRequest; -import com.nexters.keyme.notification.dto.UserNotificationRequest; +import com.nexters.keyme.domain.notification.dto.TopicNotificationRequest; +import com.nexters.keyme.domain.notification.dto.UserNotificationRequest; import java.util.concurrent.CompletableFuture; diff --git a/src/main/java/com/nexters/keyme/notification/service/NotificationServiceImpl.java b/src/main/java/com/nexters/keyme/domain/notification/service/NotificationServiceImpl.java similarity index 75% rename from src/main/java/com/nexters/keyme/notification/service/NotificationServiceImpl.java rename to src/main/java/com/nexters/keyme/domain/notification/service/NotificationServiceImpl.java index c1ec44c3..30f6d112 100644 --- a/src/main/java/com/nexters/keyme/notification/service/NotificationServiceImpl.java +++ b/src/main/java/com/nexters/keyme/domain/notification/service/NotificationServiceImpl.java @@ -1,10 +1,10 @@ -package com.nexters.keyme.notification.service; +package com.nexters.keyme.domain.notification.service; -import com.nexters.keyme.member.domain.model.MemberDevice; -import com.nexters.keyme.member.domain.repository.MemberDeviceRepository; -import com.nexters.keyme.notification.dto.TopicNotificationRequest; -import com.nexters.keyme.notification.dto.UserNotificationRequest; -import com.nexters.keyme.notification.helper.NotificationSender; +import com.nexters.keyme.domain.notification.dto.TopicNotificationRequest; +import com.nexters.keyme.domain.notification.dto.UserNotificationRequest; +import com.nexters.keyme.domain.member.domain.model.MemberDevice; +import com.nexters.keyme.domain.member.domain.repository.MemberDeviceRepository; +import com.nexters.keyme.domain.notification.helper.NotificationSender; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Async; diff --git a/src/main/java/com/nexters/keyme/domain/question/application/QuestionService.java b/src/main/java/com/nexters/keyme/domain/question/application/QuestionService.java new file mode 100644 index 00000000..992602d9 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/question/application/QuestionService.java @@ -0,0 +1,18 @@ +package com.nexters.keyme.domain.question.application; + +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionResponse; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionScoreInfoResponse; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionStatisticResponse; +import com.nexters.keyme.global.dto.response.PageResponse; +import com.nexters.keyme.domain.question.presentation.dto.request.QuestionScoreListRequest; +import com.nexters.keyme.domain.question.presentation.dto.request.QuestionListScoreRequest; +import com.nexters.keyme.domain.question.presentation.dto.request.QuestionStatisticRequest; + +import java.util.List; + +public interface QuestionService { + QuestionResponse getQuestion(Long questionId); + QuestionStatisticResponse getQuestionStatistic(Long questionId, QuestionStatisticRequest request); + PageResponse getQuestionSolvedList(Long questionId, QuestionScoreListRequest request); + List getQuestionSolvedScore(QuestionListScoreRequest request); +} \ No newline at end of file diff --git a/src/main/java/com/nexters/keyme/question/application/QuestionServiceImpl.java b/src/main/java/com/nexters/keyme/domain/question/application/QuestionServiceImpl.java similarity index 57% rename from src/main/java/com/nexters/keyme/question/application/QuestionServiceImpl.java rename to src/main/java/com/nexters/keyme/domain/question/application/QuestionServiceImpl.java index bbc7bfd6..d6595f06 100644 --- a/src/main/java/com/nexters/keyme/question/application/QuestionServiceImpl.java +++ b/src/main/java/com/nexters/keyme/domain/question/application/QuestionServiceImpl.java @@ -1,24 +1,26 @@ -package com.nexters.keyme.question.application; +package com.nexters.keyme.domain.question.application; -import com.nexters.keyme.common.dto.internal.PageInfo; -import com.nexters.keyme.common.dto.response.PageResponse; -import com.nexters.keyme.common.exceptions.ResourceNotFoundException; -import com.nexters.keyme.member.domain.model.MemberEntity; -import com.nexters.keyme.member.domain.repository.MemberRepository; -import com.nexters.keyme.question.domain.internaldto.QuestionStatisticInfo; -import com.nexters.keyme.question.domain.model.Question; -import com.nexters.keyme.question.domain.model.QuestionSolved; -import com.nexters.keyme.question.domain.repository.QuestionRepository; -import com.nexters.keyme.question.domain.repository.QuestionSolvedRepository; -import com.nexters.keyme.question.presentation.dto.request.QuestionScoreListRequest; -import com.nexters.keyme.question.presentation.dto.request.QuestionListScoreRequest; -import com.nexters.keyme.question.presentation.dto.request.QuestionStatisticRequest; -import com.nexters.keyme.question.presentation.dto.response.*; +import com.nexters.keyme.domain.member.domain.exceptions.NotFoundMemberException; +import com.nexters.keyme.domain.question.domain.exceptions.NotFoundQuestionException; +import com.nexters.keyme.domain.question.domain.model.Question; +import com.nexters.keyme.domain.question.domain.model.QuestionSolved; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionResponse; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionScoreInfoResponse; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionStatisticResponse; +import com.nexters.keyme.global.dto.internal.PageInfo; +import com.nexters.keyme.global.dto.response.PageResponse; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.member.domain.repository.MemberRepository; +import com.nexters.keyme.domain.question.domain.internaldto.QuestionStatisticInfo; +import com.nexters.keyme.domain.question.domain.repository.QuestionRepository; +import com.nexters.keyme.domain.question.domain.repository.QuestionSolvedRepository; +import com.nexters.keyme.domain.question.presentation.dto.request.QuestionScoreListRequest; +import com.nexters.keyme.domain.question.presentation.dto.request.QuestionListScoreRequest; +import com.nexters.keyme.domain.question.presentation.dto.request.QuestionStatisticRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -32,28 +34,23 @@ public class QuestionServiceImpl implements QuestionService { @Override public QuestionResponse getQuestion(Long questionId) { - Question question = questionRepository.findById(questionId).orElseThrow(ResourceNotFoundException::new); + Question question = questionRepository.findById(questionId).orElseThrow(NotFoundQuestionException::new); return new QuestionResponse(question); } @Override public QuestionStatisticResponse getQuestionStatistic(Long questionId, QuestionStatisticRequest request) { - Question question = questionRepository.findById(questionId).orElseThrow(ResourceNotFoundException::new); - MemberEntity member = memberRepository.findById(request.getOwnerId()).orElseThrow(ResourceNotFoundException::new); - QuestionStatisticInfo questionStatisticInfo = questionSolvedRepository.findQuestionStatisticsByQuestionIdAndOwnerId(questionId, request.getOwnerId()).orElseThrow(ResourceNotFoundException::new); - - // questionStatisticInfo에 값들이 null일 수 있음(푼 사람이 아무도 없을때) - if (questionStatisticInfo.getCategoryName() == null) { - return new QuestionStatisticResponse(question); - } + Question question = questionRepository.findById(questionId).orElseThrow(NotFoundQuestionException::new); + MemberEntity member = memberRepository.findById(request.getOwnerId()).orElseThrow(NotFoundMemberException::new); + QuestionStatisticInfo questionStatisticInfo = questionSolvedRepository.findQuestionStatisticsByQuestionIdAndOwnerId(questionId, request.getOwnerId()); return new QuestionStatisticResponse(questionStatisticInfo); } @Override public PageResponse getQuestionSolvedList(Long questionId, QuestionScoreListRequest request) { - Question question = questionRepository.findById(questionId).orElseThrow(ResourceNotFoundException::new); - MemberEntity member = memberRepository.findById(request.getOwnerId()).orElseThrow(ResourceNotFoundException::new); + Question question = questionRepository.findById(questionId).orElseThrow(NotFoundQuestionException::new); + MemberEntity member = memberRepository.findById(request.getOwnerId()).orElseThrow(NotFoundMemberException::new); PageInfo solvedPage = questionSolvedRepository.findQuestionSolvedList(questionId, request.getOwnerId(), request.getCursor(), request.getLimit()); @@ -67,13 +64,14 @@ public PageResponse getQuestionSolvedList(Long questi } @Override + @Deprecated public List getQuestionSolvedScore(QuestionListScoreRequest request) { List question = questionRepository.findAllById(request.getIds()); if (question.size() != request.getIds().size()) { - throw new ResourceNotFoundException(); + throw new NotFoundQuestionException(); } - MemberEntity member = memberRepository.findById(request.getOwnerId()).orElseThrow(ResourceNotFoundException::new); + MemberEntity member = memberRepository.findById(request.getOwnerId()).orElseThrow(NotFoundMemberException::new); List questionSolvedList = questionSolvedRepository.findByQuestionIdsAndOwnerIdAndSolverId(request.getIds(), request.getOwnerId(), request.getSolverId()); return questionSolvedList.stream() diff --git a/src/main/java/com/nexters/keyme/question/domain/enums/QuestionCategoryType.java b/src/main/java/com/nexters/keyme/domain/question/domain/enums/QuestionCategoryType.java similarity index 96% rename from src/main/java/com/nexters/keyme/question/domain/enums/QuestionCategoryType.java rename to src/main/java/com/nexters/keyme/domain/question/domain/enums/QuestionCategoryType.java index 82c9f221..acc18055 100644 --- a/src/main/java/com/nexters/keyme/question/domain/enums/QuestionCategoryType.java +++ b/src/main/java/com/nexters/keyme/domain/question/domain/enums/QuestionCategoryType.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.question.domain.enums; +package com.nexters.keyme.domain.question.domain.enums; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/domain/question/domain/exceptions/NotFoundQuestionException.java b/src/main/java/com/nexters/keyme/domain/question/domain/exceptions/NotFoundQuestionException.java new file mode 100644 index 00000000..db65b2f7 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/question/domain/exceptions/NotFoundQuestionException.java @@ -0,0 +1,10 @@ +package com.nexters.keyme.domain.question.domain.exceptions; + +import com.nexters.keyme.domain.question.domain.exceptions.code.QuestionErrorCode; +import com.nexters.keyme.global.exceptions.KeymeNotFoundException; + +public class NotFoundQuestionException extends KeymeNotFoundException { + public NotFoundQuestionException() { + super(QuestionErrorCode.NOT_FOUND_QUESTION.getMessage(), QuestionErrorCode.NOT_FOUND_QUESTION.getCode()); + } +} diff --git a/src/main/java/com/nexters/keyme/domain/question/domain/exceptions/code/QuestionErrorCode.java b/src/main/java/com/nexters/keyme/domain/question/domain/exceptions/code/QuestionErrorCode.java new file mode 100644 index 00000000..5ec35a68 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/question/domain/exceptions/code/QuestionErrorCode.java @@ -0,0 +1,14 @@ +package com.nexters.keyme.domain.question.domain.exceptions.code; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum QuestionErrorCode { + + NOT_FOUND_QUESTION(400, "Question을 찾을 수 없습니다."); + + private final int code; + private final String message; +} diff --git a/src/main/java/com/nexters/keyme/question/domain/helper/QuestionAsyncDataProvider.java b/src/main/java/com/nexters/keyme/domain/question/domain/helper/QuestionAsyncDataProvider.java similarity index 75% rename from src/main/java/com/nexters/keyme/question/domain/helper/QuestionAsyncDataProvider.java rename to src/main/java/com/nexters/keyme/domain/question/domain/helper/QuestionAsyncDataProvider.java index 89bcea84..f601bd7b 100644 --- a/src/main/java/com/nexters/keyme/question/domain/helper/QuestionAsyncDataProvider.java +++ b/src/main/java/com/nexters/keyme/domain/question/domain/helper/QuestionAsyncDataProvider.java @@ -1,7 +1,7 @@ -package com.nexters.keyme.question.domain.helper; +package com.nexters.keyme.domain.question.domain.helper; -import com.nexters.keyme.question.domain.model.Question; -import com.nexters.keyme.question.domain.repository.QuestionRepository; +import com.nexters.keyme.domain.question.domain.model.Question; +import com.nexters.keyme.domain.question.domain.repository.QuestionRepository; import lombok.RequiredArgsConstructor; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/nexters/keyme/question/domain/internaldto/QuestionStatisticInfo.java b/src/main/java/com/nexters/keyme/domain/question/domain/internaldto/QuestionStatisticInfo.java similarity index 56% rename from src/main/java/com/nexters/keyme/question/domain/internaldto/QuestionStatisticInfo.java rename to src/main/java/com/nexters/keyme/domain/question/domain/internaldto/QuestionStatisticInfo.java index cf617b4a..fa4b19d5 100644 --- a/src/main/java/com/nexters/keyme/question/domain/internaldto/QuestionStatisticInfo.java +++ b/src/main/java/com/nexters/keyme/domain/question/domain/internaldto/QuestionStatisticInfo.java @@ -1,8 +1,6 @@ -package com.nexters.keyme.question.domain.internaldto; +package com.nexters.keyme.domain.question.domain.internaldto; -import com.nexters.keyme.question.domain.enums.QuestionCategoryType; -import com.nexters.keyme.question.presentation.dto.response.QuestionCategoryResponse; -import io.swagger.annotations.ApiModelProperty; +import com.nexters.keyme.domain.question.domain.enums.QuestionCategoryType; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/question/domain/model/Question.java b/src/main/java/com/nexters/keyme/domain/question/domain/model/Question.java similarity index 76% rename from src/main/java/com/nexters/keyme/question/domain/model/Question.java rename to src/main/java/com/nexters/keyme/domain/question/domain/model/Question.java index 14a7f0f4..c54bfbbe 100644 --- a/src/main/java/com/nexters/keyme/question/domain/model/Question.java +++ b/src/main/java/com/nexters/keyme/domain/question/domain/model/Question.java @@ -1,9 +1,7 @@ -package com.nexters.keyme.question.domain.model; +package com.nexters.keyme.domain.question.domain.model; -import com.nexters.keyme.common.model.BaseTimeEntity; -import com.nexters.keyme.question.domain.enums.QuestionCategoryType; -import com.nexters.keyme.question.presentation.dto.response.QuestionCategoryResponse; -import com.nexters.keyme.question.presentation.dto.response.QuestionResponse; +import com.nexters.keyme.global.model.BaseTimeEntity; +import com.nexters.keyme.domain.question.domain.enums.QuestionCategoryType; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/question/domain/model/QuestionBundle.java b/src/main/java/com/nexters/keyme/domain/question/domain/model/QuestionBundle.java similarity index 87% rename from src/main/java/com/nexters/keyme/question/domain/model/QuestionBundle.java rename to src/main/java/com/nexters/keyme/domain/question/domain/model/QuestionBundle.java index d381dc47..83af7107 100644 --- a/src/main/java/com/nexters/keyme/question/domain/model/QuestionBundle.java +++ b/src/main/java/com/nexters/keyme/domain/question/domain/model/QuestionBundle.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.question.domain.model; +package com.nexters.keyme.domain.question.domain.model; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/question/domain/model/QuestionBundleId.java b/src/main/java/com/nexters/keyme/domain/question/domain/model/QuestionBundleId.java similarity index 85% rename from src/main/java/com/nexters/keyme/question/domain/model/QuestionBundleId.java rename to src/main/java/com/nexters/keyme/domain/question/domain/model/QuestionBundleId.java index 1c55df7d..258b3d2e 100644 --- a/src/main/java/com/nexters/keyme/question/domain/model/QuestionBundleId.java +++ b/src/main/java/com/nexters/keyme/domain/question/domain/model/QuestionBundleId.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.question.domain.model; +package com.nexters.keyme.domain.question.domain.model; -import com.nexters.keyme.test.domain.model.Test; +import com.nexters.keyme.domain.test.domain.model.Test; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/question/domain/model/QuestionSolved.java b/src/main/java/com/nexters/keyme/domain/question/domain/model/QuestionSolved.java similarity index 65% rename from src/main/java/com/nexters/keyme/question/domain/model/QuestionSolved.java rename to src/main/java/com/nexters/keyme/domain/question/domain/model/QuestionSolved.java index 1fac0787..771d2038 100644 --- a/src/main/java/com/nexters/keyme/question/domain/model/QuestionSolved.java +++ b/src/main/java/com/nexters/keyme/domain/question/domain/model/QuestionSolved.java @@ -1,11 +1,8 @@ -package com.nexters.keyme.question.domain.model; +package com.nexters.keyme.domain.question.domain.model; -import com.nexters.keyme.common.model.BaseTimeEntity; -import com.nexters.keyme.member.domain.model.MemberEntity; -import com.nexters.keyme.question.presentation.dto.response.QuestionCategoryResponse; -import com.nexters.keyme.question.presentation.dto.response.QuestionResponse; -import com.nexters.keyme.question.presentation.dto.response.QuestionSolvedResponse; -import com.nexters.keyme.test.domain.model.TestResult; +import com.nexters.keyme.global.model.BaseTimeEntity; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.test.domain.model.TestResult; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/domain/question/domain/repository/QuestionBundleRepository.java b/src/main/java/com/nexters/keyme/domain/question/domain/repository/QuestionBundleRepository.java new file mode 100644 index 00000000..99edd6c4 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/question/domain/repository/QuestionBundleRepository.java @@ -0,0 +1,8 @@ +package com.nexters.keyme.domain.question.domain.repository; + +import com.nexters.keyme.domain.question.domain.model.QuestionBundle; +import com.nexters.keyme.domain.question.domain.model.QuestionBundleId; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface QuestionBundleRepository extends JpaRepository { +} diff --git a/src/main/java/com/nexters/keyme/question/domain/repository/QuestionRepository.java b/src/main/java/com/nexters/keyme/domain/question/domain/repository/QuestionRepository.java similarity index 79% rename from src/main/java/com/nexters/keyme/question/domain/repository/QuestionRepository.java rename to src/main/java/com/nexters/keyme/domain/question/domain/repository/QuestionRepository.java index 02452155..fb99f384 100644 --- a/src/main/java/com/nexters/keyme/question/domain/repository/QuestionRepository.java +++ b/src/main/java/com/nexters/keyme/domain/question/domain/repository/QuestionRepository.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.question.domain.repository; +package com.nexters.keyme.domain.question.domain.repository; -import com.nexters.keyme.question.domain.model.Question; +import com.nexters.keyme.domain.question.domain.model.Question; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; diff --git a/src/main/java/com/nexters/keyme/question/domain/repository/QuestionSolvedRepository.java b/src/main/java/com/nexters/keyme/domain/question/domain/repository/QuestionSolvedRepository.java similarity index 69% rename from src/main/java/com/nexters/keyme/question/domain/repository/QuestionSolvedRepository.java rename to src/main/java/com/nexters/keyme/domain/question/domain/repository/QuestionSolvedRepository.java index 45afe160..70a0b149 100644 --- a/src/main/java/com/nexters/keyme/question/domain/repository/QuestionSolvedRepository.java +++ b/src/main/java/com/nexters/keyme/domain/question/domain/repository/QuestionSolvedRepository.java @@ -1,9 +1,7 @@ -package com.nexters.keyme.question.domain.repository; +package com.nexters.keyme.domain.question.domain.repository; -import com.nexters.keyme.member.domain.model.MemberEntity; -import com.nexters.keyme.question.domain.internaldto.QuestionStatisticInfo; -import com.nexters.keyme.question.domain.model.Question; -import com.nexters.keyme.question.domain.model.QuestionSolved; +import com.nexters.keyme.domain.question.domain.model.QuestionSolved; +import com.nexters.keyme.domain.question.domain.internaldto.QuestionStatisticInfo; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -27,7 +25,7 @@ public interface QuestionSolvedRepository extends JpaRepository findAllByTestResultIdWithQuestion(Long resultId); @Query( - "select new com.nexters.keyme.question.domain.internaldto.QuestionStatisticInfo(qs.question.questionId, qs.question.title, qs.question.keyword, qs.question.categoryName, avg(qs.score)) " + + "select new com.nexters.keyme.domain.question.domain.internaldto.QuestionStatisticInfo(qs.question.questionId, qs.question.title, qs.question.keyword, qs.question.categoryName, avg(qs.score)) " + "from QuestionSolved qs " + "where qs.testResult.test.testId = :testId " + "and (qs.testResult.solver.id != qs.owner.id or qs.testResult.solver.id IS NULL) " + @@ -36,13 +34,13 @@ public interface QuestionSolvedRepository extends JpaRepository findAllAssociatedQuestionStatisticsByTestId(Long testId); @Query( - "select new com.nexters.keyme.question.domain.internaldto.QuestionStatisticInfo(qs.question.questionId, qs.question.title, qs.question.keyword, qs.question.categoryName, avg(qs.score)) " + + "select new com.nexters.keyme.domain.question.domain.internaldto.QuestionStatisticInfo(qs.question.questionId, qs.question.title, qs.question.keyword, qs.question.categoryName, avg(qs.score)) " + "from QuestionSolved qs " + "where qs.question.questionId = :questionId " + "and qs.owner.id = :ownerId " + "and (qs.testResult.solver.id != :ownerId or qs.testResult.solver.id IS NULL)" ) - Optional findQuestionStatisticsByQuestionIdAndOwnerId(Long questionId, Long ownerId); + QuestionStatisticInfo findQuestionStatisticsByQuestionIdAndOwnerId(Long questionId, Long ownerId); @Query(value = "SELECT * FROM question_solved qs " + "JOIN test_result ts on ts.test_result_id = qs.test_result_id " + diff --git a/src/main/java/com/nexters/keyme/domain/question/domain/repository/QuestionSolvedRepositoryCustom.java b/src/main/java/com/nexters/keyme/domain/question/domain/repository/QuestionSolvedRepositoryCustom.java new file mode 100644 index 00000000..a467b049 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/question/domain/repository/QuestionSolvedRepositoryCustom.java @@ -0,0 +1,13 @@ +package com.nexters.keyme.domain.question.domain.repository; + +import com.nexters.keyme.domain.question.domain.model.QuestionSolved; +import com.nexters.keyme.global.dto.internal.PageInfo; + +public interface QuestionSolvedRepositoryCustom { + PageInfo findQuestionSolvedList( + Long questionId, + Long questionOwnerId, + Long cursorId, + int limit + ); +} diff --git a/src/main/java/com/nexters/keyme/question/domain/repository/QuestionSolvedRepositoryCustomImpl.java b/src/main/java/com/nexters/keyme/domain/question/domain/repository/QuestionSolvedRepositoryCustomImpl.java similarity index 83% rename from src/main/java/com/nexters/keyme/question/domain/repository/QuestionSolvedRepositoryCustomImpl.java rename to src/main/java/com/nexters/keyme/domain/question/domain/repository/QuestionSolvedRepositoryCustomImpl.java index 50bd0c18..9731f48a 100644 --- a/src/main/java/com/nexters/keyme/question/domain/repository/QuestionSolvedRepositoryCustomImpl.java +++ b/src/main/java/com/nexters/keyme/domain/question/domain/repository/QuestionSolvedRepositoryCustomImpl.java @@ -1,20 +1,15 @@ -package com.nexters.keyme.question.domain.repository; +package com.nexters.keyme.domain.question.domain.repository; -import com.nexters.keyme.common.dto.internal.PageInfo; -import com.nexters.keyme.question.domain.model.QQuestionSolved; -import com.nexters.keyme.question.domain.model.QuestionSolved; -import com.querydsl.core.BooleanBuilder; +import com.nexters.keyme.domain.question.domain.model.QuestionSolved; +import com.nexters.keyme.global.dto.internal.PageInfo; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; import java.util.List; -import static com.nexters.keyme.question.domain.model.QQuestionSolved.questionSolved; +import static com.nexters.keyme.domain.question.domain.model.QQuestionSolved.questionSolved; @Repository @RequiredArgsConstructor diff --git a/src/main/java/com/nexters/keyme/question/presentation/controller/QuestionController.java b/src/main/java/com/nexters/keyme/domain/question/presentation/controller/QuestionController.java similarity index 74% rename from src/main/java/com/nexters/keyme/question/presentation/controller/QuestionController.java rename to src/main/java/com/nexters/keyme/domain/question/presentation/controller/QuestionController.java index d14dbff1..f95f8bc9 100644 --- a/src/main/java/com/nexters/keyme/question/presentation/controller/QuestionController.java +++ b/src/main/java/com/nexters/keyme/domain/question/presentation/controller/QuestionController.java @@ -1,12 +1,14 @@ -package com.nexters.keyme.question.presentation.controller; +package com.nexters.keyme.domain.question.presentation.controller; -import com.nexters.keyme.common.dto.response.ApiResponse; -import com.nexters.keyme.common.dto.response.PageResponse; -import com.nexters.keyme.question.application.QuestionService; -import com.nexters.keyme.question.presentation.dto.request.QuestionScoreListRequest; -import com.nexters.keyme.question.presentation.dto.request.QuestionListScoreRequest; -import com.nexters.keyme.question.presentation.dto.request.QuestionStatisticRequest; -import com.nexters.keyme.question.presentation.dto.response.*; +import com.nexters.keyme.domain.question.application.QuestionService; +import com.nexters.keyme.domain.question.presentation.dto.request.QuestionListScoreRequest; +import com.nexters.keyme.domain.question.presentation.dto.request.QuestionStatisticRequest; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionResponse; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionScoreInfoResponse; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionStatisticResponse; +import com.nexters.keyme.global.dto.response.ApiResponse; +import com.nexters.keyme.global.dto.response.PageResponse; +import com.nexters.keyme.domain.question.presentation.dto.request.QuestionScoreListRequest; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/question/presentation/dto/request/QuestionListScoreRequest.java b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/request/QuestionListScoreRequest.java similarity index 89% rename from src/main/java/com/nexters/keyme/question/presentation/dto/request/QuestionListScoreRequest.java rename to src/main/java/com/nexters/keyme/domain/question/presentation/dto/request/QuestionListScoreRequest.java index c6d7b9c6..20be54d4 100644 --- a/src/main/java/com/nexters/keyme/question/presentation/dto/request/QuestionListScoreRequest.java +++ b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/request/QuestionListScoreRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.question.presentation.dto.request; +package com.nexters.keyme.domain.question.presentation.dto.request; import io.swagger.annotations.ApiModel; diff --git a/src/main/java/com/nexters/keyme/question/presentation/dto/request/QuestionScoreListRequest.java b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/request/QuestionScoreListRequest.java similarity index 72% rename from src/main/java/com/nexters/keyme/question/presentation/dto/request/QuestionScoreListRequest.java rename to src/main/java/com/nexters/keyme/domain/question/presentation/dto/request/QuestionScoreListRequest.java index 5852d9ae..842831ca 100644 --- a/src/main/java/com/nexters/keyme/question/presentation/dto/request/QuestionScoreListRequest.java +++ b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/request/QuestionScoreListRequest.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.question.presentation.dto.request; +package com.nexters.keyme.domain.question.presentation.dto.request; -import com.nexters.keyme.common.dto.request.PaginationRequest; +import com.nexters.keyme.global.dto.request.PaginationRequest; import io.swagger.annotations.ApiModel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/nexters/keyme/question/presentation/dto/request/QuestionStatisticRequest.java b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/request/QuestionStatisticRequest.java similarity index 82% rename from src/main/java/com/nexters/keyme/question/presentation/dto/request/QuestionStatisticRequest.java rename to src/main/java/com/nexters/keyme/domain/question/presentation/dto/request/QuestionStatisticRequest.java index b6d476e0..583262ae 100644 --- a/src/main/java/com/nexters/keyme/question/presentation/dto/request/QuestionStatisticRequest.java +++ b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/request/QuestionStatisticRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.question.presentation.dto.request; +package com.nexters.keyme.domain.question.presentation.dto.request; import io.swagger.annotations.ApiModel; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionCategoryResponse.java b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionCategoryResponse.java similarity index 84% rename from src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionCategoryResponse.java rename to src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionCategoryResponse.java index dc47c663..75c6b960 100644 --- a/src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionCategoryResponse.java +++ b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionCategoryResponse.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.question.presentation.dto.response; +package com.nexters.keyme.domain.question.presentation.dto.response; -import com.nexters.keyme.question.domain.enums.QuestionCategoryType; +import com.nexters.keyme.domain.question.domain.enums.QuestionCategoryType; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionResponse.java b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionResponse.java similarity index 88% rename from src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionResponse.java rename to src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionResponse.java index d9b319b8..26dd3fc1 100644 --- a/src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionResponse.java +++ b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionResponse.java @@ -1,10 +1,9 @@ -package com.nexters.keyme.question.presentation.dto.response; +package com.nexters.keyme.domain.question.presentation.dto.response; -import com.nexters.keyme.question.domain.model.Question; +import com.nexters.keyme.domain.question.domain.model.Question; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; diff --git a/src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionScoreInfoResponse.java b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionScoreInfoResponse.java similarity index 84% rename from src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionScoreInfoResponse.java rename to src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionScoreInfoResponse.java index 198c977a..c1420696 100644 --- a/src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionScoreInfoResponse.java +++ b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionScoreInfoResponse.java @@ -1,7 +1,7 @@ -package com.nexters.keyme.question.presentation.dto.response; +package com.nexters.keyme.domain.question.presentation.dto.response; -import com.nexters.keyme.question.domain.model.QuestionSolved; +import com.nexters.keyme.domain.question.domain.model.QuestionSolved; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionSolvedResponse.java b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionSolvedResponse.java similarity index 84% rename from src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionSolvedResponse.java rename to src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionSolvedResponse.java index 0278f1fb..31b3b22a 100644 --- a/src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionSolvedResponse.java +++ b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionSolvedResponse.java @@ -1,9 +1,8 @@ -package com.nexters.keyme.question.presentation.dto.response; +package com.nexters.keyme.domain.question.presentation.dto.response; -import com.nexters.keyme.question.domain.model.QuestionSolved; +import com.nexters.keyme.domain.question.domain.model.QuestionSolved; import io.swagger.annotations.ApiModel; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; diff --git a/src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionSolvedSimpleResponse.java b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionSolvedSimpleResponse.java similarity index 78% rename from src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionSolvedSimpleResponse.java rename to src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionSolvedSimpleResponse.java index 78560aa2..2d1aeb8f 100644 --- a/src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionSolvedSimpleResponse.java +++ b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionSolvedSimpleResponse.java @@ -1,7 +1,7 @@ -package com.nexters.keyme.question.presentation.dto.response; +package com.nexters.keyme.domain.question.presentation.dto.response; -import com.nexters.keyme.question.domain.model.QuestionSolved; +import com.nexters.keyme.domain.question.domain.model.QuestionSolved; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionStatisticResponse.java b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionStatisticResponse.java similarity index 80% rename from src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionStatisticResponse.java rename to src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionStatisticResponse.java index c8eaa8f9..11c366b6 100644 --- a/src/main/java/com/nexters/keyme/question/presentation/dto/response/QuestionStatisticResponse.java +++ b/src/main/java/com/nexters/keyme/domain/question/presentation/dto/response/QuestionStatisticResponse.java @@ -1,7 +1,7 @@ -package com.nexters.keyme.question.presentation.dto.response; +package com.nexters.keyme.domain.question.presentation.dto.response; -import com.nexters.keyme.question.domain.internaldto.QuestionStatisticInfo; -import com.nexters.keyme.question.domain.model.Question; +import com.nexters.keyme.domain.question.domain.internaldto.QuestionStatisticInfo; +import com.nexters.keyme.domain.question.domain.model.Question; import io.swagger.annotations.ApiModel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/nexters/keyme/domain/statistics/application/StatisticService.java b/src/main/java/com/nexters/keyme/domain/statistics/application/StatisticService.java new file mode 100644 index 00000000..0bdf662a --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/statistics/application/StatisticService.java @@ -0,0 +1,20 @@ +package com.nexters.keyme.domain.statistics.application; + +import com.nexters.keyme.domain.statistics.application.dto.ScoreInfo; +import com.nexters.keyme.domain.statistics.domain.internaldto.StatisticInfo; +import com.nexters.keyme.domain.statistics.domain.model.Statistic; +import com.nexters.keyme.domain.statistics.presentation.dto.AdditionalStatisticRequest; +import com.nexters.keyme.domain.statistics.presentation.dto.AdditionalStatisticResponse; +import com.nexters.keyme.domain.statistics.presentation.dto.request.StatisticRequest; +import com.nexters.keyme.domain.statistics.presentation.dto.response.MemberStatisticResponse; + +import java.util.List; + +public interface StatisticService { + Statistic createStatistic(StatisticInfo statisticInfo); + void addNewScores(ScoreInfo request); + + MemberStatisticResponse getMemberStatistic(long memberId, StatisticRequest request); + + List getAdditionalStatistics (long memberId, AdditionalStatisticRequest request); +} diff --git a/src/main/java/com/nexters/keyme/statistics/application/StatisticServiceImpl.java b/src/main/java/com/nexters/keyme/domain/statistics/application/StatisticServiceImpl.java similarity index 73% rename from src/main/java/com/nexters/keyme/statistics/application/StatisticServiceImpl.java rename to src/main/java/com/nexters/keyme/domain/statistics/application/StatisticServiceImpl.java index eb72637c..b1192b05 100644 --- a/src/main/java/com/nexters/keyme/statistics/application/StatisticServiceImpl.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/application/StatisticServiceImpl.java @@ -1,21 +1,23 @@ -package com.nexters.keyme.statistics.application; - -import com.nexters.keyme.common.exceptions.ResourceNotFoundException; -import com.nexters.keyme.question.domain.model.Question; -import com.nexters.keyme.question.domain.repository.QuestionRepository; -import com.nexters.keyme.statistics.application.dto.ScoreInfo; -import com.nexters.keyme.statistics.domain.internaldto.CoordinateInfo; -import com.nexters.keyme.statistics.domain.internaldto.StatisticInfo; -import com.nexters.keyme.statistics.domain.model.Statistic; -import com.nexters.keyme.statistics.domain.repository.StatisticRepository; -import com.nexters.keyme.statistics.domain.service.CoordinateConversionService; -import com.nexters.keyme.statistics.presentation.dto.AdditionalStatisticRequest; -import com.nexters.keyme.statistics.presentation.dto.AdditionalStatisticResponse; -import com.nexters.keyme.statistics.presentation.dto.request.StatisticRequest; -import com.nexters.keyme.statistics.presentation.dto.response.CoordinateResponse; -import com.nexters.keyme.statistics.presentation.dto.response.MemberStatisticResponse; -import com.nexters.keyme.statistics.presentation.dto.response.StatisticQuestionResponse; -import com.nexters.keyme.statistics.presentation.dto.response.StatisticResultResponse; +package com.nexters.keyme.domain.statistics.application; + +import com.nexters.keyme.domain.question.domain.exceptions.NotFoundQuestionException; +import com.nexters.keyme.domain.question.domain.model.Question; +import com.nexters.keyme.domain.question.domain.repository.QuestionRepository; +import com.nexters.keyme.domain.statistics.application.dto.ScoreInfo; +import com.nexters.keyme.domain.statistics.domain.exceptions.NotEnoughStatisticsException; +import com.nexters.keyme.domain.statistics.domain.exceptions.NotFoundStatisticsException; +import com.nexters.keyme.domain.statistics.domain.internaldto.CoordinateInfo; +import com.nexters.keyme.domain.statistics.domain.internaldto.StatisticInfo; +import com.nexters.keyme.domain.statistics.domain.model.Statistic; +import com.nexters.keyme.domain.statistics.domain.repository.StatisticRepository; +import com.nexters.keyme.domain.statistics.domain.service.CoordinateConversionService; +import com.nexters.keyme.domain.statistics.presentation.dto.AdditionalStatisticRequest; +import com.nexters.keyme.domain.statistics.presentation.dto.AdditionalStatisticResponse; +import com.nexters.keyme.domain.statistics.presentation.dto.request.StatisticRequest; +import com.nexters.keyme.domain.statistics.presentation.dto.response.CoordinateResponse; +import com.nexters.keyme.domain.statistics.presentation.dto.response.MemberStatisticResponse; +import com.nexters.keyme.domain.statistics.presentation.dto.response.StatisticQuestionResponse; +import com.nexters.keyme.domain.statistics.presentation.dto.response.StatisticResultResponse; import lombok.RequiredArgsConstructor; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -73,7 +75,7 @@ public MemberStatisticResponse getMemberStatistic(long memberId, StatisticReques } if (checkStatisticExists(statistics)) { - throw new ResourceNotFoundException(); + throw new NotEnoughStatisticsException(); } statistics.sort(getStatisticComparator()); @@ -87,7 +89,7 @@ public MemberStatisticResponse getMemberStatistic(long memberId, StatisticReques CoordinateInfo coordinateInfo = coordinates.get(i); Question question = questionRepository.findById(statistic.getQuestionId()) - .orElseThrow(ResourceNotFoundException::new); + .orElseThrow(NotFoundQuestionException::new); results.add(new StatisticResultResponse(new StatisticQuestionResponse(question, statistic.getOwnerScore(), statistic.getSolverAvgScore()), new CoordinateResponse(coordinateInfo))); } @@ -128,7 +130,7 @@ public List getAdditionalStatistics (long memberId, return statistics.stream() .map((statistic) -> { Question question = questionRepository.findById(statistic.getQuestionId()) - .orElseThrow(ResourceNotFoundException::new); + .orElseThrow(NotFoundQuestionException::new); return new AdditionalStatisticResponse(statistic.getId(), question.getKeyword(), question.getCategoryName().getColor(), question.getCategoryName().getImageUrl(), statistic.getSolverAvgScore()); }) .collect(Collectors.toList()); @@ -140,9 +142,10 @@ private Statistic getCursorStatistic(long cursor) { .id(0) .solverAvgScore(Double.MAX_VALUE) .build(); + } return statisticRepository.findById(cursor) - .orElseThrow(ResourceNotFoundException::new); + .orElseThrow(NotFoundStatisticsException::new); } } diff --git a/src/main/java/com/nexters/keyme/statistics/application/dto/ScoreInfo.java b/src/main/java/com/nexters/keyme/domain/statistics/application/dto/ScoreInfo.java similarity index 78% rename from src/main/java/com/nexters/keyme/statistics/application/dto/ScoreInfo.java rename to src/main/java/com/nexters/keyme/domain/statistics/application/dto/ScoreInfo.java index d0652c4c..017f4bef 100644 --- a/src/main/java/com/nexters/keyme/statistics/application/dto/ScoreInfo.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/application/dto/ScoreInfo.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.statistics.application.dto; +package com.nexters.keyme.domain.statistics.application.dto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/domain/statistics/domain/exceptions/NotEnoughStatisticsException.java b/src/main/java/com/nexters/keyme/domain/statistics/domain/exceptions/NotEnoughStatisticsException.java new file mode 100644 index 00000000..de2cd8c2 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/statistics/domain/exceptions/NotEnoughStatisticsException.java @@ -0,0 +1,10 @@ +package com.nexters.keyme.domain.statistics.domain.exceptions; + +import com.nexters.keyme.domain.statistics.domain.exceptions.code.StatisticsErrorCode; +import com.nexters.keyme.global.exceptions.KeymeBadRequestException; + +public class NotEnoughStatisticsException extends KeymeBadRequestException { + public NotEnoughStatisticsException() { + super(StatisticsErrorCode.NOT_ENOUGH_STATISTICS.getMessage(), StatisticsErrorCode.NOT_ENOUGH_STATISTICS.getCode()); + } +} diff --git a/src/main/java/com/nexters/keyme/domain/statistics/domain/exceptions/NotFoundStatisticsException.java b/src/main/java/com/nexters/keyme/domain/statistics/domain/exceptions/NotFoundStatisticsException.java new file mode 100644 index 00000000..2d40a958 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/statistics/domain/exceptions/NotFoundStatisticsException.java @@ -0,0 +1,10 @@ +package com.nexters.keyme.domain.statistics.domain.exceptions; + +import com.nexters.keyme.domain.statistics.domain.exceptions.code.StatisticsErrorCode; +import com.nexters.keyme.global.exceptions.KeymeNotFoundException; + +public class NotFoundStatisticsException extends KeymeNotFoundException { + public NotFoundStatisticsException() { + super(StatisticsErrorCode.NOT_FOUND_STATISTICS.getMessage(), StatisticsErrorCode.NOT_FOUND_STATISTICS.getCode()); + } +} diff --git a/src/main/java/com/nexters/keyme/domain/statistics/domain/exceptions/code/StatisticsErrorCode.java b/src/main/java/com/nexters/keyme/domain/statistics/domain/exceptions/code/StatisticsErrorCode.java new file mode 100644 index 00000000..e494c6c8 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/statistics/domain/exceptions/code/StatisticsErrorCode.java @@ -0,0 +1,14 @@ +package com.nexters.keyme.domain.statistics.domain.exceptions.code; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum StatisticsErrorCode { + NOT_ENOUGH_STATISTICS(400, "통계 정보가 충분하지 않습니다."), + NOT_FOUND_STATISTICS(404, "통계정보를 찾을 수 없습니다."); + + private final int code; + private final String message; +} diff --git a/src/main/java/com/nexters/keyme/statistics/domain/internaldto/CoordinateInfo.java b/src/main/java/com/nexters/keyme/domain/statistics/domain/internaldto/CoordinateInfo.java similarity index 75% rename from src/main/java/com/nexters/keyme/statistics/domain/internaldto/CoordinateInfo.java rename to src/main/java/com/nexters/keyme/domain/statistics/domain/internaldto/CoordinateInfo.java index d4fd3a2a..06b88d23 100644 --- a/src/main/java/com/nexters/keyme/statistics/domain/internaldto/CoordinateInfo.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/domain/internaldto/CoordinateInfo.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.statistics.domain.internaldto; +package com.nexters.keyme.domain.statistics.domain.internaldto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/statistics/domain/internaldto/StatisticInfo.java b/src/main/java/com/nexters/keyme/domain/statistics/domain/internaldto/StatisticInfo.java similarity index 75% rename from src/main/java/com/nexters/keyme/statistics/domain/internaldto/StatisticInfo.java rename to src/main/java/com/nexters/keyme/domain/statistics/domain/internaldto/StatisticInfo.java index 62e6e9ae..0541ad0c 100644 --- a/src/main/java/com/nexters/keyme/statistics/domain/internaldto/StatisticInfo.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/domain/internaldto/StatisticInfo.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.statistics.domain.internaldto; +package com.nexters.keyme.domain.statistics.domain.internaldto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/statistics/domain/model/Statistic.java b/src/main/java/com/nexters/keyme/domain/statistics/domain/model/Statistic.java similarity index 92% rename from src/main/java/com/nexters/keyme/statistics/domain/model/Statistic.java rename to src/main/java/com/nexters/keyme/domain/statistics/domain/model/Statistic.java index dc3161f1..be599bba 100644 --- a/src/main/java/com/nexters/keyme/statistics/domain/model/Statistic.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/domain/model/Statistic.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.statistics.domain.model; +package com.nexters.keyme.domain.statistics.domain.model; -import com.nexters.keyme.common.model.BaseTimeEntity; +import com.nexters.keyme.global.model.BaseTimeEntity; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/statistics/domain/repository/StatisticRepository.java b/src/main/java/com/nexters/keyme/domain/statistics/domain/repository/StatisticRepository.java similarity index 88% rename from src/main/java/com/nexters/keyme/statistics/domain/repository/StatisticRepository.java rename to src/main/java/com/nexters/keyme/domain/statistics/domain/repository/StatisticRepository.java index 410e614b..c2a03053 100644 --- a/src/main/java/com/nexters/keyme/statistics/domain/repository/StatisticRepository.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/domain/repository/StatisticRepository.java @@ -1,12 +1,10 @@ -package com.nexters.keyme.statistics.domain.repository; +package com.nexters.keyme.domain.statistics.domain.repository; -import com.nexters.keyme.statistics.domain.model.Statistic; +import com.nexters.keyme.domain.statistics.domain.model.Statistic; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Lock; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import javax.persistence.LockModeType; import java.util.List; import java.util.Optional; diff --git a/src/main/java/com/nexters/keyme/domain/statistics/domain/service/CoordinateConversionService.java b/src/main/java/com/nexters/keyme/domain/statistics/domain/service/CoordinateConversionService.java new file mode 100644 index 00000000..89b4b29b --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/statistics/domain/service/CoordinateConversionService.java @@ -0,0 +1,10 @@ +package com.nexters.keyme.domain.statistics.domain.service; + +import com.nexters.keyme.domain.statistics.domain.internaldto.CoordinateInfo; +import com.nexters.keyme.domain.statistics.domain.model.Statistic; + +import java.util.List; + +public interface CoordinateConversionService { + List convertFrom(List statistics); +} diff --git a/src/main/java/com/nexters/keyme/statistics/infrastcurture/PythonCoordinateConversionService.java b/src/main/java/com/nexters/keyme/domain/statistics/infrastcurture/PythonCoordinateConversionService.java similarity index 76% rename from src/main/java/com/nexters/keyme/statistics/infrastcurture/PythonCoordinateConversionService.java rename to src/main/java/com/nexters/keyme/domain/statistics/infrastcurture/PythonCoordinateConversionService.java index 74f2a083..478f0b66 100644 --- a/src/main/java/com/nexters/keyme/statistics/infrastcurture/PythonCoordinateConversionService.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/infrastcurture/PythonCoordinateConversionService.java @@ -1,10 +1,10 @@ -package com.nexters.keyme.statistics.infrastcurture; +package com.nexters.keyme.domain.statistics.infrastcurture; -import com.nexters.keyme.statistics.domain.internaldto.CoordinateInfo; -import com.nexters.keyme.statistics.domain.model.Statistic; -import com.nexters.keyme.statistics.domain.service.CoordinateConversionService; -import com.nexters.keyme.statistics.infrastcurture.dto.CoordinateRequest; -import com.nexters.keyme.statistics.infrastcurture.dto.CoordinateResponse; +import com.nexters.keyme.domain.statistics.domain.internaldto.CoordinateInfo; +import com.nexters.keyme.domain.statistics.domain.model.Statistic; +import com.nexters.keyme.domain.statistics.domain.service.CoordinateConversionService; +import com.nexters.keyme.domain.statistics.infrastcurture.dto.CoordinateRequest; +import com.nexters.keyme.domain.statistics.infrastcurture.dto.CoordinateResponse; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/nexters/keyme/statistics/infrastcurture/dto/CircleReponse.java b/src/main/java/com/nexters/keyme/domain/statistics/infrastcurture/dto/CircleReponse.java similarity index 78% rename from src/main/java/com/nexters/keyme/statistics/infrastcurture/dto/CircleReponse.java rename to src/main/java/com/nexters/keyme/domain/statistics/infrastcurture/dto/CircleReponse.java index 553bd69b..ede8e960 100644 --- a/src/main/java/com/nexters/keyme/statistics/infrastcurture/dto/CircleReponse.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/infrastcurture/dto/CircleReponse.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.statistics.infrastcurture.dto; +package com.nexters.keyme.domain.statistics.infrastcurture.dto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/statistics/infrastcurture/dto/CoordinateRequest.java b/src/main/java/com/nexters/keyme/domain/statistics/infrastcurture/dto/CoordinateRequest.java similarity index 76% rename from src/main/java/com/nexters/keyme/statistics/infrastcurture/dto/CoordinateRequest.java rename to src/main/java/com/nexters/keyme/domain/statistics/infrastcurture/dto/CoordinateRequest.java index cb2233af..26bb9fea 100644 --- a/src/main/java/com/nexters/keyme/statistics/infrastcurture/dto/CoordinateRequest.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/infrastcurture/dto/CoordinateRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.statistics.infrastcurture.dto; +package com.nexters.keyme.domain.statistics.infrastcurture.dto; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/statistics/infrastcurture/dto/CoordinateResponse.java b/src/main/java/com/nexters/keyme/domain/statistics/infrastcurture/dto/CoordinateResponse.java similarity index 80% rename from src/main/java/com/nexters/keyme/statistics/infrastcurture/dto/CoordinateResponse.java rename to src/main/java/com/nexters/keyme/domain/statistics/infrastcurture/dto/CoordinateResponse.java index 0d43dff3..ce89534e 100644 --- a/src/main/java/com/nexters/keyme/statistics/infrastcurture/dto/CoordinateResponse.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/infrastcurture/dto/CoordinateResponse.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.statistics.infrastcurture.dto; +package com.nexters.keyme.domain.statistics.infrastcurture.dto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/statistics/presentation/controller/StatisticController.java b/src/main/java/com/nexters/keyme/domain/statistics/presentation/controller/StatisticController.java similarity index 75% rename from src/main/java/com/nexters/keyme/statistics/presentation/controller/StatisticController.java rename to src/main/java/com/nexters/keyme/domain/statistics/presentation/controller/StatisticController.java index 64320e7c..56189b16 100644 --- a/src/main/java/com/nexters/keyme/statistics/presentation/controller/StatisticController.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/presentation/controller/StatisticController.java @@ -1,11 +1,11 @@ -package com.nexters.keyme.statistics.presentation.controller; +package com.nexters.keyme.domain.statistics.presentation.controller; -import com.nexters.keyme.common.dto.response.ApiResponse; -import com.nexters.keyme.statistics.application.StatisticService; -import com.nexters.keyme.statistics.presentation.dto.AdditionalStatisticRequest; -import com.nexters.keyme.statistics.presentation.dto.AdditionalStatisticResponse; -import com.nexters.keyme.statistics.presentation.dto.request.StatisticRequest; -import com.nexters.keyme.statistics.presentation.dto.response.MemberStatisticResponse; +import com.nexters.keyme.domain.statistics.application.StatisticService; +import com.nexters.keyme.domain.statistics.presentation.dto.AdditionalStatisticResponse; +import com.nexters.keyme.domain.statistics.presentation.dto.request.StatisticRequest; +import com.nexters.keyme.global.dto.response.ApiResponse; +import com.nexters.keyme.domain.statistics.presentation.dto.AdditionalStatisticRequest; +import com.nexters.keyme.domain.statistics.presentation.dto.response.MemberStatisticResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.v3.oas.annotations.security.SecurityRequirement; @@ -17,7 +17,7 @@ import java.util.List; -import static com.nexters.keyme.common.config.SwaggerConfig.SWAGGER_AUTHORIZATION_SCHEME; +import static com.nexters.keyme.global.config.SwaggerConfig.SWAGGER_AUTHORIZATION_SCHEME; @RestController @RequiredArgsConstructor diff --git a/src/main/java/com/nexters/keyme/statistics/presentation/dto/AdditionalStatisticRequest.java b/src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/AdditionalStatisticRequest.java similarity index 88% rename from src/main/java/com/nexters/keyme/statistics/presentation/dto/AdditionalStatisticRequest.java rename to src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/AdditionalStatisticRequest.java index a83a6660..8509e44c 100644 --- a/src/main/java/com/nexters/keyme/statistics/presentation/dto/AdditionalStatisticRequest.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/AdditionalStatisticRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.statistics.presentation.dto; +package com.nexters.keyme.domain.statistics.presentation.dto; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/statistics/presentation/dto/AdditionalStatisticResponse.java b/src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/AdditionalStatisticResponse.java similarity index 92% rename from src/main/java/com/nexters/keyme/statistics/presentation/dto/AdditionalStatisticResponse.java rename to src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/AdditionalStatisticResponse.java index 6564f5d7..d48225cd 100644 --- a/src/main/java/com/nexters/keyme/statistics/presentation/dto/AdditionalStatisticResponse.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/AdditionalStatisticResponse.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.statistics.presentation.dto; +package com.nexters.keyme.domain.statistics.presentation.dto; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/statistics/presentation/dto/request/StatisticRequest.java b/src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/request/StatisticRequest.java similarity index 89% rename from src/main/java/com/nexters/keyme/statistics/presentation/dto/request/StatisticRequest.java rename to src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/request/StatisticRequest.java index 0903ec32..7ab110a7 100644 --- a/src/main/java/com/nexters/keyme/statistics/presentation/dto/request/StatisticRequest.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/request/StatisticRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.statistics.presentation.dto.request; +package com.nexters.keyme.domain.statistics.presentation.dto.request; import com.fasterxml.jackson.annotation.JsonCreator; import io.swagger.annotations.ApiModelProperty; diff --git a/src/main/java/com/nexters/keyme/statistics/presentation/dto/response/CoordinateResponse.java b/src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/response/CoordinateResponse.java similarity index 81% rename from src/main/java/com/nexters/keyme/statistics/presentation/dto/response/CoordinateResponse.java rename to src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/response/CoordinateResponse.java index af615e72..b734d49d 100644 --- a/src/main/java/com/nexters/keyme/statistics/presentation/dto/response/CoordinateResponse.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/response/CoordinateResponse.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.statistics.presentation.dto.response; +package com.nexters.keyme.domain.statistics.presentation.dto.response; -import com.nexters.keyme.statistics.domain.internaldto.CoordinateInfo; +import com.nexters.keyme.domain.statistics.domain.internaldto.CoordinateInfo; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/statistics/presentation/dto/response/MemberStatisticResponse.java b/src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/response/MemberStatisticResponse.java similarity index 84% rename from src/main/java/com/nexters/keyme/statistics/presentation/dto/response/MemberStatisticResponse.java rename to src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/response/MemberStatisticResponse.java index 2647b4d4..f5a3073e 100644 --- a/src/main/java/com/nexters/keyme/statistics/presentation/dto/response/MemberStatisticResponse.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/response/MemberStatisticResponse.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.statistics.presentation.dto.response; +package com.nexters.keyme.domain.statistics.presentation.dto.response; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/statistics/presentation/dto/response/StatisticQuestionResponse.java b/src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/response/StatisticQuestionResponse.java similarity index 70% rename from src/main/java/com/nexters/keyme/statistics/presentation/dto/response/StatisticQuestionResponse.java rename to src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/response/StatisticQuestionResponse.java index c1b30700..96dd2be8 100644 --- a/src/main/java/com/nexters/keyme/statistics/presentation/dto/response/StatisticQuestionResponse.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/response/StatisticQuestionResponse.java @@ -1,9 +1,9 @@ -package com.nexters.keyme.statistics.presentation.dto.response; +package com.nexters.keyme.domain.statistics.presentation.dto.response; -import com.nexters.keyme.question.domain.internaldto.QuestionStatisticInfo; -import com.nexters.keyme.question.domain.model.Question; -import com.nexters.keyme.question.presentation.dto.response.QuestionCategoryResponse; -import com.nexters.keyme.question.presentation.dto.response.QuestionResponse; +import com.nexters.keyme.domain.question.domain.internaldto.QuestionStatisticInfo; +import com.nexters.keyme.domain.question.domain.model.Question; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionCategoryResponse; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionResponse; import io.swagger.annotations.ApiModel; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/nexters/keyme/statistics/presentation/dto/response/StatisticResultResponse.java b/src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/response/StatisticResultResponse.java similarity index 85% rename from src/main/java/com/nexters/keyme/statistics/presentation/dto/response/StatisticResultResponse.java rename to src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/response/StatisticResultResponse.java index 2b65c439..5d7e55c8 100644 --- a/src/main/java/com/nexters/keyme/statistics/presentation/dto/response/StatisticResultResponse.java +++ b/src/main/java/com/nexters/keyme/domain/statistics/presentation/dto/response/StatisticResultResponse.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.statistics.presentation.dto.response; +package com.nexters.keyme.domain.statistics.presentation.dto.response; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/test/application/TestResultService.java b/src/main/java/com/nexters/keyme/domain/test/application/TestResultService.java similarity index 67% rename from src/main/java/com/nexters/keyme/test/application/TestResultService.java rename to src/main/java/com/nexters/keyme/domain/test/application/TestResultService.java index f96919c9..13d16a1b 100644 --- a/src/main/java/com/nexters/keyme/test/application/TestResultService.java +++ b/src/main/java/com/nexters/keyme/domain/test/application/TestResultService.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.test.application; +package com.nexters.keyme.domain.test.application; public interface TestResultService { void injectTestResultToUser(Long memberId, String resultCode); diff --git a/src/main/java/com/nexters/keyme/test/application/TestResultServiceImpl.java b/src/main/java/com/nexters/keyme/domain/test/application/TestResultServiceImpl.java similarity index 60% rename from src/main/java/com/nexters/keyme/test/application/TestResultServiceImpl.java rename to src/main/java/com/nexters/keyme/domain/test/application/TestResultServiceImpl.java index eeed3f87..77a656bc 100644 --- a/src/main/java/com/nexters/keyme/test/application/TestResultServiceImpl.java +++ b/src/main/java/com/nexters/keyme/domain/test/application/TestResultServiceImpl.java @@ -1,18 +1,16 @@ -package com.nexters.keyme.test.application; - -import com.nexters.keyme.common.exceptions.ResourceAlreadyExistsException; -import com.nexters.keyme.common.exceptions.ResourceNotFoundException; -import com.nexters.keyme.member.domain.model.MemberEntity; -import com.nexters.keyme.member.domain.repository.MemberRepository; -import com.nexters.keyme.question.domain.model.QuestionSolved; -import com.nexters.keyme.question.domain.repository.QuestionSolvedRepository; -import com.nexters.keyme.question.presentation.dto.response.QuestionSolvedResponse; -import com.nexters.keyme.test.domain.model.Test; -import com.nexters.keyme.test.domain.model.TestResult; -import com.nexters.keyme.test.domain.model.TestResultCode; -import com.nexters.keyme.test.domain.repository.TestRepository; -import com.nexters.keyme.test.domain.repository.TestResultCodeRepository; -import com.nexters.keyme.test.domain.repository.TestResultRepository; +package com.nexters.keyme.domain.test.application; + +import com.nexters.keyme.domain.member.domain.exceptions.NotFoundMemberException; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.question.domain.model.QuestionSolved; +import com.nexters.keyme.domain.question.domain.repository.QuestionSolvedRepository; +import com.nexters.keyme.domain.member.domain.repository.MemberRepository; +import com.nexters.keyme.domain.test.domain.exceptions.AlreadyExistTestResultOwnerException; +import com.nexters.keyme.domain.test.domain.exceptions.NotFoundTestResultCodeException; +import com.nexters.keyme.domain.test.domain.model.TestResult; +import com.nexters.keyme.domain.test.domain.model.TestResultCode; +import com.nexters.keyme.domain.test.domain.repository.TestResultCodeRepository; +import com.nexters.keyme.domain.test.domain.repository.TestResultRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -33,11 +31,11 @@ public class TestResultServiceImpl implements TestResultService { @Override public void injectTestResultToUser(Long memberId, String resultCode) { // 체킹 - member 확인, resultCode확인, TestResult 존재확인 - MemberEntity member = memberRepository.findById(memberId).orElseThrow(ResourceNotFoundException::new); - TestResultCode testResultCode = testResultCodeRepository.findById(resultCode).orElseThrow(ResourceNotFoundException::new); + MemberEntity member = memberRepository.findById(memberId).orElseThrow(NotFoundMemberException::new); + TestResultCode testResultCode = testResultCodeRepository.findById(resultCode).orElseThrow(NotFoundTestResultCodeException::new); TestResult testResult = testResultRepository.findById(testResultCode.getResultId()) .filter(ts -> ts.getSolver() == null) - .orElseThrow(ResourceAlreadyExistsException::new); + .orElseThrow(AlreadyExistTestResultOwnerException::new); // 유저가 해당 test를 이미 풀었을 경우 Optional test = testResultRepository.findByTestAndSolver(testResult.getTest(), member); diff --git a/src/main/java/com/nexters/keyme/test/application/TestService.java b/src/main/java/com/nexters/keyme/domain/test/application/TestService.java similarity index 67% rename from src/main/java/com/nexters/keyme/test/application/TestService.java rename to src/main/java/com/nexters/keyme/domain/test/application/TestService.java index c17dc303..f48bbfa5 100644 --- a/src/main/java/com/nexters/keyme/test/application/TestService.java +++ b/src/main/java/com/nexters/keyme/domain/test/application/TestService.java @@ -1,8 +1,8 @@ -package com.nexters.keyme.test.application; +package com.nexters.keyme.domain.test.application; -import com.nexters.keyme.test.presentation.dto.request.TestListRequest; -import com.nexters.keyme.test.presentation.dto.request.TestSubmissionRequest; -import com.nexters.keyme.test.presentation.dto.response.*; +import com.nexters.keyme.domain.test.presentation.dto.request.TestListRequest; +import com.nexters.keyme.domain.test.presentation.dto.request.TestSubmissionRequest; +import com.nexters.keyme.domain.test.presentation.dto.response.*; import java.util.List; diff --git a/src/main/java/com/nexters/keyme/test/application/TestServiceImpl.java b/src/main/java/com/nexters/keyme/domain/test/application/TestServiceImpl.java similarity index 77% rename from src/main/java/com/nexters/keyme/test/application/TestServiceImpl.java rename to src/main/java/com/nexters/keyme/domain/test/application/TestServiceImpl.java index 34397f2f..cb4fdd29 100644 --- a/src/main/java/com/nexters/keyme/test/application/TestServiceImpl.java +++ b/src/main/java/com/nexters/keyme/domain/test/application/TestServiceImpl.java @@ -1,33 +1,35 @@ -package com.nexters.keyme.test.application; - -import com.nexters.keyme.common.exceptions.InvalidRequestException; -import com.nexters.keyme.common.exceptions.ResourceAlreadyExistsException; -import com.nexters.keyme.common.exceptions.ResourceNotFoundException; -import com.nexters.keyme.member.domain.model.MemberEntity; -import com.nexters.keyme.member.domain.repository.MemberRepository; -import com.nexters.keyme.question.domain.internaldto.QuestionStatisticInfo; -import com.nexters.keyme.question.domain.model.Question; -import com.nexters.keyme.question.domain.model.QuestionBundle; -import com.nexters.keyme.question.domain.model.QuestionBundleId; -import com.nexters.keyme.question.domain.model.QuestionSolved; -import com.nexters.keyme.question.domain.repository.QuestionBundleRepository; -import com.nexters.keyme.question.domain.repository.QuestionRepository; -import com.nexters.keyme.question.domain.repository.QuestionSolvedRepository; -import com.nexters.keyme.question.presentation.dto.response.QuestionResponse; -import com.nexters.keyme.question.presentation.dto.response.QuestionSolvedResponse; -import com.nexters.keyme.question.presentation.dto.response.QuestionStatisticResponse; -import com.nexters.keyme.test.domain.helper.TestDataProvider; -import com.nexters.keyme.test.domain.helper.TestResultCodeProvider; -import com.nexters.keyme.test.domain.internaldto.TestResultStatisticInfo; -import com.nexters.keyme.test.domain.model.Test; -import com.nexters.keyme.test.domain.model.TestResult; -import com.nexters.keyme.test.domain.repository.TestRepository; -import com.nexters.keyme.test.domain.repository.TestResultRepository; -import com.nexters.keyme.test.events.AddStatisticEvent; -import com.nexters.keyme.test.events.SendNotificationEvent; -import com.nexters.keyme.test.presentation.dto.request.TestListRequest; -import com.nexters.keyme.test.presentation.dto.request.TestSubmissionRequest; -import com.nexters.keyme.test.presentation.dto.response.*; +package com.nexters.keyme.domain.test.application; + +import com.nexters.keyme.domain.member.domain.exceptions.NotFoundMemberException; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.question.domain.internaldto.QuestionStatisticInfo; +import com.nexters.keyme.domain.question.domain.model.Question; +import com.nexters.keyme.domain.question.domain.model.QuestionBundle; +import com.nexters.keyme.domain.question.domain.model.QuestionBundleId; +import com.nexters.keyme.domain.question.domain.model.QuestionSolved; +import com.nexters.keyme.domain.question.domain.repository.QuestionBundleRepository; +import com.nexters.keyme.domain.question.domain.repository.QuestionRepository; +import com.nexters.keyme.domain.question.domain.repository.QuestionSolvedRepository; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionResponse; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionSolvedResponse; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionStatisticResponse; +import com.nexters.keyme.domain.test.domain.exceptions.AlreadyExistTestResultException; +import com.nexters.keyme.domain.test.domain.exceptions.InvalidDailyTestException; +import com.nexters.keyme.domain.test.domain.exceptions.NotFoundTestException; +import com.nexters.keyme.domain.test.domain.exceptions.NotFoundTestResultException; +import com.nexters.keyme.domain.test.events.SendNotificationEvent; +import com.nexters.keyme.domain.test.presentation.dto.request.TestListRequest; +import com.nexters.keyme.domain.test.presentation.dto.request.TestSubmissionRequest; +import com.nexters.keyme.domain.test.presentation.dto.response.*; +import com.nexters.keyme.domain.member.domain.repository.MemberRepository; +import com.nexters.keyme.domain.test.domain.helper.TestDataProvider; +import com.nexters.keyme.domain.test.domain.helper.TestResultCodeProvider; +import com.nexters.keyme.domain.test.domain.internaldto.TestResultStatisticInfo; +import com.nexters.keyme.domain.test.domain.model.Test; +import com.nexters.keyme.domain.test.domain.model.TestResult; +import com.nexters.keyme.domain.test.domain.repository.TestRepository; +import com.nexters.keyme.domain.test.domain.repository.TestResultRepository; +import com.nexters.keyme.domain.test.events.AddStatisticEvent; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.ApplicationEventPublisher; @@ -59,7 +61,7 @@ public class TestServiceImpl implements TestService { @Transactional @Override public TestDetailResponse getOrCreateOnboardingTest(Long memberId) { - MemberEntity member = memberRepository.findById(memberId).orElseThrow(ResourceNotFoundException::new); + MemberEntity member = memberRepository.findById(memberId).orElseThrow(NotFoundMemberException::new); Long existOnboardingId = testRepository.findFirstByMemberAndIsOnboardingOrderByCreatedAtDesc(member, true) .map(test -> test.getTestId()) .orElse(null); @@ -93,7 +95,7 @@ public TestDetailResponse getOrCreateOnboardingTest(Long memberId) { @Transactional @Override public TestDetailResponse getOrCreateDailyTest(Long memberId) { - MemberEntity member = memberRepository.findById(memberId).orElseThrow(ResourceNotFoundException::new); + MemberEntity member = memberRepository.findById(memberId).orElseThrow(NotFoundMemberException::new); // 최근 test가 존재하며, 해당 test를 풀지 않았거나 오늘 풀었으면 기존 테스트 리턴 // FIXME : 체킹로직 메서드로 빼기 @@ -116,8 +118,7 @@ public TestDetailResponse getOrCreateDailyTest(Long memberId) { // 온보딩 안풀어도 Daily 호출할 수 있도록 List questionSolvedList = questionSolvedRepository.findFirstLastestQuestionSolved(memberId, memberId); if (questionSolvedList.isEmpty()) { - log.error("온보딩 문제를 풀기 전 데일리 문제 호출"); - throw new InvalidRequestException(); + throw new InvalidDailyTestException(); } Long lastSolvedQuestionId = questionSolvedList.get(0).getQuestion().getQuestionId(); @@ -153,13 +154,10 @@ public SingleTestStatisticsResponse getTestStatistics(Long memberId, Long testId testRepository.findById(testId) .map(test -> test.getMember().getId()) .filter(testOwnerId -> Objects.equals(testOwnerId, memberId)) - .orElseThrow(ResourceNotFoundException::new); + .orElseThrow(NotFoundTestException::new); // FIXME : 두 통계 쿼리 병렬 수행 필요 - TestResultStatisticInfo testResultStatisticInfo = testResultRepository.findStatisticsByTestId(testId).orElseThrow(ResourceNotFoundException::new); - if (testResultStatisticInfo.getSolvedCount() == null || testResultStatisticInfo.getSolvedCount() == 0) { - throw new InvalidRequestException(); - } + TestResultStatisticInfo testResultStatisticInfo = testResultRepository.findStatisticsByTestId(testId); List questionStatisticInfoList = questionSolvedRepository.findAllAssociatedQuestionStatisticsByTestId(testId); return SingleTestStatisticsResponse.builder() @@ -181,17 +179,16 @@ public List getTestList(Long memberId, TestListRequest request @Transactional @Override public TestSubmitResponse createTestResult(Long solverId, Long testId, TestSubmissionRequest submitInfo) { - Test test = testRepository.findById(testId).orElseThrow(ResourceNotFoundException::new); + Test test = testRepository.findById(testId).orElseThrow(NotFoundTestException::new); MemberEntity member = null; // FIXME : TestResult 이미 존재하는지 확인하는 로직 domain service로 분리 // 익명유저가 아닌경우에만 if (solverId != null) { - member = memberRepository.findById(solverId).orElseThrow(ResourceNotFoundException::new); + member = memberRepository.findById(solverId).orElseThrow(NotFoundMemberException::new); Optional existTestResultOpt = testResultRepository.findByTestAndSolver(test, member); if (existTestResultOpt.isPresent()) { - log.error("Client Error : Test 결과가 이미 존재합니다."); - throw new ResourceAlreadyExistsException(); + throw new AlreadyExistTestResultException(); } } @@ -235,7 +232,7 @@ public TestSubmitResponse createTestResult(Long solverId, Long testId, TestSubmi @Override public TestResultResponse getTestResult(Long resultId) { TestResult testResult = testResultRepository.findById(resultId) - .orElseThrow(ResourceNotFoundException::new); + .orElseThrow(NotFoundTestResultException::new); List questionSolvedList = questionSolvedRepository.findAllByTestResultIdWithQuestion(resultId); diff --git a/src/main/java/com/nexters/keyme/test/domain/enums/TestListType.java b/src/main/java/com/nexters/keyme/domain/test/domain/enums/TestListType.java similarity index 75% rename from src/main/java/com/nexters/keyme/test/domain/enums/TestListType.java rename to src/main/java/com/nexters/keyme/domain/test/domain/enums/TestListType.java index b508d071..40d753e3 100644 --- a/src/main/java/com/nexters/keyme/test/domain/enums/TestListType.java +++ b/src/main/java/com/nexters/keyme/domain/test/domain/enums/TestListType.java @@ -1,9 +1,7 @@ -package com.nexters.keyme.test.domain.enums; +package com.nexters.keyme.domain.test.domain.enums; import com.fasterxml.jackson.annotation.JsonCreator; -import java.util.stream.Stream; - public enum TestListType { SOLVED, UNSOLVED, MYSOLVED; diff --git a/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/AlreadyExistTestResultException.java b/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/AlreadyExistTestResultException.java new file mode 100644 index 00000000..6b0321a2 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/AlreadyExistTestResultException.java @@ -0,0 +1,10 @@ +package com.nexters.keyme.domain.test.domain.exceptions; + +import com.nexters.keyme.domain.test.domain.exceptions.code.TestErrorCode; +import com.nexters.keyme.global.exceptions.KeymeBadRequestException; + +public class AlreadyExistTestResultException extends KeymeBadRequestException { + public AlreadyExistTestResultException() { + super(TestErrorCode.ALREADY_EXIST_TEST_RESULT.getMessage(), TestErrorCode.ALREADY_EXIST_TEST_RESULT.getCode()); + } +} \ No newline at end of file diff --git a/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/AlreadyExistTestResultOwnerException.java b/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/AlreadyExistTestResultOwnerException.java new file mode 100644 index 00000000..8d31c6c4 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/AlreadyExistTestResultOwnerException.java @@ -0,0 +1,10 @@ +package com.nexters.keyme.domain.test.domain.exceptions; + +import com.nexters.keyme.domain.test.domain.exceptions.code.TestErrorCode; +import com.nexters.keyme.global.exceptions.KeymeBadRequestException; + +public class AlreadyExistTestResultOwnerException extends KeymeBadRequestException { + public AlreadyExistTestResultOwnerException() { + super(TestErrorCode.ALREADY_EXIST_TEST_RESULT_OWNER.getMessage(), TestErrorCode.ALREADY_EXIST_TEST_RESULT_OWNER.getCode()); + } +} diff --git a/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/InvalidDailyTestException.java b/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/InvalidDailyTestException.java new file mode 100644 index 00000000..fc167ad3 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/InvalidDailyTestException.java @@ -0,0 +1,10 @@ +package com.nexters.keyme.domain.test.domain.exceptions; + +import com.nexters.keyme.domain.test.domain.exceptions.code.TestErrorCode; +import com.nexters.keyme.global.exceptions.KeymeBadRequestException; + +public class InvalidDailyTestException extends KeymeBadRequestException { + public InvalidDailyTestException() { + super(TestErrorCode.INVALID_DAILY_TEST.getMessage(), TestErrorCode.INVALID_DAILY_TEST.getCode()); + } +} diff --git a/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/NotFoundTestException.java b/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/NotFoundTestException.java new file mode 100644 index 00000000..8e2499cf --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/NotFoundTestException.java @@ -0,0 +1,10 @@ +package com.nexters.keyme.domain.test.domain.exceptions; + +import com.nexters.keyme.domain.test.domain.exceptions.code.TestErrorCode; +import com.nexters.keyme.global.exceptions.KeymeNotFoundException; + +public class NotFoundTestException extends KeymeNotFoundException { + public NotFoundTestException() { + super(TestErrorCode.NOT_FOUND_TEST.getMessage(), TestErrorCode.NOT_FOUND_TEST.getCode()); + } +} diff --git a/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/NotFoundTestResultCodeException.java b/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/NotFoundTestResultCodeException.java new file mode 100644 index 00000000..f44e2cc6 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/NotFoundTestResultCodeException.java @@ -0,0 +1,10 @@ +package com.nexters.keyme.domain.test.domain.exceptions; + +import com.nexters.keyme.domain.test.domain.exceptions.code.TestErrorCode; +import com.nexters.keyme.global.exceptions.KeymeNotFoundException; + +public class NotFoundTestResultCodeException extends KeymeNotFoundException { + public NotFoundTestResultCodeException() { + super(TestErrorCode.NOT_FOUND_TEST_RESULT_CODE.getMessage(), TestErrorCode.NOT_FOUND_TEST_RESULT_CODE.getCode()); + } +} diff --git a/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/NotFoundTestResultException.java b/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/NotFoundTestResultException.java new file mode 100644 index 00000000..05bdbfb0 --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/NotFoundTestResultException.java @@ -0,0 +1,10 @@ +package com.nexters.keyme.domain.test.domain.exceptions; + +import com.nexters.keyme.domain.test.domain.exceptions.code.TestErrorCode; +import com.nexters.keyme.global.exceptions.KeymeNotFoundException; + +public class NotFoundTestResultException extends KeymeNotFoundException { + public NotFoundTestResultException() { + super(TestErrorCode.NOT_FOUND_TEST_RESULT.getMessage(), TestErrorCode.NOT_FOUND_TEST_RESULT.getCode()); + } +} diff --git a/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/code/TestErrorCode.java b/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/code/TestErrorCode.java new file mode 100644 index 00000000..61128f6d --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/test/domain/exceptions/code/TestErrorCode.java @@ -0,0 +1,19 @@ +package com.nexters.keyme.domain.test.domain.exceptions.code; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum TestErrorCode { + + NOT_FOUND_TEST(404, "Test를 찾을 수 없습니다."), + NOT_FOUND_TEST_RESULT(404, "Test Result를 찾을 수 없습니다."), + NOT_FOUND_TEST_RESULT_CODE(404, "Result Code가 존재하지 않습니다"), + INVALID_DAILY_TEST(400, "Daily Test를 호출할 수 없습니다. 온보딩을 먼저 풀어주세요"), + ALREADY_EXIST_TEST_RESULT(400, "해당 유저의 Test Result가 이미 존재합니다."), + ALREADY_EXIST_TEST_RESULT_OWNER(400, "해당 Test Result는 다른 유저의 Result입니다."); + + private final int code; + private final String message; +} diff --git a/src/main/java/com/nexters/keyme/test/domain/helper/TestDataProvider.java b/src/main/java/com/nexters/keyme/domain/test/domain/helper/TestDataProvider.java similarity index 65% rename from src/main/java/com/nexters/keyme/test/domain/helper/TestDataProvider.java rename to src/main/java/com/nexters/keyme/domain/test/domain/helper/TestDataProvider.java index ebf93933..f072d7f6 100644 --- a/src/main/java/com/nexters/keyme/test/domain/helper/TestDataProvider.java +++ b/src/main/java/com/nexters/keyme/domain/test/domain/helper/TestDataProvider.java @@ -1,16 +1,17 @@ -package com.nexters.keyme.test.domain.helper; +package com.nexters.keyme.domain.test.domain.helper; -import com.nexters.keyme.common.exceptions.ResourceNotFoundException; -import com.nexters.keyme.member.domain.model.MemberEntity; -import com.nexters.keyme.member.domain.repository.MemberRepository; -import com.nexters.keyme.question.domain.helper.QuestionAsyncDataProvider; -import com.nexters.keyme.question.domain.model.Question; -import com.nexters.keyme.question.presentation.dto.response.QuestionResponse; -import com.nexters.keyme.test.domain.model.Test; -import com.nexters.keyme.test.domain.model.TestResult; -import com.nexters.keyme.test.domain.repository.TestRepository; -import com.nexters.keyme.test.presentation.dto.response.TestDetailResponse; -import com.nexters.keyme.test.presentation.dto.response.TestSimpleMemberResponse; +import com.nexters.keyme.domain.member.domain.exceptions.NotFoundMemberException; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.member.domain.repository.MemberRepository; +import com.nexters.keyme.domain.question.domain.helper.QuestionAsyncDataProvider; +import com.nexters.keyme.domain.question.domain.model.Question; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionResponse; +import com.nexters.keyme.domain.test.domain.exceptions.NotFoundTestException; +import com.nexters.keyme.domain.test.domain.model.Test; +import com.nexters.keyme.domain.test.domain.repository.TestRepository; +import com.nexters.keyme.domain.test.presentation.dto.response.TestDetailResponse; +import com.nexters.keyme.domain.test.presentation.dto.response.TestSimpleMemberResponse; +import com.nexters.keyme.domain.test.domain.model.TestResult; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -32,8 +33,8 @@ public class TestDataProvider { @Transactional public TestDetailResponse getTestDeatil(Long testId, Long solverId) { - Test test = testRepository.findById(testId).orElseThrow(ResourceNotFoundException::new); - MemberEntity member = solverId == null ? null : memberRepository.findById(solverId).orElseThrow(ResourceNotFoundException::new); + Test test = testRepository.findById(testId).orElseThrow(NotFoundTestException::new); + MemberEntity member = solverId == null ? null : memberRepository.findById(solverId).orElseThrow(NotFoundMemberException::new); CompletableFuture> testResultFuture = testResultAsyncDataProvider.asyncFindByTestAndSolver(test, member); CompletableFuture> questionListFuture = questionAsyncDataProvider.asyncFindAllQuestionByTestId(testId); diff --git a/src/main/java/com/nexters/keyme/test/domain/helper/TestResultAsyncDataProvider.java b/src/main/java/com/nexters/keyme/domain/test/domain/helper/TestResultAsyncDataProvider.java similarity index 71% rename from src/main/java/com/nexters/keyme/test/domain/helper/TestResultAsyncDataProvider.java rename to src/main/java/com/nexters/keyme/domain/test/domain/helper/TestResultAsyncDataProvider.java index aa295798..c104ed23 100644 --- a/src/main/java/com/nexters/keyme/test/domain/helper/TestResultAsyncDataProvider.java +++ b/src/main/java/com/nexters/keyme/domain/test/domain/helper/TestResultAsyncDataProvider.java @@ -1,9 +1,9 @@ -package com.nexters.keyme.test.domain.helper; +package com.nexters.keyme.domain.test.domain.helper; -import com.nexters.keyme.member.domain.model.MemberEntity; -import com.nexters.keyme.test.domain.model.Test; -import com.nexters.keyme.test.domain.model.TestResult; -import com.nexters.keyme.test.domain.repository.TestResultRepository; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.test.domain.model.Test; +import com.nexters.keyme.domain.test.domain.model.TestResult; +import com.nexters.keyme.domain.test.domain.repository.TestResultRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Async; diff --git a/src/main/java/com/nexters/keyme/test/domain/helper/TestResultCodeProvider.java b/src/main/java/com/nexters/keyme/domain/test/domain/helper/TestResultCodeProvider.java similarity index 84% rename from src/main/java/com/nexters/keyme/test/domain/helper/TestResultCodeProvider.java rename to src/main/java/com/nexters/keyme/domain/test/domain/helper/TestResultCodeProvider.java index c744c398..6e3c4dbf 100644 --- a/src/main/java/com/nexters/keyme/test/domain/helper/TestResultCodeProvider.java +++ b/src/main/java/com/nexters/keyme/domain/test/domain/helper/TestResultCodeProvider.java @@ -1,15 +1,13 @@ -package com.nexters.keyme.test.domain.helper; +package com.nexters.keyme.domain.test.domain.helper; -import com.nexters.keyme.test.domain.model.TestResultCode; -import com.nexters.keyme.test.domain.repository.TestResultCodeRepository; -import com.nexters.keyme.test.domain.repository.TestResultRepository; +import com.nexters.keyme.domain.test.domain.model.TestResultCode; +import com.nexters.keyme.domain.test.domain.repository.TestResultCodeRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; import java.security.SecureRandom; -import java.util.Random; @Component @RequiredArgsConstructor diff --git a/src/main/java/com/nexters/keyme/test/domain/internaldto/TestResultStatisticInfo.java b/src/main/java/com/nexters/keyme/domain/test/domain/internaldto/TestResultStatisticInfo.java similarity index 80% rename from src/main/java/com/nexters/keyme/test/domain/internaldto/TestResultStatisticInfo.java rename to src/main/java/com/nexters/keyme/domain/test/domain/internaldto/TestResultStatisticInfo.java index 957f7bf8..7378a3c4 100644 --- a/src/main/java/com/nexters/keyme/test/domain/internaldto/TestResultStatisticInfo.java +++ b/src/main/java/com/nexters/keyme/domain/test/domain/internaldto/TestResultStatisticInfo.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.test.domain.internaldto; +package com.nexters.keyme.domain.test.domain.internaldto; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/nexters/keyme/test/domain/model/Test.java b/src/main/java/com/nexters/keyme/domain/test/domain/model/Test.java similarity index 81% rename from src/main/java/com/nexters/keyme/test/domain/model/Test.java rename to src/main/java/com/nexters/keyme/domain/test/domain/model/Test.java index 66faa79a..1701bca0 100644 --- a/src/main/java/com/nexters/keyme/test/domain/model/Test.java +++ b/src/main/java/com/nexters/keyme/domain/test/domain/model/Test.java @@ -1,8 +1,8 @@ -package com.nexters.keyme.test.domain.model; +package com.nexters.keyme.domain.test.domain.model; -import com.nexters.keyme.common.model.BaseTimeEntity; -import com.nexters.keyme.member.domain.model.MemberEntity; -import com.nexters.keyme.question.domain.model.QuestionBundle; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.question.domain.model.QuestionBundle; +import com.nexters.keyme.global.model.BaseTimeEntity; import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.ColumnDefault; diff --git a/src/main/java/com/nexters/keyme/test/domain/model/TestResult.java b/src/main/java/com/nexters/keyme/domain/test/domain/model/TestResult.java similarity index 74% rename from src/main/java/com/nexters/keyme/test/domain/model/TestResult.java rename to src/main/java/com/nexters/keyme/domain/test/domain/model/TestResult.java index 2b6b03b4..b901a9c8 100644 --- a/src/main/java/com/nexters/keyme/test/domain/model/TestResult.java +++ b/src/main/java/com/nexters/keyme/domain/test/domain/model/TestResult.java @@ -1,8 +1,8 @@ -package com.nexters.keyme.test.domain.model; +package com.nexters.keyme.domain.test.domain.model; -import com.nexters.keyme.common.model.BaseTimeEntity; -import com.nexters.keyme.member.domain.model.MemberEntity; -import com.nexters.keyme.question.domain.model.QuestionSolved; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.question.domain.model.QuestionSolved; +import com.nexters.keyme.global.model.BaseTimeEntity; import lombok.*; import javax.persistence.*; diff --git a/src/main/java/com/nexters/keyme/test/domain/model/TestResultCode.java b/src/main/java/com/nexters/keyme/domain/test/domain/model/TestResultCode.java similarity index 89% rename from src/main/java/com/nexters/keyme/test/domain/model/TestResultCode.java rename to src/main/java/com/nexters/keyme/domain/test/domain/model/TestResultCode.java index d8cd0940..acd8c0f9 100644 --- a/src/main/java/com/nexters/keyme/test/domain/model/TestResultCode.java +++ b/src/main/java/com/nexters/keyme/domain/test/domain/model/TestResultCode.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.test.domain.model; +package com.nexters.keyme.domain.test.domain.model; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/test/domain/repository/TestRepository.java b/src/main/java/com/nexters/keyme/domain/test/domain/repository/TestRepository.java similarity index 66% rename from src/main/java/com/nexters/keyme/test/domain/repository/TestRepository.java rename to src/main/java/com/nexters/keyme/domain/test/domain/repository/TestRepository.java index 7b2114af..ddaa5d49 100644 --- a/src/main/java/com/nexters/keyme/test/domain/repository/TestRepository.java +++ b/src/main/java/com/nexters/keyme/domain/test/domain/repository/TestRepository.java @@ -1,7 +1,7 @@ -package com.nexters.keyme.test.domain.repository; +package com.nexters.keyme.domain.test.domain.repository; -import com.nexters.keyme.member.domain.model.MemberEntity; -import com.nexters.keyme.test.domain.model.Test; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.test.domain.model.Test; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; diff --git a/src/main/java/com/nexters/keyme/test/domain/repository/TestResultCodeRepository.java b/src/main/java/com/nexters/keyme/domain/test/domain/repository/TestResultCodeRepository.java similarity index 55% rename from src/main/java/com/nexters/keyme/test/domain/repository/TestResultCodeRepository.java rename to src/main/java/com/nexters/keyme/domain/test/domain/repository/TestResultCodeRepository.java index 822e54ec..d8b3cfcf 100644 --- a/src/main/java/com/nexters/keyme/test/domain/repository/TestResultCodeRepository.java +++ b/src/main/java/com/nexters/keyme/domain/test/domain/repository/TestResultCodeRepository.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.test.domain.repository; +package com.nexters.keyme.domain.test.domain.repository; -import com.nexters.keyme.test.domain.model.TestResultCode; +import com.nexters.keyme.domain.test.domain.model.TestResultCode; import org.springframework.data.jpa.repository.JpaRepository; public interface TestResultCodeRepository extends JpaRepository { diff --git a/src/main/java/com/nexters/keyme/domain/test/domain/repository/TestResultRepository.java b/src/main/java/com/nexters/keyme/domain/test/domain/repository/TestResultRepository.java new file mode 100644 index 00000000..63eb3b7f --- /dev/null +++ b/src/main/java/com/nexters/keyme/domain/test/domain/repository/TestResultRepository.java @@ -0,0 +1,20 @@ +package com.nexters.keyme.domain.test.domain.repository; + +import com.nexters.keyme.domain.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.test.domain.model.Test; +import com.nexters.keyme.domain.test.domain.model.TestResult; +import com.nexters.keyme.domain.test.domain.internaldto.TestResultStatisticInfo; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.Optional; + +public interface TestResultRepository extends JpaRepository { + Optional findByTestAndSolver(Test test, MemberEntity solver); + + @Query( + "select new com.nexters.keyme.domain.test.domain.internaldto.TestResultStatisticInfo(avg(tr.matchRate), COUNT(*)) from TestResult tr " + + "where tr.test.testId = :testId" + ) + TestResultStatisticInfo findStatisticsByTestId(Long testId); +} diff --git a/src/main/java/com/nexters/keyme/test/events/AddStatisticEvent.java b/src/main/java/com/nexters/keyme/domain/test/events/AddStatisticEvent.java similarity index 79% rename from src/main/java/com/nexters/keyme/test/events/AddStatisticEvent.java rename to src/main/java/com/nexters/keyme/domain/test/events/AddStatisticEvent.java index 7d779c61..dc1572a6 100644 --- a/src/main/java/com/nexters/keyme/test/events/AddStatisticEvent.java +++ b/src/main/java/com/nexters/keyme/domain/test/events/AddStatisticEvent.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.test.events; +package com.nexters.keyme.domain.test.events; -import com.nexters.keyme.question.domain.model.QuestionSolved; +import com.nexters.keyme.domain.question.domain.model.QuestionSolved; import lombok.Getter; import java.util.List; diff --git a/src/main/java/com/nexters/keyme/test/events/SendNotificationEvent.java b/src/main/java/com/nexters/keyme/domain/test/events/SendNotificationEvent.java similarity index 82% rename from src/main/java/com/nexters/keyme/test/events/SendNotificationEvent.java rename to src/main/java/com/nexters/keyme/domain/test/events/SendNotificationEvent.java index 6481acae..b01750c7 100644 --- a/src/main/java/com/nexters/keyme/test/events/SendNotificationEvent.java +++ b/src/main/java/com/nexters/keyme/domain/test/events/SendNotificationEvent.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.test.events; +package com.nexters.keyme.domain.test.events; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/nexters/keyme/test/events/TestEventHandler.java b/src/main/java/com/nexters/keyme/domain/test/events/TestEventHandler.java similarity index 75% rename from src/main/java/com/nexters/keyme/test/events/TestEventHandler.java rename to src/main/java/com/nexters/keyme/domain/test/events/TestEventHandler.java index fe948f7d..e55565e9 100644 --- a/src/main/java/com/nexters/keyme/test/events/TestEventHandler.java +++ b/src/main/java/com/nexters/keyme/domain/test/events/TestEventHandler.java @@ -1,10 +1,10 @@ -package com.nexters.keyme.test.events; +package com.nexters.keyme.domain.test.events; -import com.nexters.keyme.notification.dto.UserNotificationRequest; -import com.nexters.keyme.notification.service.NotificationService; -import com.nexters.keyme.question.domain.model.QuestionSolved; -import com.nexters.keyme.statistics.application.StatisticService; -import com.nexters.keyme.statistics.application.dto.ScoreInfo; +import com.nexters.keyme.domain.notification.dto.UserNotificationRequest; +import com.nexters.keyme.domain.notification.service.NotificationService; +import com.nexters.keyme.domain.question.domain.model.QuestionSolved; +import com.nexters.keyme.domain.statistics.application.StatisticService; +import com.nexters.keyme.domain.statistics.application.dto.ScoreInfo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.event.EventListener; diff --git a/src/main/java/com/nexters/keyme/test/presentation/controller/TestController.java b/src/main/java/com/nexters/keyme/domain/test/presentation/controller/TestController.java similarity index 82% rename from src/main/java/com/nexters/keyme/test/presentation/controller/TestController.java rename to src/main/java/com/nexters/keyme/domain/test/presentation/controller/TestController.java index 4111162a..c1b4c84a 100644 --- a/src/main/java/com/nexters/keyme/test/presentation/controller/TestController.java +++ b/src/main/java/com/nexters/keyme/domain/test/presentation/controller/TestController.java @@ -1,21 +1,20 @@ -package com.nexters.keyme.test.presentation.controller; +package com.nexters.keyme.domain.test.presentation.controller; -import com.nexters.keyme.auth.domain.internaldto.UserInfo; -import com.nexters.keyme.common.annotation.RequestUser; -import com.nexters.keyme.common.dto.response.ApiResponse; -import com.nexters.keyme.test.application.TestService; -import com.nexters.keyme.test.presentation.dto.request.TestListRequest; -import com.nexters.keyme.test.presentation.dto.request.TestSubmissionRequest; -import com.nexters.keyme.test.presentation.dto.response.*; +import com.nexters.keyme.global.dto.internal.UserInfo; +import com.nexters.keyme.domain.test.application.TestService; +import com.nexters.keyme.domain.test.presentation.dto.request.TestSubmissionRequest; +import com.nexters.keyme.domain.test.presentation.dto.response.SingleTestStatisticsResponse; +import com.nexters.keyme.domain.test.presentation.dto.response.TestDetailResponse; +import com.nexters.keyme.domain.test.presentation.dto.response.TestResultResponse; +import com.nexters.keyme.domain.test.presentation.dto.response.TestSubmitResponse; +import com.nexters.keyme.global.annotation.RequestUser; +import com.nexters.keyme.global.dto.response.ApiResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; -import java.util.List; - @Api(tags = "테스트", description = "테스트/결과 관련 API") @RestController @RequestMapping("/tests") diff --git a/src/main/java/com/nexters/keyme/test/presentation/controller/TestResultController.java b/src/main/java/com/nexters/keyme/domain/test/presentation/controller/TestResultController.java similarity index 70% rename from src/main/java/com/nexters/keyme/test/presentation/controller/TestResultController.java rename to src/main/java/com/nexters/keyme/domain/test/presentation/controller/TestResultController.java index b6110933..373338d3 100644 --- a/src/main/java/com/nexters/keyme/test/presentation/controller/TestResultController.java +++ b/src/main/java/com/nexters/keyme/domain/test/presentation/controller/TestResultController.java @@ -1,10 +1,10 @@ -package com.nexters.keyme.test.presentation.controller; +package com.nexters.keyme.domain.test.presentation.controller; -import com.nexters.keyme.auth.domain.internaldto.UserInfo; -import com.nexters.keyme.common.annotation.RequestUser; -import com.nexters.keyme.common.dto.response.ApiResponse; -import com.nexters.keyme.test.application.TestResultService; -import com.nexters.keyme.test.presentation.dto.request.TestRegistrationRequest; +import com.nexters.keyme.global.dto.internal.UserInfo; +import com.nexters.keyme.domain.test.application.TestResultService; +import com.nexters.keyme.domain.test.presentation.dto.request.TestRegistrationRequest; +import com.nexters.keyme.global.annotation.RequestUser; +import com.nexters.keyme.global.dto.response.ApiResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/test/presentation/dto/request/TestListRequest.java b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/request/TestListRequest.java similarity index 69% rename from src/main/java/com/nexters/keyme/test/presentation/dto/request/TestListRequest.java rename to src/main/java/com/nexters/keyme/domain/test/presentation/dto/request/TestListRequest.java index 08a2eb9b..22342004 100644 --- a/src/main/java/com/nexters/keyme/test/presentation/dto/request/TestListRequest.java +++ b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/request/TestListRequest.java @@ -1,7 +1,7 @@ -package com.nexters.keyme.test.presentation.dto.request; +package com.nexters.keyme.domain.test.presentation.dto.request; -import com.nexters.keyme.common.dto.request.PaginationRequest; -import com.nexters.keyme.test.domain.enums.TestListType; +import com.nexters.keyme.global.dto.request.PaginationRequest; +import com.nexters.keyme.domain.test.domain.enums.TestListType; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.*; diff --git a/src/main/java/com/nexters/keyme/test/presentation/dto/request/TestRegistrationRequest.java b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/request/TestRegistrationRequest.java similarity index 81% rename from src/main/java/com/nexters/keyme/test/presentation/dto/request/TestRegistrationRequest.java rename to src/main/java/com/nexters/keyme/domain/test/presentation/dto/request/TestRegistrationRequest.java index b215a6fe..ac9fe62d 100644 --- a/src/main/java/com/nexters/keyme/test/presentation/dto/request/TestRegistrationRequest.java +++ b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/request/TestRegistrationRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.test.presentation.dto.request; +package com.nexters.keyme.domain.test.presentation.dto.request; import io.swagger.annotations.ApiModel; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/test/presentation/dto/request/TestResultRequest.java b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/request/TestResultRequest.java similarity index 82% rename from src/main/java/com/nexters/keyme/test/presentation/dto/request/TestResultRequest.java rename to src/main/java/com/nexters/keyme/domain/test/presentation/dto/request/TestResultRequest.java index 83f06e78..ecafcb45 100644 --- a/src/main/java/com/nexters/keyme/test/presentation/dto/request/TestResultRequest.java +++ b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/request/TestResultRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.test.presentation.dto.request; +package com.nexters.keyme.domain.test.presentation.dto.request; import io.swagger.annotations.ApiModel; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/test/presentation/dto/request/TestSubmissionRequest.java b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/request/TestSubmissionRequest.java similarity index 87% rename from src/main/java/com/nexters/keyme/test/presentation/dto/request/TestSubmissionRequest.java rename to src/main/java/com/nexters/keyme/domain/test/presentation/dto/request/TestSubmissionRequest.java index 17a502c9..cf301abf 100644 --- a/src/main/java/com/nexters/keyme/test/presentation/dto/request/TestSubmissionRequest.java +++ b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/request/TestSubmissionRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.test.presentation.dto.request; +package com.nexters.keyme.domain.test.presentation.dto.request; import io.swagger.annotations.ApiModel; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/test/presentation/dto/response/SingleTestStatisticsResponse.java b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/SingleTestStatisticsResponse.java similarity index 73% rename from src/main/java/com/nexters/keyme/test/presentation/dto/response/SingleTestStatisticsResponse.java rename to src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/SingleTestStatisticsResponse.java index 0bf5c59f..758c4a92 100644 --- a/src/main/java/com/nexters/keyme/test/presentation/dto/response/SingleTestStatisticsResponse.java +++ b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/SingleTestStatisticsResponse.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.test.presentation.dto.response; +package com.nexters.keyme.domain.test.presentation.dto.response; -import com.nexters.keyme.question.presentation.dto.response.QuestionStatisticResponse; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionStatisticResponse; import io.swagger.annotations.ApiModel; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/nexters/keyme/test/presentation/dto/response/TestDetailResponse.java b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestDetailResponse.java similarity index 73% rename from src/main/java/com/nexters/keyme/test/presentation/dto/response/TestDetailResponse.java rename to src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestDetailResponse.java index 85fca0b6..dc013fe4 100644 --- a/src/main/java/com/nexters/keyme/test/presentation/dto/response/TestDetailResponse.java +++ b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestDetailResponse.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.test.presentation.dto.response; +package com.nexters.keyme.domain.test.presentation.dto.response; -import com.nexters.keyme.question.presentation.dto.response.QuestionResponse; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionResponse; import io.swagger.annotations.ApiModel; import lombok.*; diff --git a/src/main/java/com/nexters/keyme/test/presentation/dto/response/TestFeedResponse.java b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestFeedResponse.java similarity index 88% rename from src/main/java/com/nexters/keyme/test/presentation/dto/response/TestFeedResponse.java rename to src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestFeedResponse.java index d1feb602..1157bfd4 100644 --- a/src/main/java/com/nexters/keyme/test/presentation/dto/response/TestFeedResponse.java +++ b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestFeedResponse.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.test.presentation.dto.response; +package com.nexters.keyme.domain.test.presentation.dto.response; import io.swagger.annotations.ApiModel; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/test/presentation/dto/response/TestResultRateResponse.java b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestResultRateResponse.java similarity index 84% rename from src/main/java/com/nexters/keyme/test/presentation/dto/response/TestResultRateResponse.java rename to src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestResultRateResponse.java index e865a018..cb234429 100644 --- a/src/main/java/com/nexters/keyme/test/presentation/dto/response/TestResultRateResponse.java +++ b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestResultRateResponse.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.test.presentation.dto.response; +package com.nexters.keyme.domain.test.presentation.dto.response; import io.swagger.annotations.ApiModel; diff --git a/src/main/java/com/nexters/keyme/test/presentation/dto/response/TestResultResponse.java b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestResultResponse.java similarity index 79% rename from src/main/java/com/nexters/keyme/test/presentation/dto/response/TestResultResponse.java rename to src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestResultResponse.java index 7b67f3ec..fe2dd623 100644 --- a/src/main/java/com/nexters/keyme/test/presentation/dto/response/TestResultResponse.java +++ b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestResultResponse.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.test.presentation.dto.response; +package com.nexters.keyme.domain.test.presentation.dto.response; -import com.nexters.keyme.question.presentation.dto.response.QuestionSolvedResponse; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionSolvedResponse; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/test/presentation/dto/response/TestSimpleMemberResponse.java b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestSimpleMemberResponse.java similarity index 82% rename from src/main/java/com/nexters/keyme/test/presentation/dto/response/TestSimpleMemberResponse.java rename to src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestSimpleMemberResponse.java index bc21f0c7..3699656a 100644 --- a/src/main/java/com/nexters/keyme/test/presentation/dto/response/TestSimpleMemberResponse.java +++ b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestSimpleMemberResponse.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.test.presentation.dto.response; +package com.nexters.keyme.domain.test.presentation.dto.response; -import com.nexters.keyme.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; import io.swagger.annotations.ApiModel; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/nexters/keyme/test/presentation/dto/response/TestSubmitResponse.java b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestSubmitResponse.java similarity index 90% rename from src/main/java/com/nexters/keyme/test/presentation/dto/response/TestSubmitResponse.java rename to src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestSubmitResponse.java index 26d55696..a52b087c 100644 --- a/src/main/java/com/nexters/keyme/test/presentation/dto/response/TestSubmitResponse.java +++ b/src/main/java/com/nexters/keyme/domain/test/presentation/dto/response/TestSubmitResponse.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.test.presentation.dto.response; +package com.nexters.keyme.domain.test.presentation.dto.response; import io.swagger.annotations.ApiModel; diff --git a/src/main/java/com/nexters/keyme/common/annotation/ApiSecurityIgnore.java b/src/main/java/com/nexters/keyme/global/annotation/ApiSecurityIgnore.java similarity index 85% rename from src/main/java/com/nexters/keyme/common/annotation/ApiSecurityIgnore.java rename to src/main/java/com/nexters/keyme/global/annotation/ApiSecurityIgnore.java index 1c53421e..8d30dd3b 100644 --- a/src/main/java/com/nexters/keyme/common/annotation/ApiSecurityIgnore.java +++ b/src/main/java/com/nexters/keyme/global/annotation/ApiSecurityIgnore.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.common.annotation; +package com.nexters.keyme.global.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/com/nexters/keyme/common/annotation/RequestUser.java b/src/main/java/com/nexters/keyme/global/annotation/RequestUser.java similarity index 75% rename from src/main/java/com/nexters/keyme/common/annotation/RequestUser.java rename to src/main/java/com/nexters/keyme/global/annotation/RequestUser.java index 2ea441e0..ae4c47c1 100644 --- a/src/main/java/com/nexters/keyme/common/annotation/RequestUser.java +++ b/src/main/java/com/nexters/keyme/global/annotation/RequestUser.java @@ -1,6 +1,4 @@ -package com.nexters.keyme.common.annotation; - -import org.jboss.jandex.AnnotationTarget; +package com.nexters.keyme.global.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/com/nexters/keyme/common/aop/QueryExecutionTimeAspect.java b/src/main/java/com/nexters/keyme/global/aspect/QueryExecutionTimeAspect.java similarity index 97% rename from src/main/java/com/nexters/keyme/common/aop/QueryExecutionTimeAspect.java rename to src/main/java/com/nexters/keyme/global/aspect/QueryExecutionTimeAspect.java index 422dcbe4..9c16a854 100644 --- a/src/main/java/com/nexters/keyme/common/aop/QueryExecutionTimeAspect.java +++ b/src/main/java/com/nexters/keyme/global/aspect/QueryExecutionTimeAspect.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.common.aop; +package com.nexters.keyme.global.aspect; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; diff --git a/src/main/java/com/nexters/keyme/common/config/AsyncConfig.java b/src/main/java/com/nexters/keyme/global/config/AsyncConfig.java similarity index 81% rename from src/main/java/com/nexters/keyme/common/config/AsyncConfig.java rename to src/main/java/com/nexters/keyme/global/config/AsyncConfig.java index 41083138..8b562d93 100644 --- a/src/main/java/com/nexters/keyme/common/config/AsyncConfig.java +++ b/src/main/java/com/nexters/keyme/global/config/AsyncConfig.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.common.config; +package com.nexters.keyme.global.config; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableAsync; diff --git a/src/main/java/com/nexters/keyme/common/config/FeignClientConfig.java b/src/main/java/com/nexters/keyme/global/config/FeignClientConfig.java similarity index 87% rename from src/main/java/com/nexters/keyme/common/config/FeignClientConfig.java rename to src/main/java/com/nexters/keyme/global/config/FeignClientConfig.java index 9ae36f20..eb2749ee 100644 --- a/src/main/java/com/nexters/keyme/common/config/FeignClientConfig.java +++ b/src/main/java/com/nexters/keyme/global/config/FeignClientConfig.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.common.config; +package com.nexters.keyme.global.config; import com.nexters.keyme.KeymeApplication; import org.springframework.cloud.openfeign.EnableFeignClients; diff --git a/src/main/java/com/nexters/keyme/common/config/FilterConfig.java b/src/main/java/com/nexters/keyme/global/config/FilterConfig.java similarity index 87% rename from src/main/java/com/nexters/keyme/common/config/FilterConfig.java rename to src/main/java/com/nexters/keyme/global/config/FilterConfig.java index 55e8d3ea..2c99e2b7 100644 --- a/src/main/java/com/nexters/keyme/common/config/FilterConfig.java +++ b/src/main/java/com/nexters/keyme/global/config/FilterConfig.java @@ -1,8 +1,8 @@ -package com.nexters.keyme.common.config; +package com.nexters.keyme.global.config; import com.fasterxml.jackson.databind.ObjectMapper; -import com.nexters.keyme.common.filter.LoggingFilter; -import com.nexters.keyme.common.filter.LoggingTraceFilter; +import com.nexters.keyme.global.filter.LoggingFilter; +import com.nexters.keyme.global.filter.LoggingTraceFilter; import lombok.RequiredArgsConstructor; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/com/nexters/keyme/common/config/JpaConfig.java b/src/main/java/com/nexters/keyme/global/config/JpaConfig.java similarity index 90% rename from src/main/java/com/nexters/keyme/common/config/JpaConfig.java rename to src/main/java/com/nexters/keyme/global/config/JpaConfig.java index 43ec3009..60276349 100644 --- a/src/main/java/com/nexters/keyme/common/config/JpaConfig.java +++ b/src/main/java/com/nexters/keyme/global/config/JpaConfig.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.common.config; +package com.nexters.keyme.global.config; import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; diff --git a/src/main/java/com/nexters/keyme/common/config/QueryDslConfig.java b/src/main/java/com/nexters/keyme/global/config/QueryDslConfig.java similarity index 92% rename from src/main/java/com/nexters/keyme/common/config/QueryDslConfig.java rename to src/main/java/com/nexters/keyme/global/config/QueryDslConfig.java index 2516d38b..48938537 100644 --- a/src/main/java/com/nexters/keyme/common/config/QueryDslConfig.java +++ b/src/main/java/com/nexters/keyme/global/config/QueryDslConfig.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.common.config; +package com.nexters.keyme.global.config; import com.querydsl.jpa.impl.JPAQueryFactory; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/com/nexters/keyme/common/config/SecurityConfig.java b/src/main/java/com/nexters/keyme/global/config/SecurityConfig.java similarity index 90% rename from src/main/java/com/nexters/keyme/common/config/SecurityConfig.java rename to src/main/java/com/nexters/keyme/global/config/SecurityConfig.java index 2ab65127..ff14e775 100644 --- a/src/main/java/com/nexters/keyme/common/config/SecurityConfig.java +++ b/src/main/java/com/nexters/keyme/global/config/SecurityConfig.java @@ -1,11 +1,11 @@ -package com.nexters.keyme.common.config; +package com.nexters.keyme.global.config; import com.fasterxml.jackson.databind.ObjectMapper; -import com.nexters.keyme.common.security.exception.RestAuthenticationEntryPoint; -import com.nexters.keyme.common.security.filter.AuthenticationExceptionFilter; -import com.nexters.keyme.common.security.filter.JwtAuthenticationFilter; -import com.nexters.keyme.common.security.provider.AuthenticationTokenProvider; -import com.nexters.keyme.common.util.JwtTokenProvider; +import com.nexters.keyme.global.security.exception.RestAuthenticationEntryPoint; +import com.nexters.keyme.global.security.filter.AuthenticationExceptionFilter; +import com.nexters.keyme.global.security.filter.JwtAuthenticationFilter; +import com.nexters.keyme.global.security.provider.AuthenticationTokenProvider; +import com.nexters.keyme.global.util.JwtTokenProvider; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.http.HttpMethod; diff --git a/src/main/java/com/nexters/keyme/common/config/SwaggerConfig.java b/src/main/java/com/nexters/keyme/global/config/SwaggerConfig.java similarity index 91% rename from src/main/java/com/nexters/keyme/common/config/SwaggerConfig.java rename to src/main/java/com/nexters/keyme/global/config/SwaggerConfig.java index d9717a47..f16cac98 100644 --- a/src/main/java/com/nexters/keyme/common/config/SwaggerConfig.java +++ b/src/main/java/com/nexters/keyme/global/config/SwaggerConfig.java @@ -1,8 +1,7 @@ -package com.nexters.keyme.common.config; +package com.nexters.keyme.global.config; -import com.nexters.keyme.common.annotation.ApiSecurityIgnore; -import com.nexters.keyme.common.annotation.RequestUser; -import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import com.nexters.keyme.global.annotation.ApiSecurityIgnore; +import com.nexters.keyme.global.annotation.RequestUser; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.bind.annotation.RestController; diff --git a/src/main/java/com/nexters/keyme/common/config/WebMvcConfig.java b/src/main/java/com/nexters/keyme/global/config/WebMvcConfig.java similarity index 85% rename from src/main/java/com/nexters/keyme/common/config/WebMvcConfig.java rename to src/main/java/com/nexters/keyme/global/config/WebMvcConfig.java index 751aba6f..91605fdd 100644 --- a/src/main/java/com/nexters/keyme/common/config/WebMvcConfig.java +++ b/src/main/java/com/nexters/keyme/global/config/WebMvcConfig.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.common.config; +package com.nexters.keyme.global.config; -import com.nexters.keyme.common.resolver.UserInfoArgumentResolver; +import com.nexters.keyme.global.resolver.UserInfoArgumentResolver; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Configuration; import org.springframework.web.method.support.HandlerMethodArgumentResolver; diff --git a/src/main/java/com/nexters/keyme/common/config/ConstantConfig.java b/src/main/java/com/nexters/keyme/global/constant/ConstantString.java similarity index 73% rename from src/main/java/com/nexters/keyme/common/config/ConstantConfig.java rename to src/main/java/com/nexters/keyme/global/constant/ConstantString.java index 827e710f..00e53b26 100644 --- a/src/main/java/com/nexters/keyme/common/config/ConstantConfig.java +++ b/src/main/java/com/nexters/keyme/global/constant/ConstantString.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.common.config; +package com.nexters.keyme.global.constant; -public class ConstantConfig { +public class ConstantString { public static final String AUTHORIZATION_HEADER = "Authorization"; public static final String DEFAULT_IMAGE_URL = "https://keyme-ec2-access-s3.s3.ap-northeast-2.amazonaws.com/keyme_default.png"; } diff --git a/src/main/java/com/nexters/keyme/common/dto/internal/PageInfo.java b/src/main/java/com/nexters/keyme/global/dto/internal/PageInfo.java similarity index 82% rename from src/main/java/com/nexters/keyme/common/dto/internal/PageInfo.java rename to src/main/java/com/nexters/keyme/global/dto/internal/PageInfo.java index 1c83145b..7009d7b1 100644 --- a/src/main/java/com/nexters/keyme/common/dto/internal/PageInfo.java +++ b/src/main/java/com/nexters/keyme/global/dto/internal/PageInfo.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.common.dto.internal; +package com.nexters.keyme.global.dto.internal; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/common/dto/internal/RequestLogInfo.java b/src/main/java/com/nexters/keyme/global/dto/internal/RequestLogInfo.java similarity index 80% rename from src/main/java/com/nexters/keyme/common/dto/internal/RequestLogInfo.java rename to src/main/java/com/nexters/keyme/global/dto/internal/RequestLogInfo.java index 8a80bd76..3927c93e 100644 --- a/src/main/java/com/nexters/keyme/common/dto/internal/RequestLogInfo.java +++ b/src/main/java/com/nexters/keyme/global/dto/internal/RequestLogInfo.java @@ -1,17 +1,16 @@ -package com.nexters.keyme.common.dto.internal; +package com.nexters.keyme.global.dto.internal; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import java.util.List; - @NoArgsConstructor @AllArgsConstructor @Data @Builder public class RequestLogInfo { + private Long requestMemberId; private String uri; private String method; private String param; diff --git a/src/main/java/com/nexters/keyme/auth/domain/internaldto/UserInfo.java b/src/main/java/com/nexters/keyme/global/dto/internal/UserInfo.java similarity index 77% rename from src/main/java/com/nexters/keyme/auth/domain/internaldto/UserInfo.java rename to src/main/java/com/nexters/keyme/global/dto/internal/UserInfo.java index 596507a0..85441d3e 100644 --- a/src/main/java/com/nexters/keyme/auth/domain/internaldto/UserInfo.java +++ b/src/main/java/com/nexters/keyme/global/dto/internal/UserInfo.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.auth.domain.internaldto; +package com.nexters.keyme.global.dto.internal; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/nexters/keyme/common/dto/request/PaginationRequest.java b/src/main/java/com/nexters/keyme/global/dto/request/PaginationRequest.java similarity index 90% rename from src/main/java/com/nexters/keyme/common/dto/request/PaginationRequest.java rename to src/main/java/com/nexters/keyme/global/dto/request/PaginationRequest.java index a93c5211..37c1d729 100644 --- a/src/main/java/com/nexters/keyme/common/dto/request/PaginationRequest.java +++ b/src/main/java/com/nexters/keyme/global/dto/request/PaginationRequest.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.common.dto.request; +package com.nexters.keyme.global.dto.request; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/src/main/java/com/nexters/keyme/common/dto/response/ApiResponse.java b/src/main/java/com/nexters/keyme/global/dto/response/ApiResponse.java similarity index 67% rename from src/main/java/com/nexters/keyme/common/dto/response/ApiResponse.java rename to src/main/java/com/nexters/keyme/global/dto/response/ApiResponse.java index 2654579c..183a94e5 100644 --- a/src/main/java/com/nexters/keyme/common/dto/response/ApiResponse.java +++ b/src/main/java/com/nexters/keyme/global/dto/response/ApiResponse.java @@ -1,6 +1,6 @@ -package com.nexters.keyme.common.dto.response; +package com.nexters.keyme.global.dto.response; -import com.nexters.keyme.common.exceptions.errorcode.ErrorCode; +import com.nexters.keyme.global.exceptions.code.ErrorCode; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; @@ -12,10 +12,18 @@ public class ApiResponse { private String message; private T data; + static public ApiResponse success(Object data) { + return new ApiResponse(200, "요청에 성공했습니다.", data); + } + static public ApiResponse emptySuccess() { return new ApiResponse(200, "요청에 성공했습니다.", null); } + static public ApiResponse error(String message, int code) { + return new ApiResponse(code, message, null); + } + public ApiResponse(int code, String message, T data) { this.code = code; this.message = message; @@ -27,10 +35,4 @@ public ApiResponse(T data) { this.message = "요청에 성공했습니다."; this.data = data; } - - public ApiResponse(ErrorCode errorCode) { - this.code = errorCode.getCode(); - this.message = errorCode.getMessage(); - this.data = null; - } } diff --git a/src/main/java/com/nexters/keyme/common/dto/response/CommonResponse.java b/src/main/java/com/nexters/keyme/global/dto/response/CommonResponse.java similarity index 89% rename from src/main/java/com/nexters/keyme/common/dto/response/CommonResponse.java rename to src/main/java/com/nexters/keyme/global/dto/response/CommonResponse.java index 4e176d1a..f6e701b9 100644 --- a/src/main/java/com/nexters/keyme/common/dto/response/CommonResponse.java +++ b/src/main/java/com/nexters/keyme/global/dto/response/CommonResponse.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.common.dto.response; +package com.nexters.keyme.global.dto.response; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/common/dto/response/PageResponse.java b/src/main/java/com/nexters/keyme/global/dto/response/PageResponse.java similarity index 69% rename from src/main/java/com/nexters/keyme/common/dto/response/PageResponse.java rename to src/main/java/com/nexters/keyme/global/dto/response/PageResponse.java index ef65457b..3e849c78 100644 --- a/src/main/java/com/nexters/keyme/common/dto/response/PageResponse.java +++ b/src/main/java/com/nexters/keyme/global/dto/response/PageResponse.java @@ -1,6 +1,5 @@ -package com.nexters.keyme.common.dto.response; +package com.nexters.keyme.global.dto.response; -import com.nexters.keyme.common.dto.internal.PageInfo; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/nexters/keyme/common/enums/AuthRole.java b/src/main/java/com/nexters/keyme/global/enums/AuthRole.java similarity index 75% rename from src/main/java/com/nexters/keyme/common/enums/AuthRole.java rename to src/main/java/com/nexters/keyme/global/enums/AuthRole.java index c7072d38..67a124e1 100644 --- a/src/main/java/com/nexters/keyme/common/enums/AuthRole.java +++ b/src/main/java/com/nexters/keyme/global/enums/AuthRole.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.common.enums; +package com.nexters.keyme.global.enums; public enum AuthRole { ANONYMOUS, diff --git a/src/main/java/com/nexters/keyme/common/enums/OAuthType.java b/src/main/java/com/nexters/keyme/global/enums/OAuthType.java similarity index 78% rename from src/main/java/com/nexters/keyme/common/enums/OAuthType.java rename to src/main/java/com/nexters/keyme/global/enums/OAuthType.java index 05c35b94..3a548180 100644 --- a/src/main/java/com/nexters/keyme/common/enums/OAuthType.java +++ b/src/main/java/com/nexters/keyme/global/enums/OAuthType.java @@ -1,9 +1,7 @@ -package com.nexters.keyme.common.enums; +package com.nexters.keyme.global.enums; import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; import lombok.AllArgsConstructor; -import lombok.RequiredArgsConstructor; import java.util.stream.Stream; diff --git a/src/main/java/com/nexters/keyme/common/exceptions/FileUploadFailedException.java b/src/main/java/com/nexters/keyme/global/exceptions/FileUploadFailedException.java similarity index 60% rename from src/main/java/com/nexters/keyme/common/exceptions/FileUploadFailedException.java rename to src/main/java/com/nexters/keyme/global/exceptions/FileUploadFailedException.java index 2e322992..2f68eeb3 100644 --- a/src/main/java/com/nexters/keyme/common/exceptions/FileUploadFailedException.java +++ b/src/main/java/com/nexters/keyme/global/exceptions/FileUploadFailedException.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.common.exceptions; +package com.nexters.keyme.global.exceptions; public class FileUploadFailedException extends RuntimeException { diff --git a/src/main/java/com/nexters/keyme/global/exceptions/KeymeBadRequestException.java b/src/main/java/com/nexters/keyme/global/exceptions/KeymeBadRequestException.java new file mode 100644 index 00000000..15824cf3 --- /dev/null +++ b/src/main/java/com/nexters/keyme/global/exceptions/KeymeBadRequestException.java @@ -0,0 +1,10 @@ +package com.nexters.keyme.global.exceptions; + +import org.springframework.http.HttpStatus; + +public class KeymeBadRequestException extends KeymeException { + public KeymeBadRequestException(String message, int code) { + + super(HttpStatus.OK, message, code); + } +} diff --git a/src/main/java/com/nexters/keyme/global/exceptions/KeymeException.java b/src/main/java/com/nexters/keyme/global/exceptions/KeymeException.java new file mode 100644 index 00000000..caec76fc --- /dev/null +++ b/src/main/java/com/nexters/keyme/global/exceptions/KeymeException.java @@ -0,0 +1,15 @@ +package com.nexters.keyme.global.exceptions; + +import com.nexters.keyme.global.exceptions.code.ErrorCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public class KeymeException extends RuntimeException { + private final HttpStatus httpStatus; + private final String message; + private final int code; +} \ No newline at end of file diff --git a/src/main/java/com/nexters/keyme/global/exceptions/KeymeNotFoundException.java b/src/main/java/com/nexters/keyme/global/exceptions/KeymeNotFoundException.java new file mode 100644 index 00000000..5fe72506 --- /dev/null +++ b/src/main/java/com/nexters/keyme/global/exceptions/KeymeNotFoundException.java @@ -0,0 +1,9 @@ +package com.nexters.keyme.global.exceptions; + +import org.springframework.http.HttpStatus; + +public class KeymeNotFoundException extends KeymeException{ + public KeymeNotFoundException(String message, int code) { + super(HttpStatus.OK, message, code); + } +} diff --git a/src/main/java/com/nexters/keyme/global/exceptions/KeymeSuccessInfoException.java b/src/main/java/com/nexters/keyme/global/exceptions/KeymeSuccessInfoException.java new file mode 100644 index 00000000..ad4492c5 --- /dev/null +++ b/src/main/java/com/nexters/keyme/global/exceptions/KeymeSuccessInfoException.java @@ -0,0 +1,9 @@ +package com.nexters.keyme.global.exceptions; + +import org.springframework.http.HttpStatus; + +public class KeymeSuccessInfoException extends KeymeException{ + public KeymeSuccessInfoException(String message, int code) { + super(HttpStatus.OK, message, code); + } +} diff --git a/src/main/java/com/nexters/keyme/global/exceptions/KeymeUnauthorizedException.java b/src/main/java/com/nexters/keyme/global/exceptions/KeymeUnauthorizedException.java new file mode 100644 index 00000000..36c3151a --- /dev/null +++ b/src/main/java/com/nexters/keyme/global/exceptions/KeymeUnauthorizedException.java @@ -0,0 +1,14 @@ +package com.nexters.keyme.global.exceptions; + +import com.nexters.keyme.global.exceptions.KeymeException; +import com.nexters.keyme.global.exceptions.code.ErrorCode; +import org.springframework.http.HttpStatus; + +public class KeymeUnauthorizedException extends KeymeException { + public KeymeUnauthorizedException(String message, int code) { + super(HttpStatus.UNAUTHORIZED, message, code); + } + public KeymeUnauthorizedException(ErrorCode errorCode) { + super(HttpStatus.UNAUTHORIZED, errorCode.getMessage(), errorCode.getCode()); + } +} diff --git a/src/main/java/com/nexters/keyme/global/exceptions/code/ErrorCode.java b/src/main/java/com/nexters/keyme/global/exceptions/code/ErrorCode.java new file mode 100644 index 00000000..5a826584 --- /dev/null +++ b/src/main/java/com/nexters/keyme/global/exceptions/code/ErrorCode.java @@ -0,0 +1,21 @@ +package com.nexters.keyme.global.exceptions.code; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum ErrorCode { + TOKEN_EXPIRED(401, "액세스 토큰이 만료되었습니다."), + ACCESS_TOKEN_NOT_EXIST(401, "액세스 토큰이 존재하지 않습니다."), + REFRESH_TOKEN_NOT_EXIST(401, "리프레시 토큰이 존재하지 않습니다."), + TOKEN_INVALID(401, "올바르지 않은 토큰입니다."), + UNAUTHORIZED(401, "인증되지 않은 사용자입니다."), + + INVALID_REQUEST(400, "요청 형식이 잘못되었습니다. 다시 확인해주세요"), + + SERVER_ERROR(500, "서버 에러 발생! 문의주세요."); + + private final int code; + private final String message; +} diff --git a/src/main/java/com/nexters/keyme/global/exceptions/handler/GlobalExceptionHandler.java b/src/main/java/com/nexters/keyme/global/exceptions/handler/GlobalExceptionHandler.java new file mode 100644 index 00000000..bec067e0 --- /dev/null +++ b/src/main/java/com/nexters/keyme/global/exceptions/handler/GlobalExceptionHandler.java @@ -0,0 +1,71 @@ +package com.nexters.keyme.global.exceptions.handler; + +import com.nexters.keyme.global.dto.response.ApiResponse; +import com.nexters.keyme.global.exceptions.*; +import com.nexters.keyme.global.exceptions.code.ErrorCode; +import feign.Response; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; + +import java.util.Arrays; + +@Slf4j +@ControllerAdvice +public class GlobalExceptionHandler { + + // 파일 업로드 실패 + @ExceptionHandler(FileUploadFailedException.class) + public ResponseEntity handleFileUploadFailedException(FileUploadFailedException e) { + log.warn("파일 업로드에 실패하였습니다."); + return ResponseEntity.badRequest().body(ApiResponse.error("파일 업로드에 실패하였습니다. 파일 형식 및 크기를 확인해주세요", 400)); + } + + // 없는 API 호출 + @ExceptionHandler({ + MethodArgumentTypeMismatchException.class, // 요청 타입 불일치(바인딩 에러) + HttpRequestMethodNotSupportedException.class // 지원하지 않는 HTTP Method + }) + public ResponseEntity handleNotFulfilledException(Exception e) { + ErrorCode errorCode = ErrorCode.INVALID_REQUEST; + + return ResponseEntity.badRequest() + .body(ApiResponse.error(errorCode.getMessage(), errorCode.getCode())); + } + + // @Valid 예외 + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity handleArgumentNotValidException(MethodArgumentNotValidException e) { + return ResponseEntity.ok().body(ApiResponse.error(e.getMessage(), 400)); + } + + @ExceptionHandler(KeymeException.class) + public ResponseEntity handleKeymeException(KeymeException e) { + log.warn(e.getMessage()); + return ResponseEntity.status(e.getHttpStatus()) + .body(ApiResponse.error(e.getMessage(), e.getCode())); + } + + @ExceptionHandler(IllegalArgumentException.class) + public ResponseEntity handleIllegalArgumentException(IllegalArgumentException e) { + log.error("서버 로직 중 잘못된 인자를 넘기고 있습니다. {}", e.getCause()); + ErrorCode errorCode = ErrorCode.SERVER_ERROR; + + return ResponseEntity.internalServerError() + .body(ApiResponse.error(errorCode.getMessage(), errorCode.getCode())); + } + + @ExceptionHandler(Exception.class) + public ResponseEntity handleUnHandleException(Exception e) { + log.error("예상치 못한 에러발생! 😭 {} {} {}", e.getCause(), e.getMessage(), Arrays.toString(e.getStackTrace())); + ErrorCode errorCode = ErrorCode.SERVER_ERROR; + + return ResponseEntity.internalServerError() + .body(ApiResponse.error(errorCode.getMessage(), errorCode.getCode())); + } +} \ No newline at end of file diff --git a/src/main/java/com/nexters/keyme/common/filter/LoggingFilter.java b/src/main/java/com/nexters/keyme/global/filter/LoggingFilter.java similarity index 86% rename from src/main/java/com/nexters/keyme/common/filter/LoggingFilter.java rename to src/main/java/com/nexters/keyme/global/filter/LoggingFilter.java index 731837f0..794cf714 100644 --- a/src/main/java/com/nexters/keyme/common/filter/LoggingFilter.java +++ b/src/main/java/com/nexters/keyme/global/filter/LoggingFilter.java @@ -1,12 +1,14 @@ -package com.nexters.keyme.common.filter; +package com.nexters.keyme.global.filter; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.nexters.keyme.common.dto.internal.RequestLogInfo; +import com.nexters.keyme.global.dto.internal.UserInfo; +import com.nexters.keyme.global.dto.internal.RequestLogInfo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.slf4j.MDC; import org.springframework.http.HttpMethod; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.filter.OncePerRequestFilter; import org.springframework.web.util.ContentCachingRequestWrapper; import org.springframework.web.util.ContentCachingResponseWrapper; @@ -43,8 +45,15 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse private void printRequestLog(HttpServletRequest request, HttpServletResponse response) throws JsonProcessingException, UnsupportedEncodingException { long executionTime = System.currentTimeMillis() - Long.parseLong(MDC.get("requestStartTime")); + Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + Long memberId = null; + + if (principal instanceof UserInfo) { + memberId = ((UserInfo)principal).getMemberId(); + } RequestLogInfo requestLogInfo = RequestLogInfo.builder() + .requestMemberId(memberId) .uri(request.getRequestURI()) .method(request.getMethod()) .param(getParamString(request)) diff --git a/src/main/java/com/nexters/keyme/common/filter/LoggingTraceFilter.java b/src/main/java/com/nexters/keyme/global/filter/LoggingTraceFilter.java similarity index 90% rename from src/main/java/com/nexters/keyme/common/filter/LoggingTraceFilter.java rename to src/main/java/com/nexters/keyme/global/filter/LoggingTraceFilter.java index a17d5a0b..78d292db 100644 --- a/src/main/java/com/nexters/keyme/common/filter/LoggingTraceFilter.java +++ b/src/main/java/com/nexters/keyme/global/filter/LoggingTraceFilter.java @@ -1,7 +1,6 @@ -package com.nexters.keyme.common.filter; +package com.nexters.keyme.global.filter; import org.slf4j.MDC; -import org.springframework.stereotype.Component; import org.springframework.web.filter.OncePerRequestFilter; import javax.servlet.FilterChain; diff --git a/src/main/java/com/nexters/keyme/common/model/BaseTimeEntity.java b/src/main/java/com/nexters/keyme/global/model/BaseTimeEntity.java similarity index 94% rename from src/main/java/com/nexters/keyme/common/model/BaseTimeEntity.java rename to src/main/java/com/nexters/keyme/global/model/BaseTimeEntity.java index 84252680..a08de147 100644 --- a/src/main/java/com/nexters/keyme/common/model/BaseTimeEntity.java +++ b/src/main/java/com/nexters/keyme/global/model/BaseTimeEntity.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.common.model; +package com.nexters.keyme.global.model; import lombok.Getter; import org.springframework.data.annotation.CreatedDate; diff --git a/src/main/java/com/nexters/keyme/common/resolver/UserInfoArgumentResolver.java b/src/main/java/com/nexters/keyme/global/resolver/UserInfoArgumentResolver.java similarity index 84% rename from src/main/java/com/nexters/keyme/common/resolver/UserInfoArgumentResolver.java rename to src/main/java/com/nexters/keyme/global/resolver/UserInfoArgumentResolver.java index 5eb08f93..18683cdc 100644 --- a/src/main/java/com/nexters/keyme/common/resolver/UserInfoArgumentResolver.java +++ b/src/main/java/com/nexters/keyme/global/resolver/UserInfoArgumentResolver.java @@ -1,8 +1,7 @@ -package com.nexters.keyme.common.resolver; +package com.nexters.keyme.global.resolver; -import com.nexters.keyme.auth.domain.internaldto.UserInfo; -import com.nexters.keyme.common.annotation.RequestUser; -import com.nexters.keyme.common.exceptions.AccessDeniedException; +import com.nexters.keyme.global.dto.internal.UserInfo; +import com.nexters.keyme.global.annotation.RequestUser; import org.springframework.core.MethodParameter; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/nexters/keyme/common/security/exception/RestAuthenticationEntryPoint.java b/src/main/java/com/nexters/keyme/global/security/exception/RestAuthenticationEntryPoint.java similarity index 94% rename from src/main/java/com/nexters/keyme/common/security/exception/RestAuthenticationEntryPoint.java rename to src/main/java/com/nexters/keyme/global/security/exception/RestAuthenticationEntryPoint.java index 1368baba..4033410a 100644 --- a/src/main/java/com/nexters/keyme/common/security/exception/RestAuthenticationEntryPoint.java +++ b/src/main/java/com/nexters/keyme/global/security/exception/RestAuthenticationEntryPoint.java @@ -1,4 +1,4 @@ -package com.nexters.keyme.common.security.exception; +package com.nexters.keyme.global.security.exception; import net.minidev.json.JSONObject; import org.springframework.security.core.AuthenticationException; diff --git a/src/main/java/com/nexters/keyme/common/security/filter/AnonymousAuthenticationFilter.java b/src/main/java/com/nexters/keyme/global/security/filter/AnonymousAuthenticationFilter.java similarity index 80% rename from src/main/java/com/nexters/keyme/common/security/filter/AnonymousAuthenticationFilter.java rename to src/main/java/com/nexters/keyme/global/security/filter/AnonymousAuthenticationFilter.java index 671ca806..2d0dc921 100644 --- a/src/main/java/com/nexters/keyme/common/security/filter/AnonymousAuthenticationFilter.java +++ b/src/main/java/com/nexters/keyme/global/security/filter/AnonymousAuthenticationFilter.java @@ -1,15 +1,14 @@ -package com.nexters.keyme.common.security.filter; +package com.nexters.keyme.global.security.filter; -import com.nexters.keyme.auth.domain.internaldto.UserInfo; -import com.nexters.keyme.common.enums.AuthRole; -import com.nexters.keyme.common.security.token.JwtAuthenticationToken; +import com.nexters.keyme.global.dto.internal.UserInfo; +import com.nexters.keyme.global.enums.AuthRole; +import com.nexters.keyme.global.security.token.JwtAuthenticationToken; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.filter.OncePerRequestFilter; -import org.springframework.web.method.HandlerMethod; import javax.servlet.FilterChain; import javax.servlet.ServletException; @@ -18,7 +17,7 @@ import java.io.IOException; import java.util.Arrays; -import static com.nexters.keyme.common.config.ConstantConfig.AUTHORIZATION_HEADER; +import static com.nexters.keyme.global.constant.ConstantString.AUTHORIZATION_HEADER; @Slf4j public class AnonymousAuthenticationFilter extends OncePerRequestFilter { diff --git a/src/main/java/com/nexters/keyme/common/security/filter/AuthenticationExceptionFilter.java b/src/main/java/com/nexters/keyme/global/security/filter/AuthenticationExceptionFilter.java similarity index 91% rename from src/main/java/com/nexters/keyme/common/security/filter/AuthenticationExceptionFilter.java rename to src/main/java/com/nexters/keyme/global/security/filter/AuthenticationExceptionFilter.java index 9a6af7cb..0fcb06d6 100644 --- a/src/main/java/com/nexters/keyme/common/security/filter/AuthenticationExceptionFilter.java +++ b/src/main/java/com/nexters/keyme/global/security/filter/AuthenticationExceptionFilter.java @@ -1,7 +1,7 @@ -package com.nexters.keyme.common.security.filter; +package com.nexters.keyme.global.security.filter; import com.fasterxml.jackson.databind.ObjectMapper; -import com.nexters.keyme.common.dto.response.CommonResponse; +import com.nexters.keyme.global.dto.response.CommonResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; diff --git a/src/main/java/com/nexters/keyme/common/security/filter/JwtAuthenticationFilter.java b/src/main/java/com/nexters/keyme/global/security/filter/JwtAuthenticationFilter.java similarity index 87% rename from src/main/java/com/nexters/keyme/common/security/filter/JwtAuthenticationFilter.java rename to src/main/java/com/nexters/keyme/global/security/filter/JwtAuthenticationFilter.java index 996a3b8c..86c75cb5 100644 --- a/src/main/java/com/nexters/keyme/common/security/filter/JwtAuthenticationFilter.java +++ b/src/main/java/com/nexters/keyme/global/security/filter/JwtAuthenticationFilter.java @@ -1,11 +1,10 @@ -package com.nexters.keyme.common.security.filter; +package com.nexters.keyme.global.security.filter; -import com.nexters.keyme.common.security.provider.AuthenticationTokenProvider; -import com.nexters.keyme.common.util.JwtTokenProvider; +import com.nexters.keyme.global.security.provider.AuthenticationTokenProvider; +import com.nexters.keyme.global.util.JwtTokenProvider; import io.jsonwebtoken.Claims; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.slf4j.MDC; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.filter.OncePerRequestFilter; @@ -18,7 +17,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import static com.nexters.keyme.common.config.ConstantConfig.AUTHORIZATION_HEADER; +import static com.nexters.keyme.global.constant.ConstantString.AUTHORIZATION_HEADER; @Slf4j diff --git a/src/main/java/com/nexters/keyme/common/security/provider/AuthenticationTokenProvider.java b/src/main/java/com/nexters/keyme/global/security/provider/AuthenticationTokenProvider.java similarity index 83% rename from src/main/java/com/nexters/keyme/common/security/provider/AuthenticationTokenProvider.java rename to src/main/java/com/nexters/keyme/global/security/provider/AuthenticationTokenProvider.java index 27dcdd0b..32dc3f9e 100644 --- a/src/main/java/com/nexters/keyme/common/security/provider/AuthenticationTokenProvider.java +++ b/src/main/java/com/nexters/keyme/global/security/provider/AuthenticationTokenProvider.java @@ -1,7 +1,7 @@ -package com.nexters.keyme.common.security.provider; +package com.nexters.keyme.global.security.provider; -import com.nexters.keyme.common.security.token.JwtAuthenticationToken; -import com.nexters.keyme.auth.domain.internaldto.UserInfo; +import com.nexters.keyme.global.security.token.JwtAuthenticationToken; +import com.nexters.keyme.global.dto.internal.UserInfo; import io.jsonwebtoken.Claims; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/nexters/keyme/common/security/token/JwtAuthenticationToken.java b/src/main/java/com/nexters/keyme/global/security/token/JwtAuthenticationToken.java similarity index 81% rename from src/main/java/com/nexters/keyme/common/security/token/JwtAuthenticationToken.java rename to src/main/java/com/nexters/keyme/global/security/token/JwtAuthenticationToken.java index dcad6610..c7c0aea1 100644 --- a/src/main/java/com/nexters/keyme/common/security/token/JwtAuthenticationToken.java +++ b/src/main/java/com/nexters/keyme/global/security/token/JwtAuthenticationToken.java @@ -1,6 +1,5 @@ -package com.nexters.keyme.common.security.token; +package com.nexters.keyme.global.security.token; -import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.GrantedAuthority; diff --git a/src/main/java/com/nexters/keyme/common/util/JwtTokenProvider.java b/src/main/java/com/nexters/keyme/global/util/JwtTokenProvider.java similarity index 80% rename from src/main/java/com/nexters/keyme/common/util/JwtTokenProvider.java rename to src/main/java/com/nexters/keyme/global/util/JwtTokenProvider.java index e7fbf898..16affb56 100644 --- a/src/main/java/com/nexters/keyme/common/util/JwtTokenProvider.java +++ b/src/main/java/com/nexters/keyme/global/util/JwtTokenProvider.java @@ -1,8 +1,8 @@ -package com.nexters.keyme.common.util; +package com.nexters.keyme.global.util; -import com.nexters.keyme.common.enums.AuthRole; -import com.nexters.keyme.common.exceptions.AuthenticationFailedException; -import com.nexters.keyme.common.exceptions.errorcode.ErrorCode; +import com.nexters.keyme.global.enums.AuthRole; +import com.nexters.keyme.global.exceptions.KeymeUnauthorizedException; +import com.nexters.keyme.global.exceptions.code.ErrorCode; import io.jsonwebtoken.*; import lombok.extern.slf4j.Slf4j; import org.apache.tomcat.util.codec.binary.Base64; @@ -90,17 +90,13 @@ private Claims checkTokenValidation(String token, JwtParser parser) { try { return parser.parseClaimsJws(token).getBody(); } catch (MalformedJwtException e) { - log.error("Invalid JWT token"); - throw new AuthenticationFailedException(ErrorCode.TOKEN_INVALID); + throw new KeymeUnauthorizedException(ErrorCode.TOKEN_INVALID); } catch (ExpiredJwtException e) { - log.error("Expired JWT token"); - throw new AuthenticationFailedException(ErrorCode.TOKEN_EXPIRED); + throw new KeymeUnauthorizedException(ErrorCode.TOKEN_EXPIRED); } catch (UnsupportedJwtException e) { - log.error("Unsupported JWT token"); - throw new AuthenticationFailedException(ErrorCode.TOKEN_INVALID); + throw new KeymeUnauthorizedException(ErrorCode.TOKEN_INVALID); } catch (IllegalArgumentException e) { - log.error("JWT claims string is empty."); - throw new AuthenticationFailedException(ErrorCode.UNAUTHORIZED); + throw new KeymeUnauthorizedException(ErrorCode.UNAUTHORIZED); } } } diff --git a/src/main/java/com/nexters/keyme/member/application/MemberService.java b/src/main/java/com/nexters/keyme/member/application/MemberService.java deleted file mode 100644 index 096061f1..00000000 --- a/src/main/java/com/nexters/keyme/member/application/MemberService.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.nexters.keyme.member.application; - -import com.nexters.keyme.auth.domain.internaldto.OAuthUserInfo; -import com.nexters.keyme.auth.domain.internaldto.UserInfo; -import com.nexters.keyme.member.presentation.dto.request.AddTokenRequest; -import com.nexters.keyme.member.presentation.dto.request.DeleteTokenRequest; -import com.nexters.keyme.member.presentation.dto.request.MemberModificationRequest; -import com.nexters.keyme.member.presentation.dto.request.NicknameVerificationRequest; -import com.nexters.keyme.member.presentation.dto.response.ImageResponse; -import com.nexters.keyme.member.presentation.dto.response.NicknameVerificationResponse; -import com.nexters.keyme.member.presentation.dto.response.MemberResponse; -import com.nexters.keyme.member.presentation.dto.response.MemberWithTokenResponse; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.multipart.MultipartFile; - -public interface MemberService { - MemberWithTokenResponse getOrCreateMember(OAuthUserInfo oauthUserInfo); - - MemberResponse getMemberInfo(Long memberId); - - NicknameVerificationResponse verifyNickname(NicknameVerificationRequest request); - - MemberResponse modifyMemberInfo(MemberModificationRequest request, UserInfo userInfo); - - ImageResponse uploadImage(MultipartFile image); - - @Transactional - void registerDeviceToken(long userId, AddTokenRequest request); - - void deleteDeviceToken(long memberId, DeleteTokenRequest request); -} diff --git a/src/main/java/com/nexters/keyme/member/domain/exceptions/NicknameVerificationException.java b/src/main/java/com/nexters/keyme/member/domain/exceptions/NicknameVerificationException.java deleted file mode 100644 index 549a0d5e..00000000 --- a/src/main/java/com/nexters/keyme/member/domain/exceptions/NicknameVerificationException.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.nexters.keyme.member.domain.exceptions; - -import com.nexters.keyme.member.domain.state.MemberStateCode; -import lombok.Getter; - -public class NicknameVerificationException extends RuntimeException { - - private MemberStateCode code; - - public NicknameVerificationException(MemberStateCode stateCode) { - this.code = stateCode; - } - - public int getCode() { return this.code.code(); } - public String getMessage() { return this.code.message(); } -} diff --git a/src/main/java/com/nexters/keyme/member/domain/model/MemberStatus.java b/src/main/java/com/nexters/keyme/member/domain/model/MemberStatus.java deleted file mode 100644 index 5cc0f958..00000000 --- a/src/main/java/com/nexters/keyme/member/domain/model/MemberStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.nexters.keyme.member.domain.model; - -public enum MemberStatus { - ACTIVE -} diff --git a/src/main/java/com/nexters/keyme/member/domain/repository/MemberOAuthRepository.java b/src/main/java/com/nexters/keyme/member/domain/repository/MemberOAuthRepository.java deleted file mode 100644 index 3903b49c..00000000 --- a/src/main/java/com/nexters/keyme/member/domain/repository/MemberOAuthRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.nexters.keyme.member.domain.repository; - -import com.nexters.keyme.member.domain.model.MemberOAuth; -import com.nexters.keyme.member.domain.model.MemberOAuthId; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface MemberOAuthRepository extends JpaRepository { -} diff --git a/src/main/java/com/nexters/keyme/member/domain/state/MemberStateCode.java b/src/main/java/com/nexters/keyme/member/domain/state/MemberStateCode.java deleted file mode 100644 index 9239a119..00000000 --- a/src/main/java/com/nexters/keyme/member/domain/state/MemberStateCode.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.nexters.keyme.member.domain.state; - -public enum MemberStateCode { - DUPLICATED_NICKNAME("이미 사용 중인 닉네임입니다.", 200), - NICKNAME_TOO_LONG("닉네임은 7자 이하여야 합니다.", 200); - - private final String message; - private final int code; - - MemberStateCode(String message, int code) { - this.message = message; - this.code = code; - } - - public int code() { return this.code; } - - public String message() { - return this.message; - } -} diff --git a/src/main/java/com/nexters/keyme/member/presentation/handler/MemberStateHandler.java b/src/main/java/com/nexters/keyme/member/presentation/handler/MemberStateHandler.java deleted file mode 100644 index 852764ac..00000000 --- a/src/main/java/com/nexters/keyme/member/presentation/handler/MemberStateHandler.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.nexters.keyme.member.presentation.handler; - - -import com.nexters.keyme.common.dto.response.ApiResponse; -import com.nexters.keyme.member.domain.exceptions.NicknameVerificationException; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; - -@ControllerAdvice -public class MemberStateHandler { - @ExceptionHandler(NicknameVerificationException.class) - public ResponseEntity handleNicknameVerificationException(NicknameVerificationException e) { - return ResponseEntity.status(HttpStatus.OK).body(new ApiResponse<>(e.getCode(), e.getMessage(), null)); - } -} diff --git a/src/main/java/com/nexters/keyme/question/application/QuestionService.java b/src/main/java/com/nexters/keyme/question/application/QuestionService.java deleted file mode 100644 index aa6497ba..00000000 --- a/src/main/java/com/nexters/keyme/question/application/QuestionService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.nexters.keyme.question.application; - -import com.nexters.keyme.common.dto.response.PageResponse; -import com.nexters.keyme.question.presentation.dto.request.QuestionScoreListRequest; -import com.nexters.keyme.question.presentation.dto.request.QuestionListScoreRequest; -import com.nexters.keyme.question.presentation.dto.request.QuestionStatisticRequest; -import com.nexters.keyme.question.presentation.dto.response.*; - -import java.util.List; - -public interface QuestionService { - QuestionResponse getQuestion(Long questionId); - QuestionStatisticResponse getQuestionStatistic(Long questionId, QuestionStatisticRequest request); - PageResponse getQuestionSolvedList(Long questionId, QuestionScoreListRequest request); - List getQuestionSolvedScore(QuestionListScoreRequest request); -} \ No newline at end of file diff --git a/src/main/java/com/nexters/keyme/question/domain/repository/QuestionBundleRepository.java b/src/main/java/com/nexters/keyme/question/domain/repository/QuestionBundleRepository.java deleted file mode 100644 index 4f155b2f..00000000 --- a/src/main/java/com/nexters/keyme/question/domain/repository/QuestionBundleRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.nexters.keyme.question.domain.repository; - -import com.nexters.keyme.question.domain.model.Question; -import com.nexters.keyme.question.domain.model.QuestionBundle; -import com.nexters.keyme.question.domain.model.QuestionBundleId; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -public interface QuestionBundleRepository extends JpaRepository { -} diff --git a/src/main/java/com/nexters/keyme/question/domain/repository/QuestionSolvedRepositoryCustom.java b/src/main/java/com/nexters/keyme/question/domain/repository/QuestionSolvedRepositoryCustom.java deleted file mode 100644 index 51b3e642..00000000 --- a/src/main/java/com/nexters/keyme/question/domain/repository/QuestionSolvedRepositoryCustom.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.nexters.keyme.question.domain.repository; - -import com.nexters.keyme.common.dto.internal.PageInfo; -import com.nexters.keyme.question.domain.model.QuestionSolved; -import org.springframework.data.domain.Page; - -import java.util.List; - -public interface QuestionSolvedRepositoryCustom { - PageInfo findQuestionSolvedList( - Long questionId, - Long questionOwnerId, - Long cursorId, - int limit - ); -} diff --git a/src/main/java/com/nexters/keyme/statistics/application/StatisticService.java b/src/main/java/com/nexters/keyme/statistics/application/StatisticService.java deleted file mode 100644 index a724878a..00000000 --- a/src/main/java/com/nexters/keyme/statistics/application/StatisticService.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.nexters.keyme.statistics.application; - -import com.nexters.keyme.statistics.application.dto.ScoreInfo; -import com.nexters.keyme.statistics.domain.internaldto.StatisticInfo; -import com.nexters.keyme.statistics.domain.model.Statistic; -import com.nexters.keyme.statistics.presentation.dto.AdditionalStatisticRequest; -import com.nexters.keyme.statistics.presentation.dto.AdditionalStatisticResponse; -import com.nexters.keyme.statistics.presentation.dto.request.StatisticRequest; -import com.nexters.keyme.statistics.presentation.dto.response.MemberStatisticResponse; - -import java.util.List; - -public interface StatisticService { - Statistic createStatistic(StatisticInfo statisticInfo); - void addNewScores(ScoreInfo request); - - MemberStatisticResponse getMemberStatistic(long memberId, StatisticRequest request); - - List getAdditionalStatistics (long memberId, AdditionalStatisticRequest request); -} diff --git a/src/main/java/com/nexters/keyme/statistics/domain/service/CoordinateConversionService.java b/src/main/java/com/nexters/keyme/statistics/domain/service/CoordinateConversionService.java deleted file mode 100644 index 563ec91f..00000000 --- a/src/main/java/com/nexters/keyme/statistics/domain/service/CoordinateConversionService.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.nexters.keyme.statistics.domain.service; - -import com.nexters.keyme.statistics.domain.internaldto.CoordinateInfo; -import com.nexters.keyme.statistics.domain.model.Statistic; - -import java.util.List; - -public interface CoordinateConversionService { - List convertFrom(List statistics); -} diff --git a/src/main/java/com/nexters/keyme/test/domain/repository/TestResultRepository.java b/src/main/java/com/nexters/keyme/test/domain/repository/TestResultRepository.java deleted file mode 100644 index 915d81bf..00000000 --- a/src/main/java/com/nexters/keyme/test/domain/repository/TestResultRepository.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.nexters.keyme.test.domain.repository; - -import com.nexters.keyme.member.domain.model.MemberEntity; -import com.nexters.keyme.question.domain.internaldto.QuestionStatisticInfo; -import com.nexters.keyme.test.domain.internaldto.TestResultStatisticInfo; -import com.nexters.keyme.test.domain.model.Test; -import com.nexters.keyme.test.domain.model.TestResult; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; -import java.util.Optional; - -public interface TestResultRepository extends JpaRepository { - Optional findByTestAndSolver(Test test, MemberEntity solver); - - @Query( - "select new com.nexters.keyme.test.domain.internaldto.TestResultStatisticInfo(avg(tr.matchRate), COUNT(*)) from TestResult tr " + - "where tr.test.testId = :testId" - ) - Optional findStatisticsByTestId(Long testId); -} diff --git a/src/test/java/com/nexters/keyme/clienttest/application/ClientTestServiceImplTest.java b/src/test/java/com/nexters/keyme/clienttest/application/ClientTestServiceImplTest.java index f6e1d714..72a4a537 100644 --- a/src/test/java/com/nexters/keyme/clienttest/application/ClientTestServiceImplTest.java +++ b/src/test/java/com/nexters/keyme/clienttest/application/ClientTestServiceImplTest.java @@ -1,6 +1,7 @@ package com.nexters.keyme.clienttest.application; -import com.nexters.keyme.member.domain.repository.MemberRepository; +import com.nexters.keyme.domain.clienttest.application.ClientTestService; +import com.nexters.keyme.domain.member.domain.repository.MemberRepository; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -9,8 +10,6 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.transaction.annotation.Transactional; -import static org.junit.jupiter.api.Assertions.*; - @SpringBootTest @Transactional @ActiveProfiles("test") diff --git a/src/test/java/com/nexters/keyme/member/application/MemberServiceTest.java b/src/test/java/com/nexters/keyme/member/application/MemberServiceTest.java index fddb1d00..942f31b9 100644 --- a/src/test/java/com/nexters/keyme/member/application/MemberServiceTest.java +++ b/src/test/java/com/nexters/keyme/member/application/MemberServiceTest.java @@ -1,11 +1,13 @@ package com.nexters.keyme.member.application; -import com.nexters.keyme.auth.domain.internaldto.UserInfo; -import com.nexters.keyme.member.domain.exceptions.NicknameVerificationException; -import com.nexters.keyme.member.presentation.dto.request.MemberModificationRequest; -import com.nexters.keyme.member.presentation.dto.request.NicknameVerificationRequest; -import com.nexters.keyme.member.presentation.dto.response.NicknameVerificationResponse; -import com.nexters.keyme.member.presentation.dto.response.MemberResponse; +import com.nexters.keyme.domain.member.domain.exceptions.NicknameDuplicateException; +import com.nexters.keyme.global.dto.internal.UserInfo; +import com.nexters.keyme.domain.member.application.MemberService; +import com.nexters.keyme.domain.member.presentation.dto.request.MemberModificationRequest; +import com.nexters.keyme.domain.member.presentation.dto.request.NicknameVerificationRequest; +import com.nexters.keyme.domain.member.presentation.dto.response.NicknameVerificationResponse; +import com.nexters.keyme.domain.member.presentation.dto.response.MemberResponse; +import com.nexters.keyme.global.exceptions.KeymeSuccessInfoException; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -45,7 +47,7 @@ void getMemberInfo() { void verifyNickname() { NicknameVerificationRequest request = new NicknameVerificationRequest("nick"); NicknameVerificationRequest finalRequest = request; - assertThatThrownBy(() -> memberService.verifyNickname(finalRequest)).isInstanceOf(NicknameVerificationException.class); + assertThatThrownBy(() -> memberService.verifyNickname(finalRequest)).isInstanceOf(NicknameDuplicateException.class); request = new NicknameVerificationRequest("tom"); NicknameVerificationResponse response = memberService.verifyNickname(request); diff --git a/src/test/java/com/nexters/keyme/member/domain/model/MemberEntityTest.java b/src/test/java/com/nexters/keyme/member/domain/model/MemberEntityTest.java index 51136bfb..97343da6 100644 --- a/src/test/java/com/nexters/keyme/member/domain/model/MemberEntityTest.java +++ b/src/test/java/com/nexters/keyme/member/domain/model/MemberEntityTest.java @@ -1,6 +1,8 @@ package com.nexters.keyme.member.domain.model; -import com.nexters.keyme.member.domain.internaldto.MemberModificationInfo; +import com.nexters.keyme.domain.member.domain.internaldto.MemberModificationInfo; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.member.domain.model.ProfileImage; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/nexters/keyme/member/domain/repository/MemberDeviceRepositoryTest.java b/src/test/java/com/nexters/keyme/member/domain/repository/MemberDeviceRepositoryTest.java index 2b48edcb..0e10a11b 100644 --- a/src/test/java/com/nexters/keyme/member/domain/repository/MemberDeviceRepositoryTest.java +++ b/src/test/java/com/nexters/keyme/member/domain/repository/MemberDeviceRepositoryTest.java @@ -1,7 +1,7 @@ package com.nexters.keyme.member.domain.repository; -import com.nexters.keyme.common.exceptions.ResourceNotFoundException; -import com.nexters.keyme.member.domain.model.MemberDevice; +import com.nexters.keyme.domain.member.domain.repository.MemberDeviceRepository; +import com.nexters.keyme.domain.member.domain.model.MemberDevice; import com.nexters.keyme.test.annotation.RepositoryTest; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -19,7 +19,7 @@ class MemberDeviceRepositoryTest { @DisplayName("멤버 id와 토큰으로 Device 조회") void findByMemberIdAndToken() { MemberDevice device = memberDeviceRepository.findByMemberIdAndToken(1L, "token1") - .orElseThrow(ResourceNotFoundException::new); + .orElseThrow(RuntimeException::new); Assertions.assertThat(device.getId()).isEqualTo(1L); Assertions.assertThat(device.getToken()).isEqualTo("token1"); diff --git a/src/test/java/com/nexters/keyme/member/domain/repository/MemberRepositoryTest.java b/src/test/java/com/nexters/keyme/member/domain/repository/MemberRepositoryTest.java index c5a6e8a5..c633662e 100644 --- a/src/test/java/com/nexters/keyme/member/domain/repository/MemberRepositoryTest.java +++ b/src/test/java/com/nexters/keyme/member/domain/repository/MemberRepositoryTest.java @@ -1,7 +1,8 @@ package com.nexters.keyme.member.domain.repository; -import com.nexters.keyme.common.exceptions.ResourceNotFoundException; -import com.nexters.keyme.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.member.domain.exceptions.NotFoundMemberException; +import com.nexters.keyme.domain.member.domain.repository.MemberRepository; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; import com.nexters.keyme.test.annotation.RepositoryTest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -30,11 +31,11 @@ class MemberRepositoryTest { @DisplayName("닉네임으로 멤버 엔티티 찾기 테스트") void findByNickname() { assertThatThrownBy(() -> { - memberRepository.findByNickname("tom").orElseThrow(ResourceNotFoundException::new); - }).isInstanceOf(ResourceNotFoundException.class); + memberRepository.findByNickname("tom").orElseThrow(NotFoundMemberException::new); + }).isInstanceOf(NotFoundMemberException.class); MemberEntity member = memberRepository.findByNickname("nick") - .orElseThrow(ResourceNotFoundException::new); + .orElseThrow(NotFoundMemberException::new); assertThat(member.getNickname()).isEqualTo("nick"); } @@ -43,11 +44,11 @@ void findByNickname() { @DisplayName("초대코드로 멤버 엔티티 찾기 테스트") void findByInviteCode() { assertThatThrownBy(() -> { - memberRepository.findByFriendCode("ZXCVBNV").orElseThrow(ResourceNotFoundException::new); - }).isInstanceOf(ResourceNotFoundException.class); + memberRepository.findByFriendCode("ZXCVBNV").orElseThrow(NotFoundMemberException::new); + }).isInstanceOf(NotFoundMemberException.class); MemberEntity member = memberRepository.findByFriendCode("1234567") - .orElseThrow(ResourceNotFoundException::new); + .orElseThrow(NotFoundMemberException::new); assertThat(member.getFriendCode()).isEqualTo("1234567"); } diff --git a/src/test/java/com/nexters/keyme/member/domain/service/NicknameValidatorTest.java b/src/test/java/com/nexters/keyme/member/domain/service/NicknameValidatorTest.java index 9d2e2a5d..8039dabf 100644 --- a/src/test/java/com/nexters/keyme/member/domain/service/NicknameValidatorTest.java +++ b/src/test/java/com/nexters/keyme/member/domain/service/NicknameValidatorTest.java @@ -1,8 +1,10 @@ package com.nexters.keyme.member.domain.service; -import com.nexters.keyme.member.domain.exceptions.NicknameVerificationException; -import com.nexters.keyme.member.domain.model.MemberEntity; -import com.nexters.keyme.member.domain.repository.MemberRepository; +import com.nexters.keyme.domain.member.domain.exceptions.NicknameDuplicateException; +import com.nexters.keyme.domain.member.domain.exceptions.NicknameTooLongException; +import com.nexters.keyme.domain.member.domain.model.MemberEntity; +import com.nexters.keyme.domain.member.domain.repository.MemberRepository; +import com.nexters.keyme.domain.member.domain.service.NicknameValidator; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -28,12 +30,11 @@ class NicknameValidatorTest { @DisplayName("닉네임 유효성 검사 테스트") void validateNickname() { Mockito.when(memberRepository.findByNickname("sample")).thenReturn(Optional.of(new MemberEntity())); - assertThatThrownBy(() -> validator.validateNickname("sample")).isInstanceOf(NicknameVerificationException.class); + assertThatThrownBy(() -> validator.validateNickname("sample")).isInstanceOf(NicknameDuplicateException.class); - assertThatThrownBy(() -> validator.validateNickname("sample1234")).isInstanceOf(NicknameVerificationException.class); - assertThatThrownBy(() -> validator.validateNickname("너무긴한글닉네임")).isInstanceOf(NicknameVerificationException.class); + assertThatThrownBy(() -> validator.validateNickname("sample1234")).isInstanceOf(NicknameTooLongException.class); + assertThatThrownBy(() -> validator.validateNickname("너무긴한글닉네임")).isInstanceOf(NicknameTooLongException.class); - assertThatThrownBy(() -> validator.validateNickname("sample1")).isInstanceOf(NicknameVerificationException.class); assertThat(validator.validateNickname("sam123").isValid()).isTrue(); assertThat(validator.validateNickname("한글닉네임").isValid()).isTrue(); } diff --git a/src/test/java/com/nexters/keyme/notification/service/NotificationServiceTest.java b/src/test/java/com/nexters/keyme/notification/service/NotificationServiceTest.java index 7f8636b2..16d1d521 100644 --- a/src/test/java/com/nexters/keyme/notification/service/NotificationServiceTest.java +++ b/src/test/java/com/nexters/keyme/notification/service/NotificationServiceTest.java @@ -1,6 +1,7 @@ package com.nexters.keyme.notification.service; -import com.nexters.keyme.notification.dto.UserNotificationRequest; +import com.nexters.keyme.domain.notification.dto.UserNotificationRequest; +import com.nexters.keyme.domain.notification.service.NotificationService; import org.assertj.core.api.Assertions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; diff --git a/src/test/java/com/nexters/keyme/question/domain/repository/QuestionSolvedRepositoryTest.java b/src/test/java/com/nexters/keyme/question/domain/repository/QuestionSolvedRepositoryTest.java index b3abc0f9..8744626d 100644 --- a/src/test/java/com/nexters/keyme/question/domain/repository/QuestionSolvedRepositoryTest.java +++ b/src/test/java/com/nexters/keyme/question/domain/repository/QuestionSolvedRepositoryTest.java @@ -1,9 +1,10 @@ package com.nexters.keyme.question.domain.repository; -import com.nexters.keyme.common.dto.internal.PageInfo; -import com.nexters.keyme.question.domain.enums.QuestionCategoryType; -import com.nexters.keyme.question.domain.internaldto.QuestionStatisticInfo; -import com.nexters.keyme.question.domain.model.QuestionSolved; +import com.nexters.keyme.domain.question.domain.repository.QuestionSolvedRepository; +import com.nexters.keyme.global.dto.internal.PageInfo; +import com.nexters.keyme.domain.question.domain.enums.QuestionCategoryType; +import com.nexters.keyme.domain.question.domain.internaldto.QuestionStatisticInfo; +import com.nexters.keyme.domain.question.domain.model.QuestionSolved; import com.nexters.keyme.test.annotation.RepositoryTest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/nexters/keyme/statistics/application/StatisticServiceTest.java b/src/test/java/com/nexters/keyme/statistics/application/StatisticServiceTest.java index 4def1718..921f8930 100644 --- a/src/test/java/com/nexters/keyme/statistics/application/StatisticServiceTest.java +++ b/src/test/java/com/nexters/keyme/statistics/application/StatisticServiceTest.java @@ -1,16 +1,17 @@ package com.nexters.keyme.statistics.application; -import com.nexters.keyme.question.presentation.dto.response.QuestionCategoryResponse; -import com.nexters.keyme.statistics.application.dto.ScoreInfo; -import com.nexters.keyme.statistics.domain.internaldto.StatisticInfo; -import com.nexters.keyme.statistics.domain.model.Statistic; -import com.nexters.keyme.statistics.presentation.dto.AdditionalStatisticRequest; -import com.nexters.keyme.statistics.presentation.dto.AdditionalStatisticResponse; -import com.nexters.keyme.statistics.presentation.dto.request.StatisticRequest; -import com.nexters.keyme.statistics.presentation.dto.response.CoordinateResponse; -import com.nexters.keyme.statistics.presentation.dto.response.MemberStatisticResponse; -import com.nexters.keyme.statistics.presentation.dto.response.StatisticQuestionResponse; -import com.nexters.keyme.statistics.presentation.dto.response.StatisticResultResponse; +import com.nexters.keyme.domain.question.presentation.dto.response.QuestionCategoryResponse; +import com.nexters.keyme.domain.statistics.application.StatisticService; +import com.nexters.keyme.domain.statistics.application.dto.ScoreInfo; +import com.nexters.keyme.domain.statistics.domain.internaldto.StatisticInfo; +import com.nexters.keyme.domain.statistics.domain.model.Statistic; +import com.nexters.keyme.domain.statistics.presentation.dto.AdditionalStatisticRequest; +import com.nexters.keyme.domain.statistics.presentation.dto.AdditionalStatisticResponse; +import com.nexters.keyme.domain.statistics.presentation.dto.request.StatisticRequest; +import com.nexters.keyme.domain.statistics.presentation.dto.response.CoordinateResponse; +import com.nexters.keyme.domain.statistics.presentation.dto.response.MemberStatisticResponse; +import com.nexters.keyme.domain.statistics.presentation.dto.response.StatisticQuestionResponse; +import com.nexters.keyme.domain.statistics.presentation.dto.response.StatisticResultResponse; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/test/java/com/nexters/keyme/statistics/domain/model/StatisticTest.java b/src/test/java/com/nexters/keyme/statistics/domain/model/StatisticTest.java index f253a902..9785861a 100644 --- a/src/test/java/com/nexters/keyme/statistics/domain/model/StatisticTest.java +++ b/src/test/java/com/nexters/keyme/statistics/domain/model/StatisticTest.java @@ -1,5 +1,6 @@ package com.nexters.keyme.statistics.domain.model; +import com.nexters.keyme.domain.statistics.domain.model.Statistic; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/nexters/keyme/statistics/domain/repository/StatisticRepositoryTest.java b/src/test/java/com/nexters/keyme/statistics/domain/repository/StatisticRepositoryTest.java index 34204193..41c9a8e6 100644 --- a/src/test/java/com/nexters/keyme/statistics/domain/repository/StatisticRepositoryTest.java +++ b/src/test/java/com/nexters/keyme/statistics/domain/repository/StatisticRepositoryTest.java @@ -1,7 +1,8 @@ package com.nexters.keyme.statistics.domain.repository; -import com.nexters.keyme.common.exceptions.ResourceNotFoundException; -import com.nexters.keyme.statistics.domain.model.Statistic; +import com.nexters.keyme.domain.statistics.domain.exceptions.NotFoundStatisticsException; +import com.nexters.keyme.domain.statistics.domain.repository.StatisticRepository; +import com.nexters.keyme.domain.statistics.domain.model.Statistic; import com.nexters.keyme.test.annotation.RepositoryTest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -20,7 +21,7 @@ class StatisticRepositoryTest { @DisplayName("통계 정보 가져오기 테스트") void findByOwnerIdAndQuestionIdWithLock() { Statistic statistic = statisticRepository.findByOwnerIdAndQuestionIdWithLock(1, 2) - .orElseThrow(ResourceNotFoundException::new); + .orElseThrow(NotFoundStatisticsException::new); assertThat(statistic.getQuestionId()).isEqualTo(2L); assertThat(statistic.getOwnerId()).isEqualTo(1L); diff --git a/src/test/java/com/nexters/keyme/test/annotation/RepositoryTest.java b/src/test/java/com/nexters/keyme/test/annotation/RepositoryTest.java index d9e64dfb..e9738b0a 100644 --- a/src/test/java/com/nexters/keyme/test/annotation/RepositoryTest.java +++ b/src/test/java/com/nexters/keyme/test/annotation/RepositoryTest.java @@ -1,6 +1,6 @@ package com.nexters.keyme.test.annotation; -import com.nexters.keyme.common.config.QueryDslConfig; +import com.nexters.keyme.global.config.QueryDslConfig; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; import org.springframework.test.context.ActiveProfiles;