From ecc7b4036341d290a4a1cb9dba69e823c87049f8 Mon Sep 17 00:00:00 2001 From: BlackBean99 <54030889+BlackBean99@users.noreply.github.com> Date: Mon, 10 Jul 2023 15:55:19 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[DPMBE-105]=20Slack=20=EB=AF=B8=EB=B0=9C?= =?UTF-8?q?=EC=86=A1=20=EC=97=90=EB=9F=AC=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../depromeet/whatnow/consts/WhatNowStatic.kt | 1 + .../api/config/slack/SlackAsyncErrorSender.kt | 6 +++--- .../slack/SlackErrorNotificationProvider.kt | 6 +++--- .../whatnow/api/config/slack/SlackHelper.kt | 18 ++++++++++-------- .../slack/SlackServiceNotificationProvider.kt | 2 +- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Whatnow-Common/src/main/kotlin/com/depromeet/whatnow/consts/WhatNowStatic.kt b/Whatnow-Common/src/main/kotlin/com/depromeet/whatnow/consts/WhatNowStatic.kt index 34b4d76c..8cd0d525 100644 --- a/Whatnow-Common/src/main/kotlin/com/depromeet/whatnow/consts/WhatNowStatic.kt +++ b/Whatnow-Common/src/main/kotlin/com/depromeet/whatnow/consts/WhatNowStatic.kt @@ -26,6 +26,7 @@ const val DEV = "dev" const val LOCAL = "local" const val WITHDRAW_PREFIX = "withdraw" const val RADIUS_WAIT_CONFIRM = 200 +const val SLACK_MAX_LENGTH = 1000 const val IMAGE_DOMAIN = "https://image.whatnow.kr" const val ASSERT_IMAGE_DOMAIN = "https://image.whatnow.kr/assert" diff --git a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/slack/SlackAsyncErrorSender.kt b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/slack/SlackAsyncErrorSender.kt index 7e2b7729..18e25ed8 100644 --- a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/slack/SlackAsyncErrorSender.kt +++ b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/slack/SlackAsyncErrorSender.kt @@ -21,7 +21,7 @@ class SlackAsyncErrorSender( fun execute(cachingRequest: ContentCachingRequestWrapper, userId: Long) { val url = cachingRequest.requestURL.toString() val method = cachingRequest.method - val body = objectMapper.readTree(cachingRequest.contentAsByteArray.contentToString()) + val body = objectMapper.readTree(cachingRequest.contentAsByteArray.decodeToString()) val errorUserIP = cachingRequest.remoteAddr val layoutBlocks: MutableList = ArrayList() layoutBlocks.add( @@ -65,8 +65,8 @@ class SlackAsyncErrorSender( val url = cachingRequest.requestURL.toString() val method = cachingRequest.method - val body = objectMapper.readTree(cachingRequest.contentAsByteArray.contentToString()) - + val body = objectMapper.readTree(cachingRequest.contentAsByteArray.decodeToString()) + println(body) val errorMessage = e.message val errorStack = slackProvider.getErrorStack(e) val errorUserIP = cachingRequest.remoteAddr diff --git a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/slack/SlackErrorNotificationProvider.kt b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/slack/SlackErrorNotificationProvider.kt index 0796dc2b..0958ad13 100644 --- a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/slack/SlackErrorNotificationProvider.kt +++ b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/slack/SlackErrorNotificationProvider.kt @@ -3,6 +3,7 @@ package com.depromeet.whatnow.api.config.slack import com.depromeet.whatnow.annotation.Helper import com.depromeet.whatnow.config.slack.SlackProperties import com.depromeet.whatnow.config.slack.SlackProperties.SlackSecret +import com.depromeet.whatnow.consts.SLACK_MAX_LENGTH import com.slack.api.model.block.LayoutBlock import org.springframework.scheduling.annotation.Async import java.util.Arrays @@ -13,16 +14,15 @@ class SlackErrorNotificationProvider( val slackProperties: SlackProperties, ) { var slackWebHook: SlackSecret = slackProperties.webhook - val MAX_LENGTH = 500 fun getErrorStack(throwable: Throwable): String { val exceptionAsStrings = Arrays.toString(throwable.stackTrace) - val cutLength = Math.min(exceptionAsStrings.length, MAX_LENGTH) + val cutLength = Math.min(exceptionAsStrings.length, SLACK_MAX_LENGTH) return exceptionAsStrings.substring(0, cutLength) } @Async fun sendNotification(layoutBlocks: List) { - slackHelper.sendNotification(slackWebHook.channelId, layoutBlocks) + slackHelper.sendNotification(slackWebHook.url, slackWebHook.token, slackWebHook.channelId, layoutBlocks) } } diff --git a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/slack/SlackHelper.kt b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/slack/SlackHelper.kt index 8c5c4398..f00ecf92 100644 --- a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/slack/SlackHelper.kt +++ b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/slack/SlackHelper.kt @@ -1,10 +1,10 @@ package com.depromeet.whatnow.api.config.slack import com.depromeet.whatnow.helper.SpringEnvironmentHelper -import com.slack.api.methods.MethodsClient +import com.slack.api.Slack import com.slack.api.methods.SlackApiException -import com.slack.api.methods.request.chat.ChatPostMessageRequest import com.slack.api.model.block.LayoutBlock +import com.slack.api.webhook.Payload import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.stereotype.Component @@ -12,20 +12,22 @@ import org.springframework.stereotype.Component @Component class SlackHelper( val springEnvironmentHelper: SpringEnvironmentHelper, - val methodsClient: MethodsClient, ) { val logger: Logger = LoggerFactory.getLogger(SlackHelper::class.java) - fun sendNotification(CHANNEL_ID: String, layoutBlocks: List) { + fun sendNotification(url: String, token: String, channelId: String, layoutBlocks: List) { if (!springEnvironmentHelper.isProdAndDevProfile) { +// Local 환경일 경우 적용 +// if (!springEnvironmentHelper.isLocalProfile) { return } - val chatPostMessageRequest = ChatPostMessageRequest.builder() - .channel(CHANNEL_ID) - .text("") + val methodsClient = Slack.getInstance() + val payload = Payload.builder() + .text("Slack Notification") + .username("WhatNow-Bot") .blocks(layoutBlocks) .build() try { - methodsClient.chatPostMessage(chatPostMessageRequest) + methodsClient.send(url, payload) } catch (slackApiException: SlackApiException) { logger.error(slackApiException.toString()) } diff --git a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/slack/SlackServiceNotificationProvider.kt b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/slack/SlackServiceNotificationProvider.kt index 48fff478..1611654e 100644 --- a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/slack/SlackServiceNotificationProvider.kt +++ b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/slack/SlackServiceNotificationProvider.kt @@ -13,6 +13,6 @@ class SlackServiceNotificationProvider( var slackWebHook: SlackSecret = slackProperties.webhook fun sendNotification(layoutBlocks: MutableList) { - slackHelper.sendNotification(slackWebHook.channelId, layoutBlocks) + slackHelper.sendNotification(slackWebHook.channelId, slackWebHook.token, slackWebHook.channelId, layoutBlocks) } } From 8158ad534d8ca3ae37894ea1332a015ecb4484cc Mon Sep 17 00:00:00 2001 From: BlackBean99 <54030889+BlackBean99@users.noreply.github.com> Date: Mon, 10 Jul 2023 15:55:41 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[DPMBE-108]=20=EC=A7=80=EC=97=AD=20?= =?UTF-8?q?=ED=82=A4=EC=9B=8C=EB=93=9C=20=EA=B2=80=EC=83=89=EC=8B=9C=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20=EC=A0=9C=ED=95=9C=20=ED=95=B4=EC=A0=9C?= =?UTF-8?q?=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat : 검색제한을 10개로 변경 * refactor : test parameter 변경 query, display -> display, query --- .../com/depromeet/whatnow/api/location/helper/NcpHelper.kt | 3 ++- .../main/kotlin/com/depromeet/whatnow/consts/WhatNowStatic.kt | 1 + .../kotlin/com/depromeet/whatnow/api/NcpLocalSearchClient.kt | 1 + .../depromeet/whatnow/config/ncp/NcpLocalSearchClientTest.kt | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/location/helper/NcpHelper.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/location/helper/NcpHelper.kt index 754ae8c2..ed07371a 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/location/helper/NcpHelper.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/location/helper/NcpHelper.kt @@ -4,6 +4,7 @@ import com.depromeet.whatnow.annotation.Helper import com.depromeet.whatnow.api.NcpLocalSearchClient import com.depromeet.whatnow.api.dto.NcpMapInfoResponse import com.depromeet.whatnow.config.NcpProperties +import com.depromeet.whatnow.consts.NCP_LOCAL_SEARCH_DISPLAY_COUNT @Helper class NcpHelper( @@ -14,6 +15,6 @@ class NcpHelper( // 검색 키워드 조회 fun getLocalSearch(keyword: String): NcpMapInfoResponse { - return ncpClient.searchByKeyword(ncpPropertie.accessKey, ncpPropertie.secretKey, keyword) + return ncpClient.searchByKeyword(ncpPropertie.accessKey, ncpPropertie.secretKey, NCP_LOCAL_SEARCH_DISPLAY_COUNT, keyword) } } diff --git a/Whatnow-Common/src/main/kotlin/com/depromeet/whatnow/consts/WhatNowStatic.kt b/Whatnow-Common/src/main/kotlin/com/depromeet/whatnow/consts/WhatNowStatic.kt index 8cd0d525..041efe77 100644 --- a/Whatnow-Common/src/main/kotlin/com/depromeet/whatnow/consts/WhatNowStatic.kt +++ b/Whatnow-Common/src/main/kotlin/com/depromeet/whatnow/consts/WhatNowStatic.kt @@ -28,6 +28,7 @@ const val WITHDRAW_PREFIX = "withdraw" const val RADIUS_WAIT_CONFIRM = 200 const val SLACK_MAX_LENGTH = 1000 +const val NCP_LOCAL_SEARCH_DISPLAY_COUNT = 10 const val IMAGE_DOMAIN = "https://image.whatnow.kr" const val ASSERT_IMAGE_DOMAIN = "https://image.whatnow.kr/assert" const val USER_DEFAULT_PROFILE_IMAGE = "https://image.whatnow.kr/assert/users/default.svg" diff --git a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/NcpLocalSearchClient.kt b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/NcpLocalSearchClient.kt index cccc54f7..c093cf47 100644 --- a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/NcpLocalSearchClient.kt +++ b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/NcpLocalSearchClient.kt @@ -12,6 +12,7 @@ interface NcpLocalSearchClient { fun searchByKeyword( @RequestHeader("X-Naver-Client-Id") accessKey: String, @RequestHeader("X-Naver-Client-Secret") secretKey: String, + @RequestParam display: Int = 10, @RequestParam query: String, ): NcpMapInfoResponse } diff --git a/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/config/ncp/NcpLocalSearchClientTest.kt b/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/config/ncp/NcpLocalSearchClientTest.kt index 662df355..6a5a684f 100644 --- a/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/config/ncp/NcpLocalSearchClientTest.kt +++ b/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/config/ncp/NcpLocalSearchClientTest.kt @@ -52,7 +52,7 @@ class NcpLocalSearchClientTest() { .withBody(responseJson), ), ) - val response = client.searchByKeyword(accessKey, secretKey, query) + val response = client.searchByKeyword(accessKey, secretKey, 10, query) assertEquals(response.items.size, 1) } } From d1a466a4a1e17e664931af431da3f72877ac7886 Mon Sep 17 00:00:00 2001 From: BlackBean99 <54030889+BlackBean99@users.noreply.github.com> Date: Mon, 10 Jul 2023 15:56:03 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[DPMBE-111]=20=EC=95=BD=EC=86=8D=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=EC=8B=9C=20NPE=20=EC=B2=98=EB=A6=AC=ED=95=9C?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: Event 발행하기 및 에러처리 Transactional import 변경 * refactor : spotless * refactor : enum to enumString --- .../api/promise/usecase/PromiseRegisterUseCase.kt | 3 +++ .../whatnow/domains/promise/domain/Promise.kt | 5 ++--- .../domains/promiseuser/domain/PromiseUser.kt | 14 +++++++------- .../service/PromiseUserDomainService.kt | 2 +- .../events/handler/PromiseRegisterEventHandler.kt | 5 +++++ 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/PromiseRegisterUseCase.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/PromiseRegisterUseCase.kt index ebc906e6..d11d0ed6 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/PromiseRegisterUseCase.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/PromiseRegisterUseCase.kt @@ -7,6 +7,7 @@ import com.depromeet.whatnow.common.vo.PlaceVo import com.depromeet.whatnow.domains.promise.adaptor.PromiseAdaptor import com.depromeet.whatnow.domains.promise.domain.Promise import com.depromeet.whatnow.domains.promise.service.PromiseDomainService +import org.springframework.transaction.annotation.Transactional import java.time.LocalDateTime @UseCase @@ -14,6 +15,7 @@ class PromiseRegisterUseCase( val promiseAdaptor: PromiseAdaptor, val promiseDomainService: PromiseDomainService, ) { + @Transactional fun createPromise(promiseRequest: PromiseRequest): PromiseDto { val promise = promiseDomainService.save( Promise( @@ -23,6 +25,7 @@ class PromiseRegisterUseCase( endTime = promiseRequest.endTime, ), ) + promise.createPromiseEvent() return PromiseDto.from(promise) } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promise/domain/Promise.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promise/domain/Promise.kt index f6b8d7c2..193bdf60 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promise/domain/Promise.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promise/domain/Promise.kt @@ -11,11 +11,11 @@ import java.time.LocalDateTime import javax.persistence.Column import javax.persistence.Embedded import javax.persistence.Entity +import javax.persistence.EnumType import javax.persistence.Enumerated import javax.persistence.GeneratedValue import javax.persistence.GenerationType import javax.persistence.Id -import javax.persistence.PostPersist import javax.persistence.Table @Entity @@ -33,7 +33,7 @@ class Promise( @Embedded var meetPlace: PlaceVo? = null, - @Enumerated + @Enumerated(EnumType.STRING) var promiseType: PromiseType = PromiseType.BEFORE, @Id @@ -44,7 +44,6 @@ class Promise( // 차후 이벤트 domain 설계 되면 생성시에 Domain 계층에서 validate 하겠습니다 // var promiseValidator: PromiseValidator, ) : BaseTimeEntity() { - @PostPersist fun createPromiseEvent() { Events.raise(PromiseRegisterEvent(this.id!!, this.mainUserId)) } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promiseuser/domain/PromiseUser.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promiseuser/domain/PromiseUser.kt index cc1fe9a9..3515d6a6 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promiseuser/domain/PromiseUser.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promiseuser/domain/PromiseUser.kt @@ -8,10 +8,11 @@ import com.depromeet.whatnow.events.domainEvent.PromiseUserRegisterEvent import javax.persistence.Column import javax.persistence.Embedded import javax.persistence.Entity +import javax.persistence.EnumType +import javax.persistence.Enumerated import javax.persistence.GeneratedValue import javax.persistence.GenerationType import javax.persistence.Id -import javax.persistence.PostPersist import javax.persistence.PostUpdate import javax.persistence.Table @@ -23,10 +24,10 @@ class PromiseUser( var userId: Long, @Embedded - var userLocation: CoordinateVo? = null, + var userLocation: CoordinateVo = CoordinateVo(0.0, 0.0), - @Embedded - var promiseUserType: PromiseUserType? = PromiseUserType.READY, + @Enumerated(EnumType.STRING) + var promiseUserType: PromiseUserType = PromiseUserType.READY, @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -41,7 +42,6 @@ class PromiseUser( Events.raise(PromiseUserCancelEvent(this.promiseId, this.userId, this.id!!)) } - @PostPersist fun createPromiseUserEvent() { Events.raise(PromiseUserRegisterEvent(this.promiseId, this.userId, this.id!!)) } @@ -56,10 +56,10 @@ class PromiseUser( } fun updatePromiseUserType(promiseUserType: PromiseUserType?) { - this.promiseUserType = promiseUserType + this.promiseUserType = promiseUserType!! } fun updatePromiseUserLocation(userLocation: CoordinateVo?) { - this.userLocation = userLocation + this.userLocation = userLocation!! } fun userLocationInit() { this.userLocation = CoordinateVo(0.0, 0.0) diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promiseuser/service/PromiseUserDomainService.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promiseuser/service/PromiseUserDomainService.kt index d47cc00c..98830980 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promiseuser/service/PromiseUserDomainService.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promiseuser/service/PromiseUserDomainService.kt @@ -7,7 +7,7 @@ import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUser import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType import com.google.common.geometry.S2LatLng import org.springframework.stereotype.Service -import javax.transaction.Transactional +import org.springframework.transaction.annotation.Transactional @Service class PromiseUserDomainService( diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseRegisterEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseRegisterEventHandler.kt index 7027c85c..91d3abae 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseRegisterEventHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/PromiseRegisterEventHandler.kt @@ -1,6 +1,7 @@ package com.depromeet.whatnow.events.handler import com.depromeet.whatnow.annotation.Handler +import com.depromeet.whatnow.common.vo.CoordinateVo import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUser import com.depromeet.whatnow.domains.promiseuser.service.PromiseUserDomainService import com.depromeet.whatnow.events.domainEvent.PromiseRegisterEvent @@ -19,6 +20,10 @@ class PromiseRegisterEventHandler( val promiseUser = PromiseUser( promiseId = promiseRegisterEvent.promiseId, userId = promiseRegisterEvent.userId, + userLocation = CoordinateVo( + latitude = 0.0, + longitude = 0.0, + ), ) promiseUserDomainService.createPromiseUser(promiseUser) } From ca880bdc16732e4cc13b661606199f9e2a870122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EB=AA=A8?= Date: Mon, 10 Jul 2023 22:09:36 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[DPMBE-112]=20=EC=9D=B4=EB=AF=B8=EC=A7=80?= =?UTF-8?q?=20=EC=97=85=EB=A1=9C=EB=93=9C=20=EC=84=B1=EA=B3=B5=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=EC=8B=9C=20url=EC=9D=84=20=EB=A6=AC=ED=84=B4=ED=95=B4?= =?UTF-8?q?=EC=A4=80=EB=8B=A4=20(#181)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 이미지 업로드 성공 요청시 url을 리턴해준다 * style: 정적 팩토리 메서드 사용 --- .../api/image/controller/ImageController.kt | 9 +++++---- .../depromeet/whatnow/api/image/dto/ImageDto.kt | 11 +++++++++++ .../image/usecase/ImageUploadSuccessUseCase.kt | 17 +++++++++++++---- .../PromiseImageUploadSuccessUseCaseTest.kt | 7 +++++-- .../domains/image/service/ImageDomainService.kt | 6 ++++-- 5 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/image/dto/ImageDto.kt diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/image/controller/ImageController.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/image/controller/ImageController.kt index 79a3da52..57bf7655 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/image/controller/ImageController.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/image/controller/ImageController.kt @@ -1,6 +1,7 @@ package com.depromeet.whatnow.api.image.controller import com.depromeet.whatnow.api.image.dto.ImageCommentElement +import com.depromeet.whatnow.api.image.dto.ImageDto import com.depromeet.whatnow.api.image.dto.ImageUrlResponse import com.depromeet.whatnow.api.image.dto.PromiseImageDetailResponse import com.depromeet.whatnow.api.image.dto.PromiseImageResponse @@ -50,8 +51,8 @@ class ImageController( @PathVariable imageKey: String, @RequestParam fileExtension: ImageFileExtension, @RequestParam promiseImageCommentType: PromiseImageCommentType, - ) { - successUseCase.promiseUploadImageSuccess(promiseId, imageKey, fileExtension, promiseImageCommentType) + ): ImageDto { + return successUseCase.promiseUploadImageSuccess(promiseId, imageKey, fileExtension, promiseImageCommentType) } @Tag(name = "6-1 [약속 이미지]") @@ -94,7 +95,7 @@ class ImageController( @Tag(name = "6-2 [유저 이미지]") @Operation(summary = "유저 프로필 이미지 업로드 성공 요청") @PostMapping("/{imageKey}/users/me") - fun userUploadImageSuccess(@PathVariable imageKey: String, @RequestParam fileExtension: ImageFileExtension) { - successUseCase.userUploadImageSuccess(imageKey, fileExtension) + fun userUploadImageSuccess(@PathVariable imageKey: String, @RequestParam fileExtension: ImageFileExtension): ImageDto { + return successUseCase.userUploadImageSuccess(imageKey, fileExtension) } } diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/image/dto/ImageDto.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/image/dto/ImageDto.kt new file mode 100644 index 00000000..67f0719f --- /dev/null +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/image/dto/ImageDto.kt @@ -0,0 +1,11 @@ +package com.depromeet.whatnow.api.image.dto + +data class ImageDto( + val imageUrl: String, +) { + companion object { + fun from(imageUrl: String): ImageDto { + return ImageDto(imageUrl) + } + } +} diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/image/usecase/ImageUploadSuccessUseCase.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/image/usecase/ImageUploadSuccessUseCase.kt index 0f4905b7..cfc738de 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/image/usecase/ImageUploadSuccessUseCase.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/image/usecase/ImageUploadSuccessUseCase.kt @@ -1,6 +1,7 @@ package com.depromeet.whatnow.api.image.usecase import com.depromeet.whatnow.annotation.UseCase +import com.depromeet.whatnow.api.image.dto.ImageDto import com.depromeet.whatnow.config.s3.ImageFileExtension import com.depromeet.whatnow.config.security.SecurityUtils import com.depromeet.whatnow.domains.image.domain.PromiseImageCommentType @@ -15,13 +16,21 @@ class ImageUploadSuccessUseCase( imageKey: String, fileExtension: ImageFileExtension, promiseImageCommentType: PromiseImageCommentType, - ) { + ): ImageDto { val currentUserId: Long = SecurityUtils.currentUserId - imageDomainService.promiseImageUploadSuccess(currentUserId, promiseId, imageKey, fileExtension, promiseImageCommentType) + val imageUrl = imageDomainService.promiseImageUploadSuccess( + currentUserId, + promiseId, + imageKey, + fileExtension, + promiseImageCommentType, + ) + return ImageDto.from(imageUrl) } - fun userUploadImageSuccess(imageKey: String, fileExtension: ImageFileExtension) { + fun userUploadImageSuccess(imageKey: String, fileExtension: ImageFileExtension): ImageDto { val currentUserId: Long = SecurityUtils.currentUserId - imageDomainService.userImageUploadSuccess(currentUserId, imageKey, fileExtension) + val imageUrl = imageDomainService.userImageUploadSuccess(currentUserId, imageKey, fileExtension) + return ImageDto.from(imageUrl) } } diff --git a/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/usecase/PromiseImageUploadSuccessUseCaseTest.kt b/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/usecase/PromiseImageUploadSuccessUseCaseTest.kt index 075898ec..6f53c018 100644 --- a/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/usecase/PromiseImageUploadSuccessUseCaseTest.kt +++ b/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/usecase/PromiseImageUploadSuccessUseCaseTest.kt @@ -10,6 +10,7 @@ import org.junit.jupiter.api.extension.ExtendWith import org.mockito.InjectMocks import org.mockito.Mock import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.given import org.springframework.security.authentication.UsernamePasswordAuthenticationToken import org.springframework.security.core.authority.SimpleGrantedAuthority import org.springframework.security.core.context.SecurityContextHolder @@ -33,8 +34,9 @@ class PromiseImageUploadSuccessUseCaseTest { @Test fun `약속 이미지 업로드 성공 요청시 정상적이라면 에러가 발생하지 않는다`() { // given + given(imageDomainService.promiseImageUploadSuccess(1, 1, "imageKey", ImageFileExtension.JPG, PromiseImageCommentType.SORRY_LATE)) + .willReturn("imageUrl") // when - // then assertThatCode { imageUploadSuccessUseCase.promiseUploadImageSuccess(1, "imageKey", ImageFileExtension.JPG, PromiseImageCommentType.SORRY_LATE) @@ -44,7 +46,8 @@ class PromiseImageUploadSuccessUseCaseTest { @Test fun `유저 프로필 업로드 성공 요청시 정상적이라면 에러가 발생하지 않는다`() { // given - + given(imageDomainService.userImageUploadSuccess(1, "imageKey", ImageFileExtension.JPG)) + .willReturn("imageUrl") // when // then diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/service/ImageDomainService.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/service/ImageDomainService.kt index bf46ccfd..0736aef4 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/service/ImageDomainService.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/service/ImageDomainService.kt @@ -32,7 +32,7 @@ class ImageDomainService( imageKey: String, fileExtension: ImageFileExtension, promiseImageCommentType: PromiseImageCommentType, - ) { + ): String { val promiseUser = promiseUserAdapter.findByPromiseIdAndUserId(promiseId, userId) validatePromiseUserType(promiseUser.promiseUserType!!, promiseImageCommentType) @@ -40,12 +40,14 @@ class ImageDomainService( promiseImageAdapter.save( PromiseImage.of(promiseId, userId, imageUrl, imageKey, fileExtension, promiseImageCommentType), ) + return imageUrl } @Transactional - fun userImageUploadSuccess(userId: Long, imageKey: String, fileExtension: ImageFileExtension) { + fun userImageUploadSuccess(userId: Long, imageKey: String, fileExtension: ImageFileExtension): String { val imageUrl = IMAGE_DOMAIN + "/" + springEnvironmentHelper.activeProfile + "/" + "user/$userId/$imageKey" userImageAdapter.save(UserImage.of(userId, imageUrl, imageKey, fileExtension)) + return imageUrl } private fun validatePromiseUserType(promiseUserType: PromiseUserType, promiseImageCommentType: PromiseImageCommentType) {