Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

얽혀있는 의존성 및 리팩토링이 필요한 부분을 수정했습니다 #97

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 10 additions & 21 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
}

Expand All @@ -20,33 +19,23 @@ 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")

// SpringMockk
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("com.ninja-squad:springmockk:3.1.1")

testRuntimeOnly("com.h2database:h2")
}

jacoco {
Expand Down Expand Up @@ -146,11 +135,11 @@ subprojects {
}
}

tasks.bootJar {
tasks.getByName("bootJar") {
enabled = false
}

tasks.jar {
tasks.getByName("jar") {
enabled = true
}
}
}
5 changes: 4 additions & 1 deletion raisedragon-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -95,4 +95,4 @@ class AuthApplicationService(
refreshToken = jwtToken.refreshToken
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ApiExceptionHandler {
@ExceptionHandler(BaseException::class)
private fun handleBaseException(exception: BaseException): ResponseEntity<Response<Unit>> {
return ResponseEntity
.status(exception.exceptionCode.httpStatus)
.status(exception.exceptionCode.httpStatusCode)
.body(Response.fail(exception))
}

Expand All @@ -90,4 +90,4 @@ class ApiExceptionHandler {
companion object {
const val DETAIL_MESSAGE_BY_PARAMETER_EXCEPTION = "Please Check Your Request Parameter"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data class Response<T>(
return Response(
isSuccess = false,
errorResponse = ErrorResponse(
code = exceptionCode.code,
code = exceptionCode.errorCode,
detailMessage = detailMessage ?: exceptionCode.message
)
)
Expand All @@ -34,7 +34,7 @@ data class Response<T>(
return Response(
isSuccess = false,
errorResponse = ErrorResponse(
code = exception.exceptionCode.code,
code = exception.exceptionCode.errorCode,
detailMessage = exception.message
)
)
Expand All @@ -45,4 +45,4 @@ data class Response<T>(
data class ErrorResponse(
val code: String,
val detailMessage: String?
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@ 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

@Aspect
@Component
class AuthAspect(
private val httpServletRequest: HttpServletRequest,
private val userRepository: UserRepository,
private val userService: UserService,
private val jwtAgent: JwtAgent
) {

Expand All @@ -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)
Expand All @@ -53,4 +47,4 @@ class AuthAspect(
private const val PREFIX_BEARER = "Bearer "
private const val BASE_PACKAGE = "com.whatever.raisedragon.common.aop.auth.Auth"
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -363,4 +363,4 @@ class BettingApplicationServiceTest : ApplicationServiceTestSupport {
endDate = endDateTime
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -389,4 +389,4 @@ class GoalGifticonApplicationServiceTest : ApplicationServiceTestSupport {
endDate = endDateTime
)
}
}
}
Original file line number Diff line number Diff line change
@@ -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
)
}
val errorCode: String
get() = httpStatusCode.toString()
}
6 changes: 5 additions & 1 deletion raisedragon-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -11,6 +13,8 @@ dependencies {

// jasypt
implementation("com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.5")

testRuntimeOnly("com.h2database:h2")
}

allOpen {
Expand Down
5 changes: 4 additions & 1 deletion raisedragon-external/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
dependencies {
// aws
implementation("org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE")
}

// RestTemplate
implementation("org.springframework:spring-webmvc")
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
}
Loading
Loading