From d861d29fb87259cc722105e6ccc2348acb5d5ce3 Mon Sep 17 00:00:00 2001 From: "Jaemin.Park" Date: Mon, 24 Jun 2024 17:44:49 +0900 Subject: [PATCH 1/3] Move authorizing kakao client logic to external module from core --- .../auth/AuthApplicationService.kt | 4 +-- .../whatever/raisedragon/aws/s3/S3Agent.kt | 13 --------- .../raisedragon/external/aws/s3/S3Agent.kt | 22 +++++++++++++++ .../{ => external}/aws/s3/S3AgentImpl.kt | 28 +++++++++++-------- .../{aws => external/config}/AwsConfig.kt | 4 +-- .../external}/config/RestTemplateConfig.kt | 4 +-- .../{aws/s3 => external/config}/S3Config.kt | 4 +-- .../external/oauth}/AuthService.kt | 4 +-- .../oauth/kakao/KakaoLoginResponse.kt | 4 +-- .../oauth/kakao/KakaoOAuthService.kt | 6 ++-- 10 files changed, 54 insertions(+), 39 deletions(-) delete mode 100644 raisedragon-external/src/main/kotlin/com/whatever/raisedragon/aws/s3/S3Agent.kt create mode 100644 raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/aws/s3/S3Agent.kt rename raisedragon-external/src/main/kotlin/com/whatever/raisedragon/{ => external}/aws/s3/S3AgentImpl.kt (54%) rename raisedragon-external/src/main/kotlin/com/whatever/raisedragon/{aws => external/config}/AwsConfig.kt (86%) rename {raisedragon-core/src/main/kotlin/com/whatever/raisedragon/common => raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external}/config/RestTemplateConfig.kt (85%) rename raisedragon-external/src/main/kotlin/com/whatever/raisedragon/{aws/s3 => external/config}/S3Config.kt (96%) rename {raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/auth => raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/oauth}/AuthService.kt (90%) rename {raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/auth => raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external}/oauth/kakao/KakaoLoginResponse.kt (81%) rename {raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/auth => raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external}/oauth/kakao/KakaoOAuthService.kt (88%) diff --git a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/applicationservice/auth/AuthApplicationService.kt b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/applicationservice/auth/AuthApplicationService.kt index 70c5a12..33459eb 100644 --- a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/applicationservice/auth/AuthApplicationService.kt +++ b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/applicationservice/auth/AuthApplicationService.kt @@ -5,11 +5,11 @@ import com.whatever.raisedragon.applicationservice.auth.dto.LoginServiceRequest import com.whatever.raisedragon.applicationservice.auth.dto.TokenRefreshResponse import com.whatever.raisedragon.common.exception.BaseException import com.whatever.raisedragon.common.exception.ExceptionCode -import com.whatever.raisedragon.domain.auth.AuthService import com.whatever.raisedragon.domain.refreshtoken.RefreshTokenService import com.whatever.raisedragon.domain.user.Nickname import com.whatever.raisedragon.domain.user.User import com.whatever.raisedragon.domain.user.UserService +import com.whatever.raisedragon.external.oauth.AuthService import com.whatever.raisedragon.security.jwt.JwtAgent import com.whatever.raisedragon.security.jwt.JwtToken import org.springframework.stereotype.Service @@ -95,4 +95,4 @@ class AuthApplicationService( refreshToken = jwtToken.refreshToken ) } -} \ No newline at end of file +} diff --git a/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/aws/s3/S3Agent.kt b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/aws/s3/S3Agent.kt deleted file mode 100644 index 121df17..0000000 --- a/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/aws/s3/S3Agent.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.whatever.raisedragon.aws.s3 - -import org.springframework.web.multipart.MultipartFile - -interface S3Agent { - - /** - * @param directory S3 버킷에 파일을 저장할 Directory 이름입니다. - * @param multipartFile 사용자가 전송한 정적파일입니다. - * @return 해당 파일을 S3에 업로드 한 이후, 해당 파일에 접근할 수 있는 url을 반환해합니다. - */ - fun upload(directory: String, file: MultipartFile): String -} \ No newline at end of file diff --git a/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/aws/s3/S3Agent.kt b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/aws/s3/S3Agent.kt new file mode 100644 index 0000000..900a092 --- /dev/null +++ b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/aws/s3/S3Agent.kt @@ -0,0 +1,22 @@ +package com.whatever.raisedragon.external.aws.s3 + +import org.springframework.core.io.InputStreamSource + +interface S3Agent { + + /** + * @param fileInputStreamSource 사용자가 전송할 파일 InputStreamSource 입니다. + * @param directoryName S3 버킷에 파일을 저장할 Directory 이름입니다. + * @param originalFileName 사용자가 전송할 정적파일의 원본 파일 이름입니다. + * @param contentType 사용자가 전송할 파일 contentType 입니다. + * @param size 사용자가 전송할 파일의 크기 입니다. + * @return 해당 파일을 S3에 업로드 한 이후, 해당 파일에 접근할 수 있는 url을 반환해합니다. + */ + fun upload( + fileInputStreamSource: InputStreamSource, + directoryName: String, + originalFileName: String, + contentType: String, + size: Long + ): String +} diff --git a/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/aws/s3/S3AgentImpl.kt b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/aws/s3/S3AgentImpl.kt similarity index 54% rename from raisedragon-external/src/main/kotlin/com/whatever/raisedragon/aws/s3/S3AgentImpl.kt rename to raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/aws/s3/S3AgentImpl.kt index a22f3a7..ac94e1e 100644 --- a/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/aws/s3/S3AgentImpl.kt +++ b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/aws/s3/S3AgentImpl.kt @@ -1,11 +1,12 @@ -package com.whatever.raisedragon.aws.s3 +package com.whatever.raisedragon.external.aws.s3 import com.amazonaws.AmazonServiceException import com.amazonaws.services.s3.AmazonS3 import com.amazonaws.services.s3.model.ObjectMetadata +import com.whatever.raisedragon.external.config.S3Config import org.springframework.context.annotation.Profile +import org.springframework.core.io.InputStreamSource import org.springframework.stereotype.Component -import org.springframework.web.multipart.MultipartFile import java.io.IOException import java.util.* @@ -15,13 +16,18 @@ class S3AgentImpl( private val amazonS3: AmazonS3, private val s3Properties: S3Config.S3Properties ) : S3Agent { - override fun upload(directory: String, file: MultipartFile): String { - val fileName = String.format("%s%s-%s", directory, UUID.randomUUID(), file.originalFilename) + override fun upload( + fileInputStreamSource: InputStreamSource, + directoryName: String, + originalFileName: String, + contentType: String, + size: Long + ): String { + val fileName = String.format("%s%s-%s", directoryName, UUID.randomUUID(), originalFileName) val bucket = s3Properties.bucketName runCatching { - val objectMetadata = getObjectMetadataFromFile(file) - val inputStream = file.inputStream - amazonS3.putObject(bucket, fileName, inputStream, objectMetadata) + val objectMetadata = makeObjectMetadataFromFile(contentType, size) + amazonS3.putObject(bucket, fileName, fileInputStreamSource.inputStream, objectMetadata) }.onFailure { exception -> when (exception) { is IOException -> throw IllegalStateException("S3 File I/O Error", exception) @@ -34,10 +40,10 @@ class S3AgentImpl( return "${s3Properties.domain}/$fileName" } - private fun getObjectMetadataFromFile(imageFile: MultipartFile): ObjectMetadata { + private fun makeObjectMetadataFromFile(contentType: String, size: Long): ObjectMetadata { return ObjectMetadata().apply { - contentType = imageFile.contentType - contentLength = imageFile.size + this.contentType = contentType + this.contentLength = size } } -} \ No newline at end of file +} diff --git a/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/aws/AwsConfig.kt b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/config/AwsConfig.kt similarity index 86% rename from raisedragon-external/src/main/kotlin/com/whatever/raisedragon/aws/AwsConfig.kt rename to raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/config/AwsConfig.kt index df4e11e..d9145ee 100644 --- a/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/aws/AwsConfig.kt +++ b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/config/AwsConfig.kt @@ -1,4 +1,4 @@ -package com.whatever.raisedragon.aws +package com.whatever.raisedragon.external.config import org.springframework.cloud.aws.autoconfigure.context.ContextCredentialsAutoConfiguration import org.springframework.cloud.aws.autoconfigure.context.ContextRegionProviderAutoConfiguration @@ -7,4 +7,4 @@ import org.springframework.context.annotation.Import @Configuration @Import(ContextCredentialsAutoConfiguration::class, ContextRegionProviderAutoConfiguration::class) -class AwsConfig \ No newline at end of file +class AwsConfig diff --git a/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/common/config/RestTemplateConfig.kt b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/config/RestTemplateConfig.kt similarity index 85% rename from raisedragon-core/src/main/kotlin/com/whatever/raisedragon/common/config/RestTemplateConfig.kt rename to raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/config/RestTemplateConfig.kt index 9507b62..a564098 100644 --- a/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/common/config/RestTemplateConfig.kt +++ b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/config/RestTemplateConfig.kt @@ -1,4 +1,4 @@ -package com.whatever.raisedragon.common.config +package com.whatever.raisedragon.external.config import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @@ -11,4 +11,4 @@ class RestTemplateConfig { fun restTemplate(): RestTemplate { return RestTemplate() } -} \ No newline at end of file +} diff --git a/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/aws/s3/S3Config.kt b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/config/S3Config.kt similarity index 96% rename from raisedragon-external/src/main/kotlin/com/whatever/raisedragon/aws/s3/S3Config.kt rename to raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/config/S3Config.kt index a2048a7..94a190e 100644 --- a/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/aws/s3/S3Config.kt +++ b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/config/S3Config.kt @@ -1,4 +1,4 @@ -package com.whatever.raisedragon.aws.s3 +package com.whatever.raisedragon.external.config import com.amazonaws.auth.AWSStaticCredentialsProvider import com.amazonaws.auth.BasicAWSCredentials @@ -33,4 +33,4 @@ class S3Config { @ConfigurationProperties(prefix = "cloud.aws.s3") data class S3Properties(val domain: String, val bucketName: String) -} \ No newline at end of file +} diff --git a/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/auth/AuthService.kt b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/oauth/AuthService.kt similarity index 90% rename from raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/auth/AuthService.kt rename to raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/oauth/AuthService.kt index 043c1f9..c515c25 100644 --- a/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/auth/AuthService.kt +++ b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/oauth/AuthService.kt @@ -1,4 +1,4 @@ -package com.whatever.raisedragon.domain.auth +package com.whatever.raisedragon.external.oauth interface AuthService { /** @@ -8,4 +8,4 @@ interface AuthService { * @return 사용자의 카카오 유저 아이디. 반환 값이 없거나 유효하지 않은 토큰인 경우 null을 반환합니다. */ fun verifyKaKao(userToken: String): String -} \ No newline at end of file +} diff --git a/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/auth/oauth/kakao/KakaoLoginResponse.kt b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/oauth/kakao/KakaoLoginResponse.kt similarity index 81% rename from raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/auth/oauth/kakao/KakaoLoginResponse.kt rename to raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/oauth/kakao/KakaoLoginResponse.kt index 91e8f35..aa3b950 100644 --- a/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/auth/oauth/kakao/KakaoLoginResponse.kt +++ b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/oauth/kakao/KakaoLoginResponse.kt @@ -1,4 +1,4 @@ -package com.whatever.raisedragon.domain.auth.oauth.kakao +package com.whatever.raisedragon.external.oauth.kakao import com.fasterxml.jackson.annotation.JsonProperty import java.time.LocalDateTime @@ -9,4 +9,4 @@ data class KakaoLoginResponse( @JsonProperty("connected_at") val connectedAt: LocalDateTime? = null, -) \ No newline at end of file +) diff --git a/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/auth/oauth/kakao/KakaoOAuthService.kt b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/oauth/kakao/KakaoOAuthService.kt similarity index 88% rename from raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/auth/oauth/kakao/KakaoOAuthService.kt rename to raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/oauth/kakao/KakaoOAuthService.kt index c55f199..8f71e9d 100644 --- a/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/auth/oauth/kakao/KakaoOAuthService.kt +++ b/raisedragon-external/src/main/kotlin/com/whatever/raisedragon/external/oauth/kakao/KakaoOAuthService.kt @@ -1,6 +1,6 @@ -package com.whatever.raisedragon.domain.auth.oauth.kakao +package com.whatever.raisedragon.external.oauth.kakao -import com.whatever.raisedragon.domain.auth.AuthService +import com.whatever.raisedragon.external.oauth.AuthService import org.springframework.http.HttpEntity import org.springframework.http.HttpHeaders import org.springframework.http.MediaType @@ -31,4 +31,4 @@ class KakaoOAuthService( return response.body?.id!! } -} \ No newline at end of file +} From afc8ced3509c1aa20875b1b4ed6f08b6b3ca22ff Mon Sep 17 00:00:00 2001 From: "Jaemin.Park" Date: Mon, 24 Jun 2024 17:45:43 +0900 Subject: [PATCH 2/3] Remove huge dependency from S3 file uploader --- .../raisedragon/infra/s3/S3ApplicationService.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/infra/s3/S3ApplicationService.kt b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/infra/s3/S3ApplicationService.kt index eb5f4ad..23bcb05 100644 --- a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/infra/s3/S3ApplicationService.kt +++ b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/infra/s3/S3ApplicationService.kt @@ -1,6 +1,6 @@ package com.whatever.raisedragon.infra.s3 -import com.whatever.raisedragon.aws.s3.S3Agent +import com.whatever.raisedragon.external.aws.s3.S3Agent import org.springframework.context.annotation.Profile import org.springframework.stereotype.Service import org.springframework.web.multipart.MultipartFile @@ -12,10 +12,19 @@ class S3ApplicationService( ) : FileUploader { override fun upload(multipartFile: MultipartFile): String { - return s3Agent.upload(S3_PREFIX_DIRECTORY, multipartFile) + return s3Agent.upload( + fileInputStreamSource = multipartFile, + directoryName = S3_PREFIX_DIRECTORY, + originalFileName = multipartFile.originalFilename ?: DEFAULT_ORIGINAL_FILE_NAME, + contentType = multipartFile.contentType ?: DEFAULT_CONTENT_TYPE, + size = multipartFile.size + ) } companion object { private const val S3_PREFIX_DIRECTORY = "gifticon/" + + private const val DEFAULT_ORIGINAL_FILE_NAME = "default-file-name" + private const val DEFAULT_CONTENT_TYPE = "multipart/form-data" } -} \ No newline at end of file +} From 67ef367b633689129e9504a693853a05256c8902 Mon Sep 17 00:00:00 2001 From: "Jaemin.Park" Date: Mon, 24 Jun 2024 17:45:56 +0900 Subject: [PATCH 3/3] Fix seprated dependencies --- build.gradle.kts | 31 ++++++------------- raisedragon-api/build.gradle.kts | 5 ++- .../raisedragon/common/ApiExceptionHandler.kt | 4 +-- .../whatever/raisedragon/common/Response.kt | 6 ++-- .../raisedragon/common/aop/auth/AuthAspect.kt | 14 +++------ .../betting/BettingApplicationServiceTest.kt | 4 +-- .../GoalGifticonApplicationServiceTest.kt | 4 +-- .../common/exception/ExceptionCode.kt | 31 +++++++------------ raisedragon-core/build.gradle.kts | 6 +++- raisedragon-external/build.gradle.kts | 5 ++- 10 files changed, 48 insertions(+), 62 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 58e588d..d81995f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,11 +1,10 @@ plugins { - id("org.springframework.boot") version "3.2.0" - id("io.spring.dependency-management") version "1.1.4" - id("application") kotlin("jvm") version "1.9.20" - kotlin("plugin.spring") version "1.9.20" - kotlin("plugin.jpa") version "1.9.20" kotlin("kapt") version "1.6.21" + kotlin("plugin.spring") version "1.9.20" apply false + kotlin("plugin.jpa") version "1.9.20" apply false + id("org.springframework.boot") version "3.2.0" apply false + id("io.spring.dependency-management") version "1.1.4" apply false jacoco } @@ -20,24 +19,16 @@ allprojects { } } -application { - mainClass = "com.whatever.raisedragon.RaiseDragonApiApplicationKt" -} - subprojects { apply(plugin = "org.jetbrains.kotlin.jvm") + apply(plugin = "kotlin-kapt") apply(plugin = "org.jetbrains.kotlin.plugin.spring") apply(plugin = "org.springframework.boot") - apply(plugin = "kotlin") - apply(plugin = "java-library") - apply(plugin = "kotlin-jpa") - apply(plugin = "io.spring.dependency-management") - apply(plugin = "kotlin-kapt") - apply(plugin = "application") apply(plugin = "jacoco") + apply(plugin = "io.spring.dependency-management") dependencies { - implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.springframework.boot:spring-boot-starter") implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("io.github.microutils:kotlin-logging:2.0.8") implementation("org.jetbrains.kotlin:kotlin-reflect") @@ -45,8 +36,6 @@ subprojects { // SpringMockk testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("com.ninja-squad:springmockk:3.1.1") - - testRuntimeOnly("com.h2database:h2") } jacoco { @@ -146,11 +135,11 @@ subprojects { } } - tasks.bootJar { + tasks.getByName("bootJar") { enabled = false } - tasks.jar { + tasks.getByName("jar") { enabled = true } -} \ No newline at end of file +} diff --git a/raisedragon-api/build.gradle.kts b/raisedragon-api/build.gradle.kts index 0a73dd0..1d9ffd8 100644 --- a/raisedragon-api/build.gradle.kts +++ b/raisedragon-api/build.gradle.kts @@ -12,11 +12,12 @@ dependencies { implementation(project(":raisedragon-common")) implementation(project(":raisedragon-core")) implementation(project(":raisedragon-external")) - api("org.springframework.boot:spring-boot-starter-data-jpa:3.0.4") + implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.springframework.boot:spring-boot-starter-validation:3.0.4") implementation("org.springframework.boot:spring-boot-starter-aop:3.0.4") implementation("org.springframework.boot:spring-boot-starter-security:3.0.4") + implementation("org.springframework:spring-tx:6.1.1") // Swagger implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:$swaggerVersion") @@ -27,4 +28,6 @@ dependencies { implementation("io.jsonwebtoken:jjwt-jackson:0.11.5") testImplementation("org.springframework.security:spring-security-test") + testRuntimeOnly("com.h2database:h2") + testApi("org.springframework.boot:spring-boot-starter-data-jpa:3.0.4") } diff --git a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/common/ApiExceptionHandler.kt b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/common/ApiExceptionHandler.kt index fc7ce32..6b11f8b 100644 --- a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/common/ApiExceptionHandler.kt +++ b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/common/ApiExceptionHandler.kt @@ -74,7 +74,7 @@ class ApiExceptionHandler { @ExceptionHandler(BaseException::class) private fun handleBaseException(exception: BaseException): ResponseEntity> { return ResponseEntity - .status(exception.exceptionCode.httpStatus) + .status(exception.exceptionCode.httpStatusCode) .body(Response.fail(exception)) } @@ -90,4 +90,4 @@ class ApiExceptionHandler { companion object { const val DETAIL_MESSAGE_BY_PARAMETER_EXCEPTION = "Please Check Your Request Parameter" } -} \ No newline at end of file +} diff --git a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/common/Response.kt b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/common/Response.kt index 88f313e..793550f 100644 --- a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/common/Response.kt +++ b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/common/Response.kt @@ -24,7 +24,7 @@ data class Response( return Response( isSuccess = false, errorResponse = ErrorResponse( - code = exceptionCode.code, + code = exceptionCode.errorCode, detailMessage = detailMessage ?: exceptionCode.message ) ) @@ -34,7 +34,7 @@ data class Response( return Response( isSuccess = false, errorResponse = ErrorResponse( - code = exception.exceptionCode.code, + code = exception.exceptionCode.errorCode, detailMessage = exception.message ) ) @@ -45,4 +45,4 @@ data class Response( data class ErrorResponse( val code: String, val detailMessage: String? -) \ No newline at end of file +) diff --git a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/common/aop/auth/AuthAspect.kt b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/common/aop/auth/AuthAspect.kt index f25123e..fb4075e 100644 --- a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/common/aop/auth/AuthAspect.kt +++ b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/common/aop/auth/AuthAspect.kt @@ -2,14 +2,12 @@ package com.whatever.raisedragon.common.aop.auth import com.whatever.raisedragon.common.exception.BaseException import com.whatever.raisedragon.common.exception.ExceptionCode -import com.whatever.raisedragon.domain.user.UserRepository -import com.whatever.raisedragon.domain.user.toDto +import com.whatever.raisedragon.domain.user.UserService import com.whatever.raisedragon.security.jwt.JwtAgent import jakarta.servlet.http.HttpServletRequest import org.aspectj.lang.ProceedingJoinPoint import org.aspectj.lang.annotation.Around import org.aspectj.lang.annotation.Aspect -import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Component import org.springframework.util.StringUtils @@ -17,7 +15,7 @@ import org.springframework.util.StringUtils @Component class AuthAspect( private val httpServletRequest: HttpServletRequest, - private val userRepository: UserRepository, + private val userService: UserService, private val jwtAgent: JwtAgent ) { @@ -29,11 +27,7 @@ class AuthAspect( ) val userId = jwtAgent.extractUserId(token).toString().toLong() - val user = userRepository.findByIdOrNull(userId)?.toDto() - ?: throw BaseException.of( - exceptionCode = ExceptionCode.E404_NOT_FOUND, - executionMessage = "존재하지 않는 유저입니다." - ) + val user = userService.findById(userId) AuthContext.USER_CONTEXT.set(user) return pjp.proceed(pjp.args) @@ -53,4 +47,4 @@ class AuthAspect( private const val PREFIX_BEARER = "Bearer " private const val BASE_PACKAGE = "com.whatever.raisedragon.common.aop.auth.Auth" } -} \ No newline at end of file +} diff --git a/raisedragon-api/src/test/kotlin/com/whatever/raisedragon/applicationservice/betting/BettingApplicationServiceTest.kt b/raisedragon-api/src/test/kotlin/com/whatever/raisedragon/applicationservice/betting/BettingApplicationServiceTest.kt index c659630..efcda0d 100644 --- a/raisedragon-api/src/test/kotlin/com/whatever/raisedragon/applicationservice/betting/BettingApplicationServiceTest.kt +++ b/raisedragon-api/src/test/kotlin/com/whatever/raisedragon/applicationservice/betting/BettingApplicationServiceTest.kt @@ -12,11 +12,11 @@ import com.whatever.raisedragon.domain.goal.GoalType.* import com.whatever.raisedragon.domain.user.Nickname import com.whatever.raisedragon.domain.user.UserEntity import com.whatever.raisedragon.domain.user.UserRepository -import jakarta.transaction.Transactional import org.assertj.core.api.Assertions.* import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired +import org.springframework.transaction.annotation.Transactional import java.time.LocalDateTime @Transactional @@ -363,4 +363,4 @@ class BettingApplicationServiceTest : ApplicationServiceTestSupport { endDate = endDateTime ) } -} \ No newline at end of file +} diff --git a/raisedragon-api/src/test/kotlin/com/whatever/raisedragon/applicationservice/goalgifticon/GoalGifticonApplicationServiceTest.kt b/raisedragon-api/src/test/kotlin/com/whatever/raisedragon/applicationservice/goalgifticon/GoalGifticonApplicationServiceTest.kt index 3563901..3f8bc98 100644 --- a/raisedragon-api/src/test/kotlin/com/whatever/raisedragon/applicationservice/goalgifticon/GoalGifticonApplicationServiceTest.kt +++ b/raisedragon-api/src/test/kotlin/com/whatever/raisedragon/applicationservice/goalgifticon/GoalGifticonApplicationServiceTest.kt @@ -20,12 +20,12 @@ import com.whatever.raisedragon.domain.user.UserEntity import com.whatever.raisedragon.domain.user.UserRepository import com.whatever.raisedragon.domain.winner.WinnerEntity import com.whatever.raisedragon.domain.winner.WinnerRepository -import jakarta.transaction.Transactional import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired +import org.springframework.transaction.annotation.Transactional import java.time.LocalDateTime @Transactional @@ -389,4 +389,4 @@ class GoalGifticonApplicationServiceTest : ApplicationServiceTestSupport { endDate = endDateTime ) } -} \ No newline at end of file +} diff --git a/raisedragon-common/src/main/kotlin/com/whatever/raisedragon/common/exception/ExceptionCode.kt b/raisedragon-common/src/main/kotlin/com/whatever/raisedragon/common/exception/ExceptionCode.kt index 60cf783..aa3fd4c 100644 --- a/raisedragon-common/src/main/kotlin/com/whatever/raisedragon/common/exception/ExceptionCode.kt +++ b/raisedragon-common/src/main/kotlin/com/whatever/raisedragon/common/exception/ExceptionCode.kt @@ -1,40 +1,33 @@ package com.whatever.raisedragon.common.exception -import org.springframework.http.HttpStatus - enum class ExceptionCode( - val httpStatus: HttpStatus, - val code: String, + val httpStatusCode: Int, val message: String, ) { - E400_BAD_REQUEST(HttpStatus.BAD_REQUEST, "400", "필수 파라미터 값이 없거나 잘못된 값으로 요청을 보낸 경우 발생"), + E400_BAD_REQUEST( 400, "필수 파라미터 값이 없거나 잘못된 값으로 요청을 보낸 경우 발생"), // ------------------------------ 401 ------------------------------ - E401_UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "401", "유효하지 않은 인증 토큰을 사용한 경우 발생"), + E401_UNAUTHORIZED(401, "유효하지 않은 인증 토큰을 사용한 경우 발생"), // ------------------------------ 403 ------------------------------ - E403_FORBIDDEN(HttpStatus.FORBIDDEN, "403", "사용 권한이 없는 경우 발생"), + E403_FORBIDDEN(403, "사용 권한이 없는 경우 발생"), // ------------------------------ 404 ------------------------------ - E404_NOT_FOUND(HttpStatus.NOT_FOUND, "404", "요청한 리소스가 존재하지 않는 경우 발생"), + E404_NOT_FOUND(404, "요청한 리소스가 존재하지 않는 경우 발생"), // ------------------------------ 405 ------------------------------ - E405_METHOD_NOT_ALLOWED(HttpStatus.METHOD_NOT_ALLOWED, "405", "HTTP Method가 잘못된 경우"), + E405_METHOD_NOT_ALLOWED(405, "HTTP Method가 잘못된 경우"), // ------------------------------ 409 ------------------------------ - E409_CONFLICT(HttpStatus.CONFLICT, "409", "요청한 리소스가 중복된 경우 발생"), + E409_CONFLICT(409, "요청한 리소스가 중복된 경우 발생"), // ------------------------------ 500 ------------------------------ - E500_INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "500", "서버 내부에 문제 발생"), + E500_INTERNAL_SERVER_ERROR(500, "서버 내부에 문제 발생"), // ------------------------------ 501 ------------------------------ - E501_NOT_IMPLEMENTED(HttpStatus.NOT_IMPLEMENTED, "501", "지원하지 않는 타입의 요청"), -} + E501_NOT_IMPLEMENTED(501, "지원하지 않는 타입의 요청"); -fun ExceptionCode.throwAsException() { - throw BaseException.of( - exceptionCode = this, - executionMessage = message - ) -} \ No newline at end of file + val errorCode: String + get() = httpStatusCode.toString() +} diff --git a/raisedragon-core/build.gradle.kts b/raisedragon-core/build.gradle.kts index dc65551..efad95f 100644 --- a/raisedragon-core/build.gradle.kts +++ b/raisedragon-core/build.gradle.kts @@ -1,7 +1,9 @@ +apply(plugin = "kotlin-jpa") + dependencies { implementation(project(":raisedragon-common")) implementation("org.springframework.boot:spring-boot-starter-data-jpa:3.0.4") - runtimeOnly("com.mysql:mysql-connector-j:8.0.32") + runtimeOnly("com.mysql:mysql-connector-j:8.2.0") // querydsl implementation("com.querydsl:querydsl-jpa:5.0.0:jakarta") @@ -11,6 +13,8 @@ dependencies { // jasypt implementation("com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.5") + + testRuntimeOnly("com.h2database:h2") } allOpen { diff --git a/raisedragon-external/build.gradle.kts b/raisedragon-external/build.gradle.kts index a27eb54..dc7abed 100644 --- a/raisedragon-external/build.gradle.kts +++ b/raisedragon-external/build.gradle.kts @@ -1,4 +1,7 @@ dependencies { // aws implementation("org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE") -} \ No newline at end of file + + // RestTemplate + implementation("org.springframework:spring-webmvc") +}