From 104481a74f3779a23d08c0aa5b34072bf78dcdae Mon Sep 17 00:00:00 2001 From: dldmsql Date: Sun, 22 Sep 2024 09:39:26 +0900 Subject: [PATCH] =?UTF-8?q?feat:=204=EC=B0=A8=20MVP=20=EA=B8=B0=ED=9A=8D?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/dto/BoardCreateRequest.kt | 4 +- .../board/controller/dto/BoardGetResponse.kt | 9 +- .../domain/board/my/dto/MyBoardDto.kt | 11 +++ .../domain/board/service/BoardService.kt | 9 +- .../controller/BoardStickerController.kt | 40 -------- .../board/sticker/dto/StickerCreateRequest.kt | 10 -- .../board/sticker/dto/StickerGetResponse.kt | 9 -- .../repository/BoardStickerRepository.kt | 11 --- .../repository/BoardStickerRepositoryImpl.kt | 65 ------------- .../board/sticker/service/StickerService.kt | 20 ---- .../dto/ImageResignedUrlResponse.kt | 4 + .../domain/oauth/service/OauthService.kt | 97 ++++++++----------- .../controller/BoardPolaroidController.kt | 2 +- .../controller/BoardPolaroidV2Controller.kt | 4 +- .../polaroid/controller/PolaroidController.kt | 2 +- .../controller/dto/PolaroidCreateRequest.kt | 18 ---- .../controller/dto/PolaroidGetResponse.kt | 25 ----- .../polaroid/dto/PolaroidCreateRequest.kt | 18 ++++ .../polaroid/dto/PolaroidGetResponse.kt | 25 +++++ .../repository/PolaroidJooqRepository.kt | 2 +- .../repository/PolaroidJooqRepositoryImpl.kt | 2 +- .../polaroid/service/PolaroidService.kt | 4 +- .../domain/user/controller/UserController.kt | 3 - .../sonnypolabobe/domain/user/dto/UserDto.kt | 22 ++++- .../domain/user/service/UserService.kt | 2 +- .../user/{ => withdraw}/dto/WithdrawType.kt | 2 +- .../repository/WithdrawJooqRepository.kt | 2 +- .../repository/WithdrawJooqRepositoryImpl.kt | 2 +- .../global/HealthCheckController.kt | 4 +- .../global/config/JasyptConfig.kt | 24 ++--- .../global/config/SwaggerConfig.kt | 13 ++- .../sonnypolabobe/global/entity/PageDto.kt | 1 - .../exception/GlobalExceptionHandler.kt | 2 +- .../security/CustomUserDetailsService.kt | 5 +- .../global/security/JwtExceptionFilter.kt | 4 +- .../sonnypolabobe/global/security/JwtUtil.kt | 15 ++- .../sonnypolabobe/global/security/KakaoDto.kt | 43 -------- .../security/RateLimitingInterceptor.kt | 7 +- .../global/security/RateLimitingService.kt | 4 +- .../global/util/DateConverter.kt | 11 +-- .../global/util/DiscordApiClient.kt | 52 ++++------ .../ddd/sonnypolabobe/global/util/HttpLog.kt | 12 --- .../ddd/sonnypolabobe/global/util/S3Util.kt | 15 +-- .../global/util/UuidConverter.kt | 17 ++-- .../global/util/UuidGenerator.kt | 4 +- .../global/util/WebClientUtil.kt | 28 ------ 46 files changed, 210 insertions(+), 475 deletions(-) delete mode 100644 src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/controller/BoardStickerController.kt delete mode 100644 src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/dto/StickerCreateRequest.kt delete mode 100644 src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/dto/StickerGetResponse.kt delete mode 100644 src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/repository/BoardStickerRepository.kt delete mode 100644 src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/repository/BoardStickerRepositoryImpl.kt delete mode 100644 src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/service/StickerService.kt delete mode 100644 src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/dto/PolaroidCreateRequest.kt delete mode 100644 src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/dto/PolaroidGetResponse.kt create mode 100644 src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/dto/PolaroidCreateRequest.kt create mode 100644 src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/dto/PolaroidGetResponse.kt rename src/main/kotlin/com/ddd/sonnypolabobe/domain/user/{ => withdraw}/dto/WithdrawType.kt (83%) rename src/main/kotlin/com/ddd/sonnypolabobe/domain/user/{ => withdraw}/repository/WithdrawJooqRepository.kt (72%) rename src/main/kotlin/com/ddd/sonnypolabobe/domain/user/{ => withdraw}/repository/WithdrawJooqRepositoryImpl.kt (94%) delete mode 100644 src/main/kotlin/com/ddd/sonnypolabobe/global/security/KakaoDto.kt delete mode 100644 src/main/kotlin/com/ddd/sonnypolabobe/global/util/HttpLog.kt delete mode 100644 src/main/kotlin/com/ddd/sonnypolabobe/global/util/WebClientUtil.kt diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/controller/dto/BoardCreateRequest.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/controller/dto/BoardCreateRequest.kt index 422042b..fdb3cf6 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/controller/dto/BoardCreateRequest.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/controller/dto/BoardCreateRequest.kt @@ -6,10 +6,10 @@ import jakarta.validation.constraints.Pattern import java.util.* data class BoardCreateRequest( - @Schema(description = "제목", example = "쏘니의 보드") + @field:Schema(description = "제목", example = "쏘니의 보드") @field:NotBlank @field:Pattern(regexp = "^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!@#$%^&*()_+=-])(?=.*[ㄱ-ㅎㅏ-ㅣ가-힣]).{1,20}$", message = "제목은 국문, 영문, 숫자, 특수문자, 띄어쓰기를 포함한 20자 이내여야 합니다.") val title: String, - @Schema(description = "작성자 아이디", example = "null", required = false) + @field:Schema(description = "작성자 아이디", example = "null", required = false) var userId: Long? = null ) diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/controller/dto/BoardGetResponse.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/controller/dto/BoardGetResponse.kt index 787e8c7..7c644c1 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/controller/dto/BoardGetResponse.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/controller/dto/BoardGetResponse.kt @@ -1,14 +1,11 @@ package com.ddd.sonnypolabobe.domain.board.controller.dto -import com.ddd.sonnypolabobe.domain.board.sticker.dto.StickerGetResponse -import com.ddd.sonnypolabobe.domain.polaroid.controller.dto.PolaroidGetResponse +import com.ddd.sonnypolabobe.domain.polaroid.dto.PolaroidGetResponse import io.swagger.v3.oas.annotations.media.Schema data class BoardGetResponse( - @Schema(description = "제목", example = "쏘니의 보드") + @field:Schema(description = "제목", example = "쏘니의 보드") val title: String, - @Schema(description = "폴라로이드") + @field:Schema(description = "폴라로이드") val items: List, - @Schema(description = "스티커 리스트") - val stickers : List? ) \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/my/dto/MyBoardDto.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/my/dto/MyBoardDto.kt index 9aa647f..82cc0de 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/my/dto/MyBoardDto.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/my/dto/MyBoardDto.kt @@ -1,6 +1,7 @@ package com.ddd.sonnypolabobe.domain.board.my.dto import com.fasterxml.jackson.annotation.JsonProperty +import io.swagger.v3.oas.annotations.media.Schema import org.springframework.format.annotation.DateTimeFormat import java.time.LocalDateTime import java.util.UUID @@ -9,26 +10,36 @@ class MyBoardDto { companion object { data class MBUpdateReq( @JsonProperty("title") + @field:Schema(description = "제목", example = "쏘니의 보드") val title: String ) data class PageListRes( + @field:Schema(description = "보드 아이디", example = "01906259-94b2-74ef-8c13-554385c42943") val id: UUID, + @field:Schema(description = "제목", example = "쏘니의 보드") val title: String, @DateTimeFormat(pattern = "yyyy-MM-dd", iso = DateTimeFormat.ISO.DATE) + @field:Schema(description = "생성일", example = "2021-07-01") val createdAt: LocalDateTime, ) data class GetOneRes( + @field:Schema(description = "보드 아이디", example = "01906259-94b2-74ef-8c13-554385c42943") val id: UUID, + @field:Schema(description = "제목", example = "쏘니의 보드") val title: String, @DateTimeFormat(pattern = "yyyy-MM-dd", iso = DateTimeFormat.ISO.DATE) + @field:Schema(description = "생성일", example = "2021-07-01") val createdAt: LocalDateTime, + @field:Schema(description = "작성자 아이디", example = "null", required = false) val userId: Long? ) data class TotalCountRes( + @field:Schema(description = "총 보드 생성 수", example = "100") val totalCreateCount: Long, + @field:Schema(description = "총 참여자 수", example = "1000") val totalParticipantCount: Long ) diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/service/BoardService.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/service/BoardService.kt index e5f715d..eff43dc 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/service/BoardService.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/service/BoardService.kt @@ -3,9 +3,7 @@ package com.ddd.sonnypolabobe.domain.board.service import com.ddd.sonnypolabobe.domain.board.controller.dto.BoardCreateRequest import com.ddd.sonnypolabobe.domain.board.controller.dto.BoardGetResponse import com.ddd.sonnypolabobe.domain.board.repository.BoardJooqRepository -import com.ddd.sonnypolabobe.domain.board.sticker.dto.StickerGetResponse -import com.ddd.sonnypolabobe.domain.board.sticker.repository.BoardStickerRepository -import com.ddd.sonnypolabobe.domain.polaroid.controller.dto.PolaroidGetResponse +import com.ddd.sonnypolabobe.domain.polaroid.dto.PolaroidGetResponse import com.ddd.sonnypolabobe.domain.polaroid.enumerate.PolaroidOption import com.ddd.sonnypolabobe.domain.user.dto.UserDto import com.ddd.sonnypolabobe.global.exception.ApplicationException @@ -18,12 +16,10 @@ import com.fasterxml.jackson.databind.ObjectMapper import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service import java.util.* -import javax.swing.text.html.HTML.Tag.U @Service class BoardService( private val boardJooqRepository: BoardJooqRepository, - private val boardStickerRepository: BoardStickerRepository, private val s3Util: S3Util, @Value("\${limit.count}") private val limit: Int @@ -36,7 +32,6 @@ class BoardService( return id.run { val queryResult = boardJooqRepository.selectOneById(UuidConverter.stringToUUID(this@run)) - val stickers = boardStickerRepository.findByBoardId(UuidConverter.stringToUUID(id)) val groupByTitle = queryResult.groupBy { it.title } groupByTitle.map { entry -> val title = entry.key @@ -53,7 +48,7 @@ class BoardService( ) }.filter { it.id != 0L }.distinctBy { it.id } - BoardGetResponse(title = title ?: "", items = polaroids, stickers = stickers) + BoardGetResponse(title = title ?: "", items = polaroids) } } } diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/controller/BoardStickerController.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/controller/BoardStickerController.kt deleted file mode 100644 index 2c7c60c..0000000 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/controller/BoardStickerController.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.ddd.sonnypolabobe.domain.board.sticker.controller - -import com.ddd.sonnypolabobe.domain.board.sticker.dto.StickerCreateRequest -import com.ddd.sonnypolabobe.domain.board.sticker.service.StickerService -import com.ddd.sonnypolabobe.global.response.ApplicationResponse -import com.ddd.sonnypolabobe.global.security.JwtUtil -import io.swagger.v3.oas.annotations.tags.Tag -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RequestHeader -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController - -@RestController -@RequestMapping("/api/v1/boards/sticker") -class BoardStickerController( - private val jwtUtil: JwtUtil, - private val stickerService: StickerService -) { - - @Tag(name = "1.3.0") - @GetMapping("/recent") - fun getRecentList( @RequestHeader("Authorization") token: String?) - : ApplicationResponse> { - val user = token?.let { this.jwtUtil.getAuthenticatedMemberFromToken(it) } - return ApplicationResponse.ok(this.stickerService.getByUserId(user?.id?.toLong())) - } - - @Tag(name = "1.3.0") - @PostMapping - fun createStickerToBoard( - @RequestHeader("Authorization") token: String?, - @RequestBody req : StickerCreateRequest - ) : ApplicationResponse { - val user = token?.let { this.jwtUtil.getAuthenticatedMemberFromToken(it) } - this.stickerService.create(req, user?.id?.toLong()) - return ApplicationResponse.ok() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/dto/StickerCreateRequest.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/dto/StickerCreateRequest.kt deleted file mode 100644 index 21a391d..0000000 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/dto/StickerCreateRequest.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.ddd.sonnypolabobe.domain.board.sticker.dto - -data class StickerCreateRequest( - val boardId : String, - val stickerId: String, - val x : String, - val y : String, - val scale: String, - val rotate: String -) diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/dto/StickerGetResponse.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/dto/StickerGetResponse.kt deleted file mode 100644 index a753316..0000000 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/dto/StickerGetResponse.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.ddd.sonnypolabobe.domain.board.sticker.dto - -data class StickerGetResponse( - val id : String, - val x : String, - val y : String, - val scale: String, - val rotate : String -) diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/repository/BoardStickerRepository.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/repository/BoardStickerRepository.kt deleted file mode 100644 index 63cc2d5..0000000 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/repository/BoardStickerRepository.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.ddd.sonnypolabobe.domain.board.sticker.repository - -import com.ddd.sonnypolabobe.domain.board.sticker.dto.StickerCreateRequest -import com.ddd.sonnypolabobe.domain.board.sticker.dto.StickerGetResponse -import java.util.* - -interface BoardStickerRepository { - fun findByUserId(id: Long) : List - fun insertOne(req: StickerCreateRequest, userId: Long?) - fun findByBoardId(stringToUUID: UUID): List? -} \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/repository/BoardStickerRepositoryImpl.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/repository/BoardStickerRepositoryImpl.kt deleted file mode 100644 index f04a7b9..0000000 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/repository/BoardStickerRepositoryImpl.kt +++ /dev/null @@ -1,65 +0,0 @@ -package com.ddd.sonnypolabobe.domain.board.sticker.repository - -import com.ddd.sonnypolabobe.domain.board.sticker.dto.StickerCreateRequest -import com.ddd.sonnypolabobe.domain.board.sticker.dto.StickerGetResponse -import com.ddd.sonnypolabobe.global.util.DateConverter -import com.ddd.sonnypolabobe.global.util.UuidConverter -import com.ddd.sonnypolabobe.jooq.polabo.tables.BoardSticker -import org.jooq.DSLContext -import org.springframework.stereotype.Repository -import java.time.LocalDateTime -import java.util.* - -@Repository -class BoardStickerRepositoryImpl( - private val dslContext: DSLContext -) : BoardStickerRepository { - override fun findByUserId(userId: Long): List { - val jSticker = BoardSticker.BOARD_STICKER - return this.dslContext.selectDistinct(jSticker.STICKER_ID) - .from(jSticker) - .where(jSticker.USER_ID.eq(userId)) - .orderBy(jSticker.CREATED_AT.desc()) - .fetchInto(String::class.java) - } - - override fun insertOne(req: StickerCreateRequest, userId: Long?) { - val jSticker = BoardSticker.BOARD_STICKER - this.dslContext.insertInto(jSticker) - .columns( - jSticker.STICKER_ID, - jSticker.BOARD_ID, - jSticker.USER_ID, - jSticker.X, - jSticker.Y, - jSticker.SCALE, - jSticker.ROTATE, - jSticker.CREATED_AT - ).values( - req.stickerId, - UuidConverter.uuidToByteArray(UuidConverter.stringToUUID(req.boardId)), - userId, - req.x, - req.y, - req.scale, - req.rotate, - DateConverter.convertToKst(LocalDateTime.now()) - ).execute() - } - - override fun findByBoardId(stringToUUID: UUID): List? { - val jSticker = BoardSticker.BOARD_STICKER - return this.dslContext.select( - jSticker.ID, - jSticker.X, - jSticker.Y, - jSticker.SCALE, - jSticker.ROTATE - ) - .from(jSticker) - .where(jSticker.BOARD_ID.eq(UuidConverter.uuidToByteArray(stringToUUID))) - .fetchInto(StickerGetResponse::class.java) - } - - -} \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/service/StickerService.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/service/StickerService.kt deleted file mode 100644 index 4266e3a..0000000 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/board/sticker/service/StickerService.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.ddd.sonnypolabobe.domain.board.sticker.service - -import com.ddd.sonnypolabobe.domain.board.sticker.dto.StickerCreateRequest -import com.ddd.sonnypolabobe.domain.board.sticker.repository.BoardStickerRepository -import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Transactional - -@Service -class StickerService( - private val boardStickerRepository: BoardStickerRepository -) { - @Transactional(readOnly = true) - fun getByUserId(id: Long?): List - = id?.let { this.boardStickerRepository.findByUserId(id) } ?: emptyList() - - @Transactional - fun create(req: StickerCreateRequest, userId: Long?) { - this.boardStickerRepository.insertOne(req, userId) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/file/controller/dto/ImageResignedUrlResponse.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/file/controller/dto/ImageResignedUrlResponse.kt index 5ddac9f..31982be 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/file/controller/dto/ImageResignedUrlResponse.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/file/controller/dto/ImageResignedUrlResponse.kt @@ -1,6 +1,10 @@ package com.ddd.sonnypolabobe.domain.file.controller.dto +import io.swagger.v3.oas.annotations.media.Schema + data class ImageResignedUrlResponse( + @field:Schema(description = "S3에 저장될 이미지 키", example = "imageKey") val imageKey : String, + @field:Schema(description = "이미지 업로드를 위한 URL", example = "https://cloudfront.net/imageKey") val url : String ) diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/oauth/service/OauthService.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/oauth/service/OauthService.kt index dc6ed19..2985484 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/oauth/service/OauthService.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/oauth/service/OauthService.kt @@ -7,35 +7,22 @@ import com.ddd.sonnypolabobe.domain.user.token.dto.UserTokenDto import com.ddd.sonnypolabobe.domain.user.token.repository.UserTokenJooqRepository import com.ddd.sonnypolabobe.global.security.JwtUtil import com.ddd.sonnypolabobe.global.util.DateConverter.dateToLocalDateTime -import com.ddd.sonnypolabobe.logger import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service class OauthService( - private val userRepository : UserJooqRepository, + private val userRepository: UserJooqRepository, + private val userTokenRepository: UserTokenJooqRepository, private val jwtUtil: JwtUtil, - private val userTokenRepository: UserTokenJooqRepository - ) { +) { @Transactional fun signIn(request: UserDto.Companion.CreateReq): UserDto.Companion.TokenRes { this.userRepository.findByEmail(request.email)?.let { - val tokenRequest = UserDto.Companion.CreateTokenReq( - id = it.id, - email = it.email, - nickName = it.nickName - ) - - val tokenRes = this.jwtUtil.generateAccessToken(tokenRequest) - - val userToken = UserTokenDto( - userId = it.id, - accessToken = tokenRes.accessToken, - expiredAt = dateToLocalDateTime(tokenRes.expiredDate), - refreshToken = tokenRes.refreshToken - ) + val tokenRes = generateAccessToken(it) + val userToken = userTokenDto(it.id, tokenRes) this.userTokenRepository.updateByUserId(userToken) return tokenRes.also { _ -> @@ -45,22 +32,8 @@ class OauthService( } } ?: run { val userId = this.userRepository.insertOne(request) - - // 토큰 생성 - val tokenRequest = UserDto.Companion.CreateTokenReq( - id = userId, - email = request.email, - nickName = request.nickName - ) - - val tokenRes = this.jwtUtil.generateAccessToken(tokenRequest) - - val userToken = UserTokenDto( - userId = userId, - accessToken = tokenRes.accessToken, - expiredAt = dateToLocalDateTime(tokenRes.expiredDate), - refreshToken = tokenRes.refreshToken - ) + val tokenRes = generateAccessToken(userId, request) + val userToken = userTokenDto(userId, tokenRes) this.userTokenRepository.insertOne(userToken) return tokenRes.also { _ -> @@ -71,34 +44,50 @@ class OauthService( } } - fun reIssue(token: String?): UserDto.Companion.TokenRes{ - val tokenFromDB = token?.let { - val slicedToken = if(it.startsWith("Bearer ")) it.substring(7) else it - this.jwtUtil.getAuthenticatedMemberFromRefreshToken(slicedToken) - } ?: throw RuntimeException("Token Not Found") - val user = this.userRepository.findById(tokenFromDB.id.toLong()) ?: throw RuntimeException("User Not Found") - - // 토큰 생성 - val tokenRequest = UserDto.Companion.CreateTokenReq( - id = user.id, - email = user.email, - nickName = user.nickName - ) + @Transactional + fun reIssue(token: String?): UserDto.Companion.TokenRes { + val tokenFromDB = token?.let { + val slicedToken = if (it.startsWith("Bearer ")) it.substring(7) else it + this.jwtUtil.getAuthenticatedMemberFromRefreshToken(slicedToken) + } ?: throw RuntimeException("Token Not Found") - val tokenRes = this.jwtUtil.generateAccessToken(tokenRequest) + val user = this.userRepository.findById(tokenFromDB.id.toLong()) + ?: throw RuntimeException("User Not Found") - val userToken = UserTokenDto( - userId = user.id, - accessToken = tokenRes.accessToken, - expiredAt = dateToLocalDateTime(tokenRes.expiredDate), - refreshToken = tokenRes.refreshToken - ) + val tokenRes = generateAccessToken(user) + val userToken = userTokenDto(user.id, tokenRes) this.userTokenRepository.updateByUserId(userToken) return tokenRes } + @Transactional fun signOut(id: Long) { this.userTokenRepository.deleteByUserId(id) } + + private fun userTokenDto( + userId: Long, + tokenRes: UserDto.Companion.TokenRes + ): UserTokenDto = UserTokenDto( + userId = userId, + accessToken = tokenRes.accessToken, + expiredAt = dateToLocalDateTime(tokenRes.expiredDate), + refreshToken = tokenRes.refreshToken + ) + + private fun OauthService.generateAccessToken( + userId: Long, request: UserDto.Companion.CreateReq + ): UserDto.Companion.TokenRes = this.jwtUtil.generateAccessToken( + UserDto.Companion.CreateTokenReq( + id = userId, email = request.email, nickName = request.nickName + ) + ) + + private fun OauthService.generateAccessToken(it: UserDto.Companion.Res): UserDto.Companion.TokenRes = + this.jwtUtil.generateAccessToken( + UserDto.Companion.CreateTokenReq( + id = it.id, email = it.email, nickName = it.nickName + ) + ) } \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/BoardPolaroidController.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/BoardPolaroidController.kt index c4a94e0..3fe2aa5 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/BoardPolaroidController.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/BoardPolaroidController.kt @@ -1,6 +1,6 @@ package com.ddd.sonnypolabobe.domain.polaroid.controller -import com.ddd.sonnypolabobe.domain.polaroid.controller.dto.PolaroidCreateRequest +import com.ddd.sonnypolabobe.domain.polaroid.dto.PolaroidCreateRequest import com.ddd.sonnypolabobe.domain.polaroid.service.PolaroidService import com.ddd.sonnypolabobe.global.response.ApplicationResponse import io.swagger.v3.oas.annotations.Operation diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/BoardPolaroidV2Controller.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/BoardPolaroidV2Controller.kt index 65937ae..d2a66c4 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/BoardPolaroidV2Controller.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/BoardPolaroidV2Controller.kt @@ -1,6 +1,6 @@ package com.ddd.sonnypolabobe.domain.polaroid.controller -import com.ddd.sonnypolabobe.domain.polaroid.controller.dto.PolaroidCreateRequest +import com.ddd.sonnypolabobe.domain.polaroid.dto.PolaroidCreateRequest import com.ddd.sonnypolabobe.domain.polaroid.enumerate.PolaroidOption import com.ddd.sonnypolabobe.domain.polaroid.service.PolaroidService import com.ddd.sonnypolabobe.global.response.ApplicationResponse @@ -21,9 +21,7 @@ class BoardPolaroidV2Controller( @Operation( summary = "폴라로이드 생성", description = """ 폴라로이드를 생성합니다. - 옵션을 추가했습니다. - enum에 따라 옵션을 선택해주세요. """ ) diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/PolaroidController.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/PolaroidController.kt index c94c1b3..787f0a2 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/PolaroidController.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/PolaroidController.kt @@ -1,6 +1,6 @@ package com.ddd.sonnypolabobe.domain.polaroid.controller -import com.ddd.sonnypolabobe.domain.polaroid.controller.dto.PolaroidGetResponse +import com.ddd.sonnypolabobe.domain.polaroid.dto.PolaroidGetResponse import com.ddd.sonnypolabobe.domain.polaroid.service.PolaroidService import com.ddd.sonnypolabobe.domain.user.dto.UserDto import com.ddd.sonnypolabobe.global.response.ApplicationResponse diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/dto/PolaroidCreateRequest.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/dto/PolaroidCreateRequest.kt deleted file mode 100644 index bc93322..0000000 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/dto/PolaroidCreateRequest.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.ddd.sonnypolabobe.domain.polaroid.controller.dto - -import com.ddd.sonnypolabobe.domain.polaroid.enumerate.PolaroidOption -import io.swagger.v3.oas.annotations.media.Schema -import jakarta.validation.constraints.Size - -@Schema(description = "폴라로이드 생성 요청 v2") -data class PolaroidCreateRequest( - @Schema(description = "이미지 키", example = "imageKey") - val imageKey : String, - @Schema(description = "한 줄 문구", example = "한 줄 메시지입니다. 최대 20자까지 가능합니다.") - @field:Size(max = 20) - val oneLineMessage : String, - @Schema(description = "작성자 닉네임이 null 이면서 회원가입된 유저라면, 유저의 닉네임을 자동할당합니다.", example = "작성자 닉네임") - var nickname : String?, - @Schema(description = "폴라로이드 옵션", examples = ["FONT", "FILTER", "THEMA"]) - val options : Map -) \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/dto/PolaroidGetResponse.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/dto/PolaroidGetResponse.kt deleted file mode 100644 index c382f82..0000000 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/controller/dto/PolaroidGetResponse.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.ddd.sonnypolabobe.domain.polaroid.controller.dto - -import com.ddd.sonnypolabobe.domain.polaroid.enumerate.PolaroidOption -import io.swagger.v3.oas.annotations.media.Schema -import java.time.LocalDateTime -import java.util.UUID - -data class PolaroidGetResponse( - @Schema(description = "폴라로이드 ID", example = "1") - val id: Long, - @Schema(description = "이미지 주소", example = "https://image.com/image.jpg") - val imageUrl: String, - @Schema(description = "한 줄 문구", example = "한 줄 메시지입니다.") - val oneLineMessage: String, - @Schema(description = "작성자 ID", example = "userId") - val userId: Long?, - @Schema(description = "작성자 닉네임", example = "nickname") - val nickname: String, - @Schema(description = "작성자인지 여부", example = "true") - val isMine: Boolean, - @Schema(description = "생성일시", example = "2021-01-01T00:00:00") - val createdAt: LocalDateTime?, - @Schema(description = "옵션") - val options: Map? -) diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/dto/PolaroidCreateRequest.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/dto/PolaroidCreateRequest.kt new file mode 100644 index 0000000..03bea72 --- /dev/null +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/dto/PolaroidCreateRequest.kt @@ -0,0 +1,18 @@ +package com.ddd.sonnypolabobe.domain.polaroid.dto + +import com.ddd.sonnypolabobe.domain.polaroid.enumerate.PolaroidOption +import io.swagger.v3.oas.annotations.media.Schema +import jakarta.validation.constraints.Size + +@Schema(description = "폴라로이드 생성 요청 v2") +data class PolaroidCreateRequest( + @field:Schema(description = "이미지 키", example = "imageKey") + val imageKey : String, + @field:Schema(description = "한 줄 문구", example = "한 줄 메시지입니다. 최대 20자까지 가능합니다.") + @field:Size(max = 20) + val oneLineMessage : String, + @field:Schema(description = "작성자 닉네임이 null 이면서 회원가입된 유저라면, 유저의 닉네임을 자동할당합니다.", example = "작성자 닉네임") + var nickname : String?, + @field:Schema(description = "폴라로이드 옵션", example = "{\"FONT\":\"value1\",\"FILTER\":\"value2\",\"THEMA\":\"value3\"}") + val options : Map +) \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/dto/PolaroidGetResponse.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/dto/PolaroidGetResponse.kt new file mode 100644 index 0000000..80e8901 --- /dev/null +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/dto/PolaroidGetResponse.kt @@ -0,0 +1,25 @@ +package com.ddd.sonnypolabobe.domain.polaroid.dto + +import com.ddd.sonnypolabobe.domain.polaroid.enumerate.PolaroidOption +import io.swagger.v3.oas.annotations.media.Schema +import java.time.LocalDateTime +import java.util.UUID + +data class PolaroidGetResponse( + @field:Schema(description = "폴라로이드 ID", example = "1") + val id: Long, + @field:Schema(description = "이미지 주소", example = "https://image.com/image.jpg") + val imageUrl: String, + @field:Schema(description = "한 줄 문구", example = "한 줄 메시지입니다.") + val oneLineMessage: String, + @field:Schema(description = "작성자 ID", example = "userId") + val userId: Long?, + @field:Schema(description = "작성자 닉네임", example = "nickname") + val nickname: String, + @field:Schema(description = "작성자인지 여부", example = "true") + val isMine: Boolean, + @field:Schema(description = "생성일시", example = "2021-01-01T00:00:00") + val createdAt: LocalDateTime?, + @field:Schema(description = "옵션") + val options: Map? +) diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/repository/PolaroidJooqRepository.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/repository/PolaroidJooqRepository.kt index c39ba22..2a4bc07 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/repository/PolaroidJooqRepository.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/repository/PolaroidJooqRepository.kt @@ -1,6 +1,6 @@ package com.ddd.sonnypolabobe.domain.polaroid.repository -import com.ddd.sonnypolabobe.domain.polaroid.controller.dto.PolaroidCreateRequest +import com.ddd.sonnypolabobe.domain.polaroid.dto.PolaroidCreateRequest import com.ddd.sonnypolabobe.jooq.polabo.tables.records.PolaroidRecord interface PolaroidJooqRepository { diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/repository/PolaroidJooqRepositoryImpl.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/repository/PolaroidJooqRepositoryImpl.kt index da7e055..e9ce3b9 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/repository/PolaroidJooqRepositoryImpl.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/repository/PolaroidJooqRepositoryImpl.kt @@ -1,6 +1,6 @@ package com.ddd.sonnypolabobe.domain.polaroid.repository -import com.ddd.sonnypolabobe.domain.polaroid.controller.dto.PolaroidCreateRequest +import com.ddd.sonnypolabobe.domain.polaroid.dto.PolaroidCreateRequest import com.ddd.sonnypolabobe.global.exception.ApplicationException import com.ddd.sonnypolabobe.global.exception.CustomErrorCode import com.ddd.sonnypolabobe.global.util.DateConverter diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/service/PolaroidService.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/service/PolaroidService.kt index 3047615..49677fd 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/service/PolaroidService.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/polaroid/service/PolaroidService.kt @@ -1,8 +1,8 @@ package com.ddd.sonnypolabobe.domain.polaroid.service import com.ddd.sonnypolabobe.domain.board.repository.BoardJooqRepository -import com.ddd.sonnypolabobe.domain.polaroid.controller.dto.PolaroidCreateRequest -import com.ddd.sonnypolabobe.domain.polaroid.controller.dto.PolaroidGetResponse +import com.ddd.sonnypolabobe.domain.polaroid.dto.PolaroidCreateRequest +import com.ddd.sonnypolabobe.domain.polaroid.dto.PolaroidGetResponse import com.ddd.sonnypolabobe.domain.polaroid.enumerate.PolaroidOption import com.ddd.sonnypolabobe.domain.polaroid.repository.PolaroidJooqRepository import com.ddd.sonnypolabobe.domain.user.dto.UserDto diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/controller/UserController.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/controller/UserController.kt index e65d85f..be0b860 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/controller/UserController.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/controller/UserController.kt @@ -3,12 +3,9 @@ package com.ddd.sonnypolabobe.domain.user.controller import com.ddd.sonnypolabobe.domain.user.dto.UserDto import com.ddd.sonnypolabobe.domain.user.service.UserService import com.ddd.sonnypolabobe.global.response.ApplicationResponse -import com.ddd.sonnypolabobe.global.util.DateConverter import io.swagger.v3.oas.annotations.Operation -import org.springframework.security.core.context.SecurityContext import org.springframework.security.core.context.SecurityContextHolder import org.springframework.web.bind.annotation.* -import java.time.LocalDateTime @RestController @RequestMapping("/api/v1/user") diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/dto/UserDto.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/dto/UserDto.kt index 7e626af..3e816e1 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/dto/UserDto.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/dto/UserDto.kt @@ -1,8 +1,9 @@ package com.ddd.sonnypolabobe.domain.user.dto +import com.ddd.sonnypolabobe.domain.user.withdraw.dto.WithdrawType import com.fasterxml.jackson.annotation.JsonProperty +import io.swagger.v3.oas.annotations.media.Schema import jakarta.validation.constraints.Email -import org.intellij.lang.annotations.RegExp import org.springframework.security.core.GrantedAuthority import org.springframework.security.core.authority.SimpleGrantedAuthority import org.springframework.security.core.userdetails.UserDetails @@ -15,17 +16,20 @@ class UserDto { companion object { data class CreateReq( @field:Email + @field:Schema(description = "이메일", example = "test@polabo.com") val email: String, + @field:Schema(description = "닉네임", example = "쏘니") val nickName: String, -// val birthDt : LocalDate?, -// val gender : GenderType? ) data class UpdateReq( @JsonProperty("nickName") + @field:Schema(description = "닉네임", example = "쏘니") val nickName: String, @JsonProperty("birthDt") + @field:Schema(description = "생년월일", example = "1990-01-01") val birthDt: LocalDate?, + @field:Schema(description = "성별", example = "NONE, F, M") val gender: GenderType? ) @@ -62,14 +66,26 @@ class UserDto { } data class ProfileRes( + @field:Schema(description = "아이디", example = "1") val id: Long, + @field:Schema(description = "이메일", example = "test@polabo.com") val email: String, + @field:Schema(description = "닉네임", example = "쏘니") val nickName: String, + @field:Schema(description = "생년월일", example = "1990-01-01") val createdAt: LocalDateTime, ) data class WithdrawReq( + @field:Schema(description = "탈퇴 타입", example = """ + NOT_USE : 사용하지 않음 + WORRY_ABOUT_PERSONAL_INFO : 개인정보 우려 + DROP_MY_DATA : 내 데이터 삭제 + WANT_TO_NEW_ACCOUNT : 새로운 계정을 만들고 싶어요 + OTHER : 기타 + """) val type: WithdrawType, + @field:Schema(description = "탈퇴 사유", example = "탈퇴 사유입니다.") val reason: String? ) diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/service/UserService.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/service/UserService.kt index de96dc5..17fe370 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/service/UserService.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/service/UserService.kt @@ -2,7 +2,7 @@ package com.ddd.sonnypolabobe.domain.user.service import com.ddd.sonnypolabobe.domain.user.dto.UserDto import com.ddd.sonnypolabobe.domain.user.repository.UserJooqRepository -import com.ddd.sonnypolabobe.domain.user.repository.WithdrawJooqRepository +import com.ddd.sonnypolabobe.domain.user.withdraw.repository.WithdrawJooqRepository import org.springframework.stereotype.Service @Service diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/dto/WithdrawType.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/withdraw/dto/WithdrawType.kt similarity index 83% rename from src/main/kotlin/com/ddd/sonnypolabobe/domain/user/dto/WithdrawType.kt rename to src/main/kotlin/com/ddd/sonnypolabobe/domain/user/withdraw/dto/WithdrawType.kt index 2dbbeca..608c937 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/dto/WithdrawType.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/withdraw/dto/WithdrawType.kt @@ -1,4 +1,4 @@ -package com.ddd.sonnypolabobe.domain.user.dto +package com.ddd.sonnypolabobe.domain.user.withdraw.dto enum class WithdrawType(val description : String) { NOT_USE("더이상 사용하지 않아요"), diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/repository/WithdrawJooqRepository.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/withdraw/repository/WithdrawJooqRepository.kt similarity index 72% rename from src/main/kotlin/com/ddd/sonnypolabobe/domain/user/repository/WithdrawJooqRepository.kt rename to src/main/kotlin/com/ddd/sonnypolabobe/domain/user/withdraw/repository/WithdrawJooqRepository.kt index ec9b0be..c9d1083 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/repository/WithdrawJooqRepository.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/withdraw/repository/WithdrawJooqRepository.kt @@ -1,4 +1,4 @@ -package com.ddd.sonnypolabobe.domain.user.repository +package com.ddd.sonnypolabobe.domain.user.withdraw.repository import com.ddd.sonnypolabobe.domain.user.dto.UserDto diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/repository/WithdrawJooqRepositoryImpl.kt b/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/withdraw/repository/WithdrawJooqRepositoryImpl.kt similarity index 94% rename from src/main/kotlin/com/ddd/sonnypolabobe/domain/user/repository/WithdrawJooqRepositoryImpl.kt rename to src/main/kotlin/com/ddd/sonnypolabobe/domain/user/withdraw/repository/WithdrawJooqRepositoryImpl.kt index a5c50d4..d844be6 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/repository/WithdrawJooqRepositoryImpl.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/domain/user/withdraw/repository/WithdrawJooqRepositoryImpl.kt @@ -1,4 +1,4 @@ -package com.ddd.sonnypolabobe.domain.user.repository +package com.ddd.sonnypolabobe.domain.user.withdraw.repository import com.ddd.sonnypolabobe.domain.user.dto.UserDto import com.ddd.sonnypolabobe.global.util.DateConverter diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/HealthCheckController.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/HealthCheckController.kt index b171ce0..3bb0061 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/HealthCheckController.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/HealthCheckController.kt @@ -7,7 +7,5 @@ import org.springframework.web.bind.annotation.RestController class HealthCheckController { @GetMapping("/health") - fun healthCheck(): String { - return "OK" - } + fun healthCheck(): String = "OK" } \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/config/JasyptConfig.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/config/JasyptConfig.kt index 1f0dbce..663810f 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/config/JasyptConfig.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/config/JasyptConfig.kt @@ -10,17 +10,17 @@ import org.springframework.context.annotation.Configuration class JasyptConfig { @Bean("jasyptStringEncryptor") - fun stringEncryptor(): StringEncryptor { - val encryptor = PooledPBEStringEncryptor() - val config = SimpleStringPBEConfig() - config.password = System.getenv("JASYPT_ENCRYPTOR_PASSWORD") - config.algorithm = "PBEWithMD5AndDES" - config.setKeyObtentionIterations("1000") - config.setPoolSize("1") - config.stringOutputType = "base64" - config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator") - config.setIvGeneratorClassName("org.jasypt.iv.NoIvGenerator") - encryptor.setConfig(config) - return encryptor + fun stringEncryptor(): StringEncryptor = PooledPBEStringEncryptor().apply { + this.setConfig( + SimpleStringPBEConfig().apply { + this.password = System.getenv("JASYPT_ENCRYPTOR_PASSWORD") + this.algorithm = "PBEWithMD5AndDES" + this.setKeyObtentionIterations("1000") + this.setPoolSize("1") + this.stringOutputType = "base64" + this.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator") + this.setIvGeneratorClassName("org.jasypt.iv.NoIvGenerator") + } + ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/config/SwaggerConfig.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/config/SwaggerConfig.kt index 8b1147d..627e706 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/config/SwaggerConfig.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/config/SwaggerConfig.kt @@ -15,7 +15,7 @@ class SwaggerConfig { @Bean fun openAPI(): OpenAPI { val securityScheme: SecurityScheme = getSecurityScheme() - val securityRequirement: SecurityRequirement = getSecurityRequireMent() + val securityRequirement: SecurityRequirement = getSecurityRequirement() return OpenAPI() .addServersItem(Server().url("/")) @@ -23,12 +23,11 @@ class SwaggerConfig { .security(listOf(securityRequirement)) } - private fun getSecurityScheme(): SecurityScheme { - return SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("Bearer").bearerFormat("JWT") + private fun getSecurityScheme(): SecurityScheme = + SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("Bearer").bearerFormat("JWT") .`in`(SecurityScheme.In.HEADER).name("Authorization") - } - private fun getSecurityRequireMent(): SecurityRequirement { - return SecurityRequirement().addList("bearerAuth") - } + + private fun getSecurityRequirement(): SecurityRequirement = + SecurityRequirement().addList("bearerAuth") } \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/entity/PageDto.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/entity/PageDto.kt index 7be6e65..7e50158 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/entity/PageDto.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/entity/PageDto.kt @@ -8,7 +8,6 @@ data class PageDto( val currentPage: Int, val size : Int ) { - constructor( data: List, totalCount: Long, diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/exception/GlobalExceptionHandler.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/exception/GlobalExceptionHandler.kt index d90670f..ad6eaa0 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/exception/GlobalExceptionHandler.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/exception/GlobalExceptionHandler.kt @@ -15,7 +15,7 @@ class GlobalExceptionHandler( @ExceptionHandler(ApplicationException::class) fun applicationException(ex: ApplicationException): ResponseEntity> { logger().error("error : ${ex.error}") - if(ex.error.status.is5xxServerError) { + if (ex.error.status.is5xxServerError) { this.discordApiClient.sendErrorTrace( ex.error.status.toString(), ex.error.message, ex.stackTrace.contentToString() diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/security/CustomUserDetailsService.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/security/CustomUserDetailsService.kt index 18af849..45fc114 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/security/CustomUserDetailsService.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/security/CustomUserDetailsService.kt @@ -11,8 +11,7 @@ import org.springframework.transaction.annotation.Transactional class CustomUserDetailsService( private val userJooqRepository: UserJooqRepository ) : UserDetailsService { - override fun loadUserByUsername(id: String): UserDetails { - return userJooqRepository.findById(id.toLong()) + override fun loadUserByUsername(id: String): UserDetails = + this.userJooqRepository.findById(id.toLong()) ?: throw IllegalArgumentException("해당하는 사용자를 찾을 수 없습니다.") - } } \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/security/JwtExceptionFilter.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/security/JwtExceptionFilter.kt index 876a7e6..e2aa0db 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/security/JwtExceptionFilter.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/security/JwtExceptionFilter.kt @@ -67,9 +67,7 @@ class JwtExceptionFilter( } } - private fun excludeLogging(requestURI: String): Boolean { - return excludedUrls.any { requestURI.startsWith(it) } - } + private fun excludeLogging(requestURI: String): Boolean = excludedUrls.any { requestURI.startsWith(it) } private fun getResponseBody(response: ContentCachingResponseWrapper): String { var payload: String? = null diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/security/JwtUtil.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/security/JwtUtil.kt index 7081300..63c232b 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/security/JwtUtil.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/security/JwtUtil.kt @@ -9,7 +9,6 @@ import io.jsonwebtoken.security.Keys import jakarta.xml.bind.DatatypeConverter import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Component -import java.nio.charset.StandardCharsets import java.security.Key import java.util.* @@ -38,7 +37,13 @@ class JwtUtil( .setExpiration(expiredDate) .signWith(SignatureAlgorithm.HS512, getKeyBytes(accessSecretKey)) .compact() - return UserDto.Companion.TokenRes(accessToken, generateRefreshToken(request), expiredDate, false, request.nickName) + return UserDto.Companion.TokenRes( + accessToken, + generateRefreshToken(request), + expiredDate, + false, + request.nickName + ) } fun generateRefreshToken(request: UserDto.Companion.CreateTokenReq): String { @@ -123,10 +128,4 @@ class JwtUtil( private fun getKeyBytes(secretKey: String): ByteArray { return DatatypeConverter.parseBase64Binary((secretKey)) } - - private fun getKey(secretKey: String): Key { - val keyBytes = Base64.getDecoder().decode(secretKey) - return Keys.hmacShaKeyFor(keyBytes) - } - } \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/security/KakaoDto.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/security/KakaoDto.kt deleted file mode 100644 index 9ae1626..0000000 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/security/KakaoDto.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.ddd.sonnypolabobe.global.security - -import java.util.* - -class KakaoDto { - - companion object { - data class Token( - val access_token: String, - val refresh_token: String, - val token_type: String, - val expires_in: Int, - val refresh_token_expires_in: Int, - val scope: String - ) - - data class UserInfo( - val id: Long, - val connected_at: String, - val properties: Map, - val kakao_account: KakaoAccount - ) - - data class KakaoAccount( - val profile_nickname_needs_agreement: Boolean, - val profile_image_needs_agreement: Boolean, - val profile: Profile, - val has_email: Boolean, - val email_needs_agreement: Boolean, - val is_email_valid: Boolean, - val is_email_verified: Boolean, - val email: String - ) - - data class Profile( - val nickname: String, - val thumbnail_image_url: String, - val profile_image_url: String, - val is_default_image: Boolean, - val is_default_nickname: Boolean - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/security/RateLimitingInterceptor.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/security/RateLimitingInterceptor.kt index 95d96fb..57607ce 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/security/RateLimitingInterceptor.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/security/RateLimitingInterceptor.kt @@ -10,8 +10,11 @@ import org.springframework.web.servlet.HandlerInterceptor class RateLimitingInterceptor(private val rateLimitingService: RateLimitingService) : HandlerInterceptor { - override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean { - // 특정 URL 패턴을 필터링합니다. + override fun preHandle( + request: HttpServletRequest, + response: HttpServletResponse, + handler: Any + ): Boolean { if (request.requestURI == "/api/v1/boards" && request.method == "POST") { if (!rateLimitingService.incrementRequestCount()) { response.status = HttpStatus.TOO_MANY_REQUESTS.value() diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/security/RateLimitingService.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/security/RateLimitingService.kt index b7dbfd2..b283e7b 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/security/RateLimitingService.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/security/RateLimitingService.kt @@ -29,7 +29,5 @@ class RateLimitingService( } @Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul") - fun resetRequestCount() { - requestCounts.clear() - } + fun resetRequestCount() = requestCounts.clear() } \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/util/DateConverter.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/util/DateConverter.kt index 7836126..73bb93a 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/util/DateConverter.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/util/DateConverter.kt @@ -2,16 +2,13 @@ package com.ddd.sonnypolabobe.global.util import java.time.LocalDateTime import java.time.ZoneId -import java.util.Date +import java.util.* object DateConverter { - fun convertToKst(date: LocalDateTime): LocalDateTime { - return date.plusHours(9) - } + fun convertToKst(date: LocalDateTime): LocalDateTime = date.plusHours(9) - fun dateToLocalDateTime(date: Date) : LocalDateTime { - return LocalDateTime.ofInstant(date.toInstant(), ZoneId.of("Asia/Seoul")) - } + fun dateToLocalDateTime(date: Date): LocalDateTime = + LocalDateTime.ofInstant(date.toInstant(), ZoneId.of("Asia/Seoul")) } \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/util/DiscordApiClient.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/util/DiscordApiClient.kt index 0b8906b..7b237ec 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/util/DiscordApiClient.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/util/DiscordApiClient.kt @@ -23,18 +23,16 @@ class DiscordApiClient( .build() fun sendErrorLog(req: String) { - val embedData: MutableMap = HashMap() - - embedData["title"] = "서버 에러 발생" - - val field1: MutableMap = HashMap() - field1["name"] = "요청" - field1["value"] = req - - embedData["fields"] = listOf>(field1) - - val payload: MutableMap = HashMap() - payload["embeds"] = arrayOf(embedData) + val payload = """ + { + "content": "서버 알림", + "tts": false, + "embeds": [{ + "title": "에러 발생", + "description": "$req" + }] + } + """.trimIndent() sendDiscordComm() .post() @@ -46,26 +44,16 @@ class DiscordApiClient( } fun sendErrorTrace(errorCode: String, message: String?, trace: String) { - val embedData: MutableMap = HashMap() - - embedData["title"] = "서버 에러 발생" - - val field1: MutableMap = HashMap() - field1["name"] = "트레이스" - field1["value"] = trace - - val field2: MutableMap = HashMap() - field2["name"] = "에러 코드" - field2["value"] = errorCode - - val field3: MutableMap = HashMap() - field3["name"] = "메시지" - field3["value"] = message ?: "메시지 없음" - - embedData["fields"] = listOf>(field1, field2, field3) - - val payload: MutableMap = HashMap() - payload["embeds"] = arrayOf(embedData) + val payload = """ + { + "content": "서버 알림", + "tts": false, + "embeds": [{ + "title": "서버 에러 발생", + "description": "에러 코드 : ${errorCode} \n 트레이스 : $trace \n 메세지 : ${message ?: "메시지 없음"}" + }] + } + """.trimIndent() sendDiscordComm() .post() diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/util/HttpLog.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/util/HttpLog.kt deleted file mode 100644 index a9cfe8a..0000000 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/util/HttpLog.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.ddd.sonnypolabobe.global.util - -data class HttpLog( - val requestMethod : String, - val requestURI : String, - val responseStatus : Int, - val elapsedTime : Double, - val headers : Map, - val parameters : Map, - val requestBody : String, - val responseBody : String -) diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/util/S3Util.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/util/S3Util.kt index f09219d..c160551 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/util/S3Util.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/util/S3Util.kt @@ -33,16 +33,11 @@ class S3Util( private val cloudfrontDomain: String, ) { - fun awsCredentials(): BasicAWSCredentials { - return BasicAWSCredentials(accessKey, secretKey) - } - - fun amazonS3Client(): AmazonS3 { - return AmazonS3ClientBuilder.standard() - .withCredentials(AWSStaticCredentialsProvider(awsCredentials())) - .withRegion(region) - .build() - } + fun awsCredentials(): BasicAWSCredentials = BasicAWSCredentials(accessKey, secretKey) + fun amazonS3Client(): AmazonS3 = AmazonS3ClientBuilder.standard() + .withCredentials(AWSStaticCredentialsProvider(awsCredentials())) + .withRegion(region) + .build() fun getPreSignedUrl(fileName: String): URL { val path: String = (runningName + File.separator) + fileName diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/util/UuidConverter.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/util/UuidConverter.kt index 1abe579..5e32ae2 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/util/UuidConverter.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/util/UuidConverter.kt @@ -20,17 +20,12 @@ object UuidConverter { return byteBuffer.array() } - fun stringToUUID(uuid: String): UUID { - return try { - UUID.fromString(uuid) - } catch (e: IllegalArgumentException) { - throw ApplicationException( - CustomErrorCode.BOARD_NOT_FOUND - ) - } + fun stringToUUID(uuid: String): UUID = try { + UUID.fromString(uuid) + } catch (e: IllegalArgumentException) { + throw ApplicationException( + CustomErrorCode.BOARD_NOT_FOUND + ) } - fun uuidToString(uuid: UUID): String { - return uuid.toString() - } } \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/util/UuidGenerator.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/util/UuidGenerator.kt index 26bb83d..0bf6c46 100644 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/util/UuidGenerator.kt +++ b/src/main/kotlin/com/ddd/sonnypolabobe/global/util/UuidGenerator.kt @@ -4,7 +4,5 @@ import com.github.f4b6a3.uuid.UuidCreator import java.util.* object UuidGenerator { - fun create(): UUID { - return UuidCreator.getTimeOrderedEpochPlus1() - } + fun create(): UUID = UuidCreator.getTimeOrderedEpochPlus1() } \ No newline at end of file diff --git a/src/main/kotlin/com/ddd/sonnypolabobe/global/util/WebClientUtil.kt b/src/main/kotlin/com/ddd/sonnypolabobe/global/util/WebClientUtil.kt deleted file mode 100644 index 9a8709a..0000000 --- a/src/main/kotlin/com/ddd/sonnypolabobe/global/util/WebClientUtil.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.ddd.sonnypolabobe.global.util - -import org.springframework.http.HttpHeaders -import org.springframework.http.MediaType -import org.springframework.http.client.reactive.ReactorClientHttpConnector -import org.springframework.stereotype.Component -import org.springframework.web.reactive.function.client.WebClient -import reactor.netty.http.client.HttpClient -import java.time.Duration - - -@Component -class WebClientUtil() { - - fun create(baseUrl: String): WebClient { - return WebClient.builder() - .baseUrl(baseUrl) - .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) - .codecs { it.defaultCodecs().enableLoggingRequestDetails(true) } - .clientConnector( - ReactorClientHttpConnector( - HttpClient.create().responseTimeout(Duration.ofMillis(2500)) - ) - ) - .build() - } - -} \ No newline at end of file