From 7fcfba73e6ee208063861d1a4815a18f21b17e3b Mon Sep 17 00:00:00 2001 From: BlackBean99 <54030889+BlackBean99@users.noreply.github.com> Date: Sat, 1 Jul 2023 15:22:54 +0900 Subject: [PATCH 1/7] =?UTF-8?q?[DPMBE-82]=20=EC=A2=8C=ED=91=9C=EB=A1=9C=20?= =?UTF-8?q?=ED=96=89=EC=A0=95=EB=8F=99=EC=9D=84=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8B=A4=20(#124)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor : sonar bugs * build : mongoDB Config * feat: 행정동 조히 * stash * test : District 조회 test * fix : contextLoad 해결 --- .../example/controller/ExampleController.kt | 12 +++ .../api/promise/controller/LocalController.kt | 14 ++- .../promise/controller/PromiseController.kt | 2 +- .../api/promise/usecase/GetDistrictUseCase.kt | 17 ++++ .../promise/controller/LocalControllerTest.kt | 85 +++++++++++++++++++ .../repository/DistrictRepositoryTest.kt | 68 +++++++++++++++ .../whatnow/WhatnowDomainApplication.kt | 3 + .../domains/district/domain/District.kt | 27 ++++++ .../district/repository/DistrictRepository.kt | 13 +++ Whatnow-Infrastructure/build.gradle.kts | 2 + .../api/config/slack/SlackAsyncErrorSender.kt | 2 +- .../whatnow/config/EnableConfigProperties.kt | 2 +- .../whatnow/config/MongoDBProperties.kt | 18 ++++ .../whatnow/config/mongo/MongoConfig.kt | 29 +++++++ .../resources/application-infrastructure.yml | 8 +- 15 files changed, 296 insertions(+), 6 deletions(-) create mode 100644 Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/GetDistrictUseCase.kt create mode 100644 Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/promise/controller/LocalControllerTest.kt create mode 100644 Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/promise/repository/DistrictRepositoryTest.kt create mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/district/domain/District.kt create mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/district/repository/DistrictRepository.kt create mode 100644 Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/MongoDBProperties.kt create mode 100644 Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/mongo/MongoConfig.kt diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/example/controller/ExampleController.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/example/controller/ExampleController.kt index a6e67ae0..f5fd4880 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/example/controller/ExampleController.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/example/controller/ExampleController.kt @@ -4,6 +4,8 @@ import com.depromeet.whatnow.annotation.ApiErrorCodeExample import com.depromeet.whatnow.api.config.kakao.KakaoKauthErrorCode import com.depromeet.whatnow.domains.image.exception.ImageErrorCode import com.depromeet.whatnow.domains.progresshistory.exception.PromiseHistoryErrorCode +import com.depromeet.whatnow.domains.promise.exception.PromiseErrorCode +import com.depromeet.whatnow.domains.promiseuser.exception.PromiseUserErrorCode import com.depromeet.whatnow.domains.user.exception.UserErrorCode import com.depromeet.whatnow.exception.GlobalErrorCode import io.swagger.v3.oas.annotations.Operation @@ -45,4 +47,14 @@ class ExampleController() { @Operation(summary = "이미지 업로드 관련 에러코드 나열") @ApiErrorCodeExample(ImageErrorCode::class) fun imageErrorCode() {} + + @GetMapping("/promises") + @Operation(summary = "약속 관련 에러코드 나열") + @ApiErrorCodeExample(PromiseErrorCode::class) + fun promiseErrorCode() {} + + @GetMapping("/promise-users") + @Operation(summary = "약속 참여 관련 에러코드 나열") + @ApiErrorCodeExample(PromiseUserErrorCode::class) + fun promiseUserErrorCode() {} } diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/controller/LocalController.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/controller/LocalController.kt index 2fd8437b..00cc322a 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/controller/LocalController.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/controller/LocalController.kt @@ -2,19 +2,20 @@ package com.depromeet.whatnow.api.promise.controller import com.depromeet.whatnow.api.dto.NcpMapInfoResponse import com.depromeet.whatnow.api.location.helper.NcpHelper +import com.depromeet.whatnow.api.promise.usecase.GetDistrictUseCase import io.swagger.v3.oas.annotations.Operation -import io.swagger.v3.oas.annotations.security.SecurityRequirement import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController +// @SecurityRequirement(name = "access-token") @RestController @RequestMapping("/v1") @Tag(name = "3.1 [약속-장소]") -@SecurityRequirement(name = "access-token") class LocalController( + val getDistrictUseCase: GetDistrictUseCase, val ncpHelper: NcpHelper, ) { @Operation(summary = "약속 장소 검색", description = "약속 장소를 검색합니다.") @@ -22,4 +23,13 @@ class LocalController( fun searchLocal(@RequestParam(value = "location") addressKeyword: String): NcpMapInfoResponse { return ncpHelper.getLocalSearch(addressKeyword) } + + @Operation(summary = "행정동 조회", description = "좌표를 통해 행정동을 조회합니다.") + @GetMapping("/district") + fun getDistrict( + @RequestParam coordinateX: Double, + @RequestParam coordinateY: Double, + ): String { + return getDistrictUseCase.execute(coordinateX, coordinateY) + } } diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/controller/PromiseController.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/controller/PromiseController.kt index 3d93c6cb..4dd9249b 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/controller/PromiseController.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/controller/PromiseController.kt @@ -48,7 +48,7 @@ class PromiseController( return promiseReadUseCase.findPromiseByUserIdYearMonth(yearMonth) } - @Operation(summary = "약속 모음집 상세", description = "D3. 지난(AFTER) 약속 상세 조회 (날짜(월,일), 약속 사진 url, 타임오버 캡쳐, 만난 사람(프로필 tkwls Url, 이름, wait/late 여부, interaction 종륲별 카운트), 하이라이트 기록 최대 3개") + @Operation(summary = "약속 모음집 상세", description = "D3. 지난(AFTER) 약속 상세 조회 (날짜(월,일), 약속 사진 url, 타임오버 캡쳐, 만난 사람(프로필 사진 Url, 이름, wait/late 여부, interaction 종륲별 카운트), 하이라이트 기록 최대 3개") @GetMapping("/promises/users/status/{status}") fun findPromiseDetailByStatus(@PathVariable(value = "status") status: PromiseType): List { return promiseReadUseCase.findPromiseDetailByStatus(status) diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/GetDistrictUseCase.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/GetDistrictUseCase.kt new file mode 100644 index 00000000..0a53f00a --- /dev/null +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/GetDistrictUseCase.kt @@ -0,0 +1,17 @@ +package com.depromeet.whatnow.api.promise.usecase + +import com.depromeet.whatnow.annotation.UseCase +import com.depromeet.whatnow.domains.district.repository.DistrictRepository +import com.mongodb.client.model.geojson.Point +import com.mongodb.client.model.geojson.Position + +@UseCase +class GetDistrictUseCase( + val districtRepository: DistrictRepository, +) { + fun execute(coordinateX: Double, coordinateY: Double): String { + val intersects = + districtRepository.findByLocationIntersects(Point(Position(coordinateX, coordinateY))) + return intersects.properties.adm_nm + } +} diff --git a/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/promise/controller/LocalControllerTest.kt b/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/promise/controller/LocalControllerTest.kt new file mode 100644 index 00000000..73257682 --- /dev/null +++ b/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/promise/controller/LocalControllerTest.kt @@ -0,0 +1,85 @@ +package com.depromeet.whatnow.api.promise.controller + +import com.depromeet.whatnow.api.dto.NcpMapInfoResponse +import com.depromeet.whatnow.api.location.helper.NcpHelper +import com.depromeet.whatnow.api.promise.usecase.GetDistrictUseCase +import com.depromeet.whatnow.domains.district.domain.District +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mock +import org.mockito.Mockito.`when` +import org.mockito.MockitoAnnotations +import org.mockito.junit.jupiter.MockitoExtension + +@ExtendWith(MockitoExtension::class) +class LocalControllerTest { + + @Mock + private lateinit var getDistrictUseCase: GetDistrictUseCase + + @Mock + private lateinit var ncpHelper: NcpHelper + + private lateinit var localController: LocalController + + @BeforeEach + fun setup() { + MockitoAnnotations.openMocks(this) + localController = LocalController(getDistrictUseCase, ncpHelper) + } + + @Test + fun `searchLocal should return NcpMapInfoResponse`() { + // Given + val addressKeyword = "New York" + val expectedResponse = NcpMapInfoResponse( + lastBuildDate = "2022:02:02", + total = 1, + start = 1, + display = 1, + items = listOf(), + ) + `when`(ncpHelper.getLocalSearch(addressKeyword)).thenReturn(expectedResponse) + + // When + val result = localController.searchLocal(addressKeyword) + + // Then + assertEquals(expectedResponse, result) + } + + @Test + fun `행정동을 조회할 수 있다`() { + // Given + val coordinateX = 123.4 + val coordinateY = 432.23 + val expectedDistrictName = "서울특별시 종로구 평창동" + val expectedDistrict = District( + id = "1", + type = "Feature", + properties = District.Properties( + OBJECTID = 1, + adm_nm = expectedDistrictName, + adm_cd = "1101056", + adm_cd2 = "1111056000", + sgg = "11110", + sido = "11", + sidonm = "서울특별시", + sggnm = "종로구", + ), + geometry = District.Geometry( + type = "MultiPolygon", + coordinates = listOf(listOf(listOf(126.97507466788086, 37.63138628651299))), + ), + ) + `when`(getDistrictUseCase.execute(coordinateX, coordinateY)).thenReturn(expectedDistrict.properties.adm_nm) + + // When + val result = localController.getDistrict(coordinateX, coordinateY) + + // Then + assertEquals(expectedDistrict.properties.adm_nm, result) + } +} diff --git a/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/promise/repository/DistrictRepositoryTest.kt b/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/promise/repository/DistrictRepositoryTest.kt new file mode 100644 index 00000000..c7fa2ed9 --- /dev/null +++ b/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/promise/repository/DistrictRepositoryTest.kt @@ -0,0 +1,68 @@ +package com.depromeet.whatnow.api.promise.repository + +import com.depromeet.whatnow.domains.district.domain.District +import com.depromeet.whatnow.domains.district.repository.DistrictRepository +import com.mongodb.client.model.geojson.Point +import com.mongodb.client.model.geojson.Position +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mock +import org.mockito.Mockito.`when` +import org.mockito.junit.jupiter.MockitoExtension + +@ExtendWith(MockitoExtension::class) +class DistrictRepositoryTest { + + @Mock + private lateinit var districtRepository: DistrictRepository + + @Test + fun `xy좌표로 행정동 조회를 할 수 있다`() { + // Given + val coordinateX = 123.4 + val coordinateY = 432.23 + val expectedDistrictName = "서울특별시 종로구 평창동" + val district = District( + id = "1", + type = "Feature", + properties = District.Properties( + OBJECTID = 1, + adm_nm = expectedDistrictName, + adm_cd = "1101056", + adm_cd2 = "1111056000", + sgg = "11110", + sido = "11", + sidonm = "서울특별시", + sggnm = "종로구", + ), + geometry = District.Geometry( + type = "MultiPolygon", + coordinates = listOf(listOf(listOf(126.97507466788086, 37.63138628651299))), + ), + ) + + `when`( + districtRepository.findByLocationIntersects( + Point( + Position( + coordinateX, + coordinateY, + ), + ), + ), + ).thenReturn(district) + // When + val result = districtRepository.findByLocationIntersects( + Point( + Position( + coordinateX, + coordinateY, + ), + ), + ) + + // Then + assertEquals(district, result) + } +} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/WhatnowDomainApplication.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/WhatnowDomainApplication.kt index f40ec9b2..acfb8cae 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/WhatnowDomainApplication.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/WhatnowDomainApplication.kt @@ -1,9 +1,12 @@ package com.depromeet.whatnow +import com.depromeet.whatnow.config.mongo.MongoConfig import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication +import org.springframework.context.annotation.Import @SpringBootApplication +@Import(MongoConfig::class) class WhatnowDomainApplication fun main(args: Array) { diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/district/domain/District.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/district/domain/District.kt new file mode 100644 index 00000000..65bef344 --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/district/domain/District.kt @@ -0,0 +1,27 @@ +package com.depromeet.whatnow.domains.district.domain +import org.springframework.data.annotation.Id +import org.springframework.data.mongodb.core.mapping.Document + +@Document(collection = "reversegeo") +data class District( + @Id + val id: String, + val type: String, + val properties: Properties, + val geometry: Geometry, +) { + data class Properties( + val OBJECTID: Int, + val adm_nm: String, + val adm_cd: String, + val adm_cd2: String, + val sgg: String, + val sido: String, + val sidonm: String, + val sggnm: String, + ) + data class Geometry( + val type: String, + val coordinates: List>>, + ) +} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/district/repository/DistrictRepository.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/district/repository/DistrictRepository.kt new file mode 100644 index 00000000..9d46535f --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/district/repository/DistrictRepository.kt @@ -0,0 +1,13 @@ +package com.depromeet.whatnow.domains.district.repository + +import com.depromeet.whatnow.domains.district.domain.District +import com.mongodb.client.model.geojson.Point +import org.springframework.data.mongodb.repository.Query +import org.springframework.data.mongodb.repository.ReactiveMongoRepository +import org.springframework.stereotype.Repository + +@Repository +interface DistrictRepository : ReactiveMongoRepository { + @Query("{\$geoIntersects: {\$geometry: {type: 'Point', coordinates: ?0}}}") + fun findByLocationIntersects(coordinates: Point?): District +} diff --git a/Whatnow-Infrastructure/build.gradle.kts b/Whatnow-Infrastructure/build.gradle.kts index b3b92940..bcc18a68 100644 --- a/Whatnow-Infrastructure/build.gradle.kts +++ b/Whatnow-Infrastructure/build.gradle.kts @@ -18,6 +18,8 @@ dependencies{ implementation(project(":Whatnow-Common")) + // mongoDB + api ("org.springframework.boot:spring-boot-starter-data-mongodb-reactive") testImplementation ("org.springframework.cloud:spring-cloud-starter-contract-stub-runner:3.1.5") testImplementation ("org.springframework.cloud:spring-cloud-contract-wiremock:3.1.5") 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 28b27ff8..7e2b7729 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 @@ -65,7 +65,7 @@ class SlackAsyncErrorSender( val url = cachingRequest.requestURL.toString() val method = cachingRequest.method - val body = objectMapper.readTree(cachingRequest.contentAsByteArray.toString()) + val body = objectMapper.readTree(cachingRequest.contentAsByteArray.contentToString()) val errorMessage = e.message val errorStack = slackProvider.getErrorStack(e) diff --git a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/EnableConfigProperties.kt b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/EnableConfigProperties.kt index 8a7a374a..34ba660f 100644 --- a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/EnableConfigProperties.kt +++ b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/EnableConfigProperties.kt @@ -5,6 +5,6 @@ import com.depromeet.whatnow.config.slack.SlackProperties import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Configuration -@EnableConfigurationProperties(NcpProperties::class, SlackProperties::class, OauthProperties::class, S3Properties::class) +@EnableConfigurationProperties(MongoDBProperties::class, NcpProperties::class, SlackProperties::class, OauthProperties::class, S3Properties::class) @Configuration class EnableConfigProperties diff --git a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/MongoDBProperties.kt b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/MongoDBProperties.kt new file mode 100644 index 00000000..10afac2a --- /dev/null +++ b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/MongoDBProperties.kt @@ -0,0 +1,18 @@ +package com.depromeet.whatnow.config + +import org.springframework.boot.context.properties.ConfigurationProperties +import org.springframework.boot.context.properties.ConstructorBinding + +@ConfigurationProperties(prefix = "data") +@ConstructorBinding +data class MongoDBProperties( + val mongodb: MongoDB, +) { + data class MongoDB( + val url: String, + val host: String, + val database: String, + val username: String, + val password: String, + ) +} diff --git a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/mongo/MongoConfig.kt b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/mongo/MongoConfig.kt new file mode 100644 index 00000000..3454a1a3 --- /dev/null +++ b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/config/mongo/MongoConfig.kt @@ -0,0 +1,29 @@ +package com.depromeet.whatnow.config.mongo + +import com.depromeet.whatnow.config.MongoDBProperties +import com.mongodb.reactivestreams.client.MongoClients +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.data.mongodb.ReactiveMongoDatabaseFactory +import org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration +import org.springframework.data.mongodb.core.ReactiveMongoTemplate +import org.springframework.data.mongodb.core.convert.MappingMongoConverter + +@Configuration +class MongoConfig( + val mongoDBProperties: MongoDBProperties, +) : AbstractReactiveMongoConfiguration() { + var mongoProperties: MongoDBProperties.MongoDB = mongoDBProperties.mongodb + + override fun getDatabaseName(): String { + return mongoProperties.database + } + override fun reactiveMongoClient(): com.mongodb.reactivestreams.client.MongoClient { + return MongoClients.create(mongoProperties.url) + } + + @Bean("mongoTemplate") + override fun reactiveMongoTemplate(databaseFactory: ReactiveMongoDatabaseFactory, mongoConverter: MappingMongoConverter): ReactiveMongoTemplate { + return ReactiveMongoTemplate(reactiveMongoClient(), databaseName) + } +} diff --git a/Whatnow-Infrastructure/src/main/resources/application-infrastructure.yml b/Whatnow-Infrastructure/src/main/resources/application-infrastructure.yml index 15131699..af537f25 100644 --- a/Whatnow-Infrastructure/src/main/resources/application-infrastructure.yml +++ b/Whatnow-Infrastructure/src/main/resources/application-infrastructure.yml @@ -6,7 +6,13 @@ # bucket: ${AWS_S3_BUCKET:bucket} # private-bucket : ${AWS_S3_BUCKET_PRIVATE:bucket-private} # base-url: ${AWS_S3_BASE_URL:base-url} - +data: + mongodb: + url: mongodb+srv://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOST:cluster0.aybkvg3.mongodb.net}/${MONGO_DATABASE}?retryWrites=true&w=majority + host: ${MONGO_HOST:cluster0.aybkvg3.mongodb.net} + database: ${MONGO_DATABASE:reversegeo} + username: ${MONGO_USERNAME} + password: ${MONGO_PASSWORD} spring: redis: host: ${REDIS_HOST:localhost} From 0ec6b7e60829ece03fa3abe88b91fe3455a5d063 Mon Sep 17 00:00:00 2001 From: BlackBean99 <54030889+BlackBean99@users.noreply.github.com> Date: Mon, 3 Jul 2023 23:00:00 +0900 Subject: [PATCH 2/7] =?UTF-8?q?[DPMBE-84]=20PromiseUserDto=20=EC=97=90=20P?= =?UTF-8?q?romiseProgress=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80=20(#12?= =?UTF-8?q?9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat : PromiseUserDto 에 Progress 추가 * chore : spotless * refactor : post, put, delete 반환형 수정 --- .../controller/PromiseUserController.kt | 21 ++++---- .../api/promiseuser/dto/PromiseUserDto.kt | 6 ++- .../usecase/PromiseUserReadUseCase.kt | 41 ++++++--------- .../usecase/PromiseUserRecordUseCase.kt | 31 +++++++---- .../usecase/PromiseUserReadUseCaseTest.kt | 51 ++++++++++--------- .../adapter/ProgressHistoryAdapter.kt | 5 ++ .../repository/ProgressHistoryRepository.kt | 5 ++ .../promiseuser/adaptor/PromiseUserAdaptor.kt | 6 +-- .../domains/promiseuser/domain/PromiseUser.kt | 4 +- .../repository/PromiseUserRepository.kt | 6 +-- .../service/PromiseUserDomainService.kt | 5 +- 11 files changed, 98 insertions(+), 83 deletions(-) diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promiseuser/controller/PromiseUserController.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promiseuser/controller/PromiseUserController.kt index 0c1bea18..bd4f3855 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promiseuser/controller/PromiseUserController.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promiseuser/controller/PromiseUserController.kt @@ -4,6 +4,7 @@ import com.depromeet.whatnow.api.promiseuser.dto.PromiseUserDto import com.depromeet.whatnow.api.promiseuser.usecase.PromiseUserReadUseCase import com.depromeet.whatnow.api.promiseuser.usecase.PromiseUserRecordUseCase import com.depromeet.whatnow.common.vo.CoordinateVo +import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.security.SecurityRequirement import io.swagger.v3.oas.annotations.tags.Tag @@ -15,7 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController @RestController -@RequestMapping("/v1/") +@RequestMapping("/v1") @Tag(name = "4. [약속 유저]") @SecurityRequirement(name = "access-token") class PromiseUserController( @@ -23,26 +24,26 @@ class PromiseUserController( val promiseUserReadUseCase: PromiseUserReadUseCase, ) { @Operation(summary = "약속 유저(promise) 생성", description = "약속에 유저가 참여합니다.") - @PostMapping("promises/{promise-id}/users") + @PostMapping("/promises/{promise-id}/users") fun joinPromise(@PathVariable("promise-id") promiseId: Long, userId: Long, userLocation: CoordinateVo): PromiseUserDto { return promiseUserRecordUseCase.createPromiseUser(promiseId, userId, userLocation) } @Operation(summary = "약속 id로 약속 유저(promiseUser) 조회", description = "약속ID 로 약속 유저를 조회합니다.") - @GetMapping("promises/{promiseId}/users") + @GetMapping("/promises/{promiseId}/users") fun getPromiseUser(@PathVariable("promise-id") promiseId: Long): List { return promiseUserReadUseCase.findByPromiseId(promiseId) } - @Operation(summary = "유저가 약속을 취소(상태로 변경)", description = "userId로 참여한 약속 유저를 취소(cancel) 합니다.") - @GetMapping("promises/{promise-id}/users/{user-id}/status/{status}") - fun getPromiseUserByPromiseUserType(@PathVariable("promise-id") promiseId: Long, @PathVariable("user-id") userId: Long, @PathVariable("status") status: String): List { - return promiseUserReadUseCase.findPromiseUserByPromiseUserType(promiseId, userId, status) + @Operation(summary = "약속id 와 유저 id 로 약속에 참여한 유저의 정보를 조회", description = "약속ID 와 유저ID 로 약속에 참여한 유저의 정보를 조회합니다.") + @GetMapping("/promises/{promise-id}/users/{user-id}") + fun getPromiseUserByPromiseUserType(@PathVariable("promise-id") promiseId: Long, @PathVariable("user-id") userId: Long): PromiseUserDto { + return promiseUserReadUseCase.findPromiseUserByPromiseIdAndUserId(promiseId, userId) } @Operation(summary = "유저가 약속을 취소(상태로 변경)", description = "userId로 참여한 약속 유저를 취소(cancel) 합니다.") - @PutMapping("promises/{promise-id}/users/{user-id}/status/{status}") - fun cancelPromise(@PathVariable("promise-id") promiseId: Long, @PathVariable("user-id") userId: Long, @PathVariable("status") status: String): PromiseUserDto { - return promiseUserRecordUseCase.updatePromiseUserType(promiseId, userId, status) + @PutMapping("/promises/{promise-id}/users/{user-id}/status/{status}") + fun cancelPromise(@PathVariable("promise-id") promiseId: Long, @PathVariable("user-id") userId: Long, @PathVariable("status") promiseUserType: PromiseUserType): PromiseUserDto { + return promiseUserRecordUseCase.updatePromiseUserType(promiseId, userId, promiseUserType) } } diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promiseuser/dto/PromiseUserDto.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promiseuser/dto/PromiseUserDto.kt index 892eabec..21465510 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promiseuser/dto/PromiseUserDto.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promiseuser/dto/PromiseUserDto.kt @@ -1,6 +1,7 @@ package com.depromeet.whatnow.api.promiseuser.dto import com.depromeet.whatnow.common.vo.CoordinateVo +import com.depromeet.whatnow.domains.progresshistory.domain.PromiseProgress import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUser import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType @@ -9,10 +10,11 @@ data class PromiseUserDto( val mainUserId: Long, val userLocation: CoordinateVo?, val promiseUserType: PromiseUserType, + val promiseProgress: PromiseProgress, ) { companion object { - fun from(p: PromiseUser): PromiseUserDto { - return PromiseUserDto(p.promiseId, p.userId, p.userLocation, p.promiseUserType!!) + fun of(p: PromiseUser, progress: PromiseProgress): PromiseUserDto { + return PromiseUserDto(p.promiseId, p.userId, p.userLocation, p.promiseUserType!!, progress) } } } diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promiseuser/usecase/PromiseUserReadUseCase.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promiseuser/usecase/PromiseUserReadUseCase.kt index 9215110e..2c8914f0 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promiseuser/usecase/PromiseUserReadUseCase.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promiseuser/usecase/PromiseUserReadUseCase.kt @@ -2,39 +2,30 @@ package com.depromeet.whatnow.api.promiseuser.usecase import com.depromeet.whatnow.annotation.UseCase import com.depromeet.whatnow.api.promiseuser.dto.PromiseUserDto -import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType.READY -import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType.valueOf +import com.depromeet.whatnow.domains.progresshistory.adapter.ProgressHistoryAdapter +import com.depromeet.whatnow.domains.promiseuser.adaptor.PromiseUserAdaptor import com.depromeet.whatnow.domains.promiseuser.service.PromiseUserDomainService @UseCase class PromiseUserReadUseCase( val promiseUserDomainService: PromiseUserDomainService, + val progressHistoryAdapter: ProgressHistoryAdapter, + val promiseUserAdaptor: PromiseUserAdaptor, ) { fun findByPromiseId(promiseId: Long): List { - return promiseUserDomainService.findByPromiseId(promiseId).map { PromiseUserDto.from(it) } - } - fun findPromiseUserByPromiseUserType(promiseId: Long, userId: Long, status: String): List { - return promiseUserDomainService.findByPromiseId(promiseId) -// userType 와 status 를 비교해서 같은 것만 반환 - .filter { - it.userId == userId && it.promiseUserType == valueOf(status) - } - .map { PromiseUserDto.from(it) } - } - - fun findByUserIdOnReady(userId: Long): List { - return promiseUserDomainService.findByUserId(userId) - .filter { it.promiseUserType == READY } - .map { - PromiseUserDto.from(it) - } + val progressHistories = progressHistoryAdapter.findByPromiseId(promiseId) + val promiseUserDtos = mutableListOf() + val findByPromiseId = promiseUserDomainService.findByPromiseId(promiseId) + findByPromiseId.forEach { promiseUser -> + val progressHistory = progressHistories.find { it.userId == promiseUser.userId } + promiseUserDtos.add(PromiseUserDto.of(promiseUser, progressHistory!!.currentPromiseProgress)) + } + return promiseUserDtos } - fun findByUserIdWithStatus(userId: Long, status: String): List { - return promiseUserDomainService.findByUserId(userId) - .filter { it.promiseUserType == valueOf(status) } - .map { - PromiseUserDto.from(it) - } + fun findPromiseUserByPromiseIdAndUserId(promiseId: Long, userId: Long): PromiseUserDto { + val promiseUsers = promiseUserAdaptor.findByPromiseIdAndUserId(promiseId, userId) + val progressHistory = progressHistoryAdapter.findByPromiseIdAndUserId(promiseId, userId) + return PromiseUserDto.of(promiseUsers, progressHistory.currentPromiseProgress) } } diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promiseuser/usecase/PromiseUserRecordUseCase.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promiseuser/usecase/PromiseUserRecordUseCase.kt index b5d309b6..6c8710a7 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promiseuser/usecase/PromiseUserRecordUseCase.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promiseuser/usecase/PromiseUserRecordUseCase.kt @@ -3,7 +3,9 @@ package com.depromeet.whatnow.api.promiseuser.usecase import com.depromeet.whatnow.annotation.UseCase import com.depromeet.whatnow.api.promiseuser.dto.PromiseUserDto import com.depromeet.whatnow.common.vo.CoordinateVo +import com.depromeet.whatnow.domains.progresshistory.domain.PromiseProgress.DEFAULT import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUser +import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType import com.depromeet.whatnow.domains.promiseuser.service.PromiseUserDomainService @UseCase @@ -11,23 +13,30 @@ class PromiseUserRecordUseCase( val promiseUserDomainService: PromiseUserDomainService, ) { fun createPromiseUser(promiseId: Long, userId: Long, userLocation: CoordinateVo): PromiseUserDto { - val createPromiseUser = promiseUserDomainService.createPromiseUser( - PromiseUser( - promiseId = promiseId, - userId = userId, - userLocation = userLocation, + return PromiseUserDto.of( + promiseUserDomainService.createPromiseUser( + PromiseUser( + promiseId = promiseId, + userId = userId, + userLocation = userLocation, + ), ), + progress = DEFAULT, ) - return PromiseUserDto.from(createPromiseUser) } - fun cancelPromise(promiseId: Long, userId: Long): PromiseUserDto { + fun cancelPromise(promiseId: Long, userId: Long) { promiseUserDomainService.withDraw(promiseId, userId) - return PromiseUserDto.from(promiseUserDomainService.queryPromiseUser(promiseId)) } - fun updatePromiseUserType(promiseId: Long, userId: Long, status: String): PromiseUserDto { - val promiseUser = promiseUserDomainService.updatePromiseUserType(promiseId, userId, status) - return PromiseUserDto.from(promiseUser) + fun updatePromiseUserType(promiseId: Long, userId: Long, promiseUserType: PromiseUserType): PromiseUserDto { + return PromiseUserDto.of( + promiseUserDomainService.updatePromiseUserType( + promiseId = promiseId, + userId = userId, + promiseUserType = promiseUserType, + ), + progress = DEFAULT, + ) } } diff --git a/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/promiseuser/usecase/PromiseUserReadUseCaseTest.kt b/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/promiseuser/usecase/PromiseUserReadUseCaseTest.kt index dc8c2d1c..5253d36b 100644 --- a/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/promiseuser/usecase/PromiseUserReadUseCaseTest.kt +++ b/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/promiseuser/usecase/PromiseUserReadUseCaseTest.kt @@ -2,6 +2,11 @@ package com.depromeet.whatnow.api.promiseuser.usecase import com.depromeet.whatnow.api.promiseuser.dto.PromiseUserDto import com.depromeet.whatnow.common.vo.CoordinateVo +import com.depromeet.whatnow.domains.progresshistory.adapter.ProgressHistoryAdapter +import com.depromeet.whatnow.domains.progresshistory.domain.ProgressHistory +import com.depromeet.whatnow.domains.progresshistory.domain.PromiseProgress +import com.depromeet.whatnow.domains.progresshistory.domain.PromiseProgress.DEFAULT +import com.depromeet.whatnow.domains.promiseuser.adaptor.PromiseUserAdaptor import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUser import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType import com.depromeet.whatnow.domains.promiseuser.service.PromiseUserDomainService @@ -16,45 +21,41 @@ class PromiseUserReadUseCaseTest { @Mock private lateinit var promiseUserDomainService: PromiseUserDomainService + @Mock + private lateinit var progressHistoryAdapter: ProgressHistoryAdapter + + @Mock + private lateinit var promiseUserAdaptor: PromiseUserAdaptor + private lateinit var promiseUserReadUseCase: PromiseUserReadUseCase @BeforeEach fun setUp() { MockitoAnnotations.openMocks(this) - promiseUserReadUseCase = PromiseUserReadUseCase(promiseUserDomainService) + promiseUserReadUseCase = PromiseUserReadUseCase(promiseUserDomainService, progressHistoryAdapter, promiseUserAdaptor) } @Test - fun `PromiseId로_1개의_회원을_조회할_수_있다`() { + fun `PromiseId로_회원을_조회할_수_있다`() { val promiseId = 1L + val location1 = CoordinateVo(100.4, 1.2) + val location2 = CoordinateVo(123.4, 132.6) val promiseUserList = listOf( - PromiseUser(1L, 1L, CoordinateVo(100.4, 1.2), PromiseUserType.READY), - PromiseUser(2L, 2L, CoordinateVo(123.4, 132.6), PromiseUserType.LATE), - PromiseUser(3L, 1L, CoordinateVo(123.445, 6789.612), PromiseUserType.WAIT), + PromiseUser(1L, 1L, location1, PromiseUserType.READY), + PromiseUser(1L, 2L, location2, PromiseUserType.LATE), + ) + val progressHistoryList = listOf( + ProgressHistory(1L, 1L, PromiseProgress.DEFAULT, PromiseProgress.DEFAULT), + ProgressHistory(1L, 2L, PromiseProgress.BED, PromiseProgress.DEFAULT), + ) + val expected = listOf( + PromiseUserDto(1L, 1L, location1, PromiseUserType.READY, PromiseProgress.DEFAULT), + PromiseUserDto(1L, 2L, location2, PromiseUserType.LATE, PromiseProgress.BED), ) `when`(promiseUserDomainService.findByPromiseId(promiseId)).thenReturn(promiseUserList) - + `when`(progressHistoryAdapter.findByPromiseId(promiseId)).thenReturn(progressHistoryList) val result = promiseUserReadUseCase.findByPromiseId(promiseId) - val expected = promiseUserList.map { PromiseUserDto.from(it) } - assertEquals(expected, result) - } - - @Test - fun `userId로_PromiseUser_Type이_READY인_PromiseUser를_조회할_수_있다`() { - val userId = 2L - val promiseUserList = listOf( - PromiseUser(1L, 1L, CoordinateVo(100.4, 1.2), PromiseUserType.READY), - PromiseUser(2L, 2L, CoordinateVo(123.4, 132.6), PromiseUserType.LATE), - PromiseUser(3L, 1L, CoordinateVo(123.445, 6789.612), PromiseUserType.WAIT), - ) - `when`(promiseUserDomainService.findByUserId(userId)).thenReturn(promiseUserList) - - val result = promiseUserReadUseCase.findByUserIdOnReady(userId) - - val expected = promiseUserList - .filter { it.promiseUserType == PromiseUserType.READY } - .map { PromiseUserDto.from(it) } assertEquals(expected, result) } } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/progresshistory/adapter/ProgressHistoryAdapter.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/progresshistory/adapter/ProgressHistoryAdapter.kt index 29b6b274..b9b6c231 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/progresshistory/adapter/ProgressHistoryAdapter.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/progresshistory/adapter/ProgressHistoryAdapter.kt @@ -20,6 +20,11 @@ class ProgressHistoryAdapter( fun delete(progressHistory: ProgressHistory) { promiseHistoryRepository.delete(progressHistory) } + + fun findByPromiseId(promiseId: Long): List { + return promiseHistoryRepository.findByPromiseId(promiseId) + } + // fun findAll(): List { // return promiseHistoryRepository.findAll() // } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/progresshistory/repository/ProgressHistoryRepository.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/progresshistory/repository/ProgressHistoryRepository.kt index 181275c7..1b205770 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/progresshistory/repository/ProgressHistoryRepository.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/progresshistory/repository/ProgressHistoryRepository.kt @@ -2,7 +2,12 @@ package com.depromeet.whatnow.domains.progresshistory.repository import com.depromeet.whatnow.domains.progresshistory.domain.ProgressHistory import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Query interface ProgressHistoryRepository : JpaRepository { fun findByPromiseIdAndUserId(promiseId: Long, userId: Long): ProgressHistory? + + @Query("select ph from ProgressHistory ph where ph.promiseId = :promiseId and ph.userId in :userIds") + fun findByPromiseIdAndUserIdIn(promiseId: Long, userIds: List): List + fun findByPromiseId(promiseId: Long): List } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promiseuser/adaptor/PromiseUserAdaptor.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promiseuser/adaptor/PromiseUserAdaptor.kt index f9459f92..0269b8ed 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promiseuser/adaptor/PromiseUserAdaptor.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promiseuser/adaptor/PromiseUserAdaptor.kt @@ -24,10 +24,10 @@ class PromiseUserAdaptor( } fun findByPromiseId(promiseId: Long): List { - return promiseUserRepository.findByPromiseId(promiseId) + return promiseUserRepository.findByPromiseId(promiseId) ?: run { throw PromiseUserNotFoundException.EXCEPTION } } fun findByUserId(userId: Long): List { - return promiseUserRepository.findByUserId(userId) + return promiseUserRepository.findByUserId(userId) ?: run { throw PromiseUserNotFoundException.EXCEPTION } } fun findByPromiseIdAndUserId(promiseId: Long, userId: Long): PromiseUser { @@ -35,7 +35,7 @@ class PromiseUserAdaptor( } fun findByPromiseIds(promiseIds: List): List { - return promiseUserRepository.findByPromiseIdIn(promiseIds) + return promiseUserRepository.findByPromiseIdIn(promiseIds) ?: run { throw PromiseUserNotFoundException.EXCEPTION } } fun findByUniquePromiseIds(promiseIds: List): Set { 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 6289eb1f..73f19e3a 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 @@ -55,7 +55,7 @@ class PromiseUser( this.promiseUserType = PromiseUserType.LATE } - fun updatePromiseUserType(status: String) { - this.promiseUserType = PromiseUserType.valueOf(status) + fun updatePromiseUserType(promiseUserType: PromiseUserType?) { + this.promiseUserType = promiseUserType } } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promiseuser/repository/PromiseUserRepository.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promiseuser/repository/PromiseUserRepository.kt index c3ded037..a828ee4f 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promiseuser/repository/PromiseUserRepository.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/promiseuser/repository/PromiseUserRepository.kt @@ -7,11 +7,11 @@ import org.springframework.stereotype.Repository @Repository interface PromiseUserRepository : JpaRepository { - fun findByPromiseId(promiseId: Long): List - fun findByUserId(userId: Long): List + fun findByPromiseId(promiseId: Long): List? + fun findByUserId(userId: Long): List? fun findByPromiseIdAndUserId(promiseId: Long, userId: Long): PromiseUser? - fun findByPromiseIdIn(promiseIds: List): List + fun findByPromiseIdIn(promiseIds: List): List? @Query("SELECT DISTINCT p FROM PromiseUser p WHERE p.promiseId IN :promiseIds") fun findByUniquePromiseIdIn(promiseIds: List): Set 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 7ffe7835..e97091bb 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 @@ -2,6 +2,7 @@ package com.depromeet.whatnow.domains.promiseuser.service import com.depromeet.whatnow.domains.promiseuser.adaptor.PromiseUserAdaptor import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUser +import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType import org.springframework.stereotype.Service import javax.transaction.Transactional @@ -24,9 +25,9 @@ class PromiseUserDomainService( } @Transactional - fun updatePromiseUserType(promiseId: Long, userId: Long, status: String): PromiseUser { + fun updatePromiseUserType(promiseId: Long, userId: Long, promiseUserType: PromiseUserType): PromiseUser { val promiseUser = promiseUserAdaptor.findByPromiseIdAndUserId(promiseId, userId) - promiseUser.updatePromiseUserType(status) + promiseUser.updatePromiseUserType(promiseUserType) return promiseUser } From 8be001fe704b86efbf83c7e97112ac72231220bc Mon Sep 17 00:00:00 2001 From: BlackBean99 <54030889+BlackBean99@users.noreply.github.com> Date: Mon, 3 Jul 2023 23:00:22 +0900 Subject: [PATCH 3/7] =?UTF-8?q?[DPMBE-85]=20=ED=98=84=EC=9E=AC=20=EC=95=BD?= =?UTF-8?q?=EC=86=8D=EC=9D=B4=20=ED=99=9C=EC=84=B1=ED=99=94=EC=9D=B8?= =?UTF-8?q?=EC=A7=80=20=EB=B9=84=ED=99=9C=EC=84=B1=ED=99=94=EC=9D=B8?= =?UTF-8?q?=EC=A7=80=20=EA=B5=AC=EB=B6=84=20=EC=A1=B0=ED=9A=8C=20(#130)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat : 약속 활성화 유무 조회 * chore : spotless --- .../whatnow/api/promise/controller/PromiseController.kt | 6 ++++++ .../whatnow/api/promise/usecase/PromiseReadUseCase.kt | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/controller/PromiseController.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/controller/PromiseController.kt index 4dd9249b..2d6042ce 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/controller/PromiseController.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/controller/PromiseController.kt @@ -54,6 +54,12 @@ class PromiseController( return promiseReadUseCase.findPromiseDetailByStatus(status) } + @Operation(summary = "현재 약속이 활성화 상태인지 비활성화 상태인지 조회", description = "현재 약속이 활성화 상태인지 비활성화 상태인지 조회한다.") + @GetMapping("/promises/{promise-id}/active") + fun findPromiseActive(@PathVariable(value = "promise-id") promiseId: Long): Boolean { + return promiseReadUseCase.findPromiseActive(promiseId) + } + @Operation(summary = "약속(promise) 생성", description = "약속을 생성합니다.") @PostMapping("/promises") fun createPromise(@RequestBody promiseRequest: PromiseRequest): PromiseDto { diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/PromiseReadUseCase.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/PromiseReadUseCase.kt index e0e76a16..378845e2 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/PromiseReadUseCase.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/usecase/PromiseReadUseCase.kt @@ -14,6 +14,7 @@ import com.depromeet.whatnow.domains.promiseuser.adaptor.PromiseUserAdaptor import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUser import com.depromeet.whatnow.domains.user.adapter.UserAdapter import com.depromeet.whatnow.domains.user.repository.UserRepository +import java.time.LocalDateTime import java.time.YearMonth @UseCase @@ -135,4 +136,12 @@ class PromiseReadUseCase( } return result } + + fun findPromiseActive(promiseId: Long): Boolean { + val promise = promiseAdaptor.queryPromise(promiseId) + // 현재 시간이 endTime 의1시간 전과 30분 이후 사이에 있으면 true + val now = LocalDateTime.now() + val endTime = promise.endTime + return now.isAfter(endTime.minusHours(1)) && now.isBefore(endTime.plusMinutes(30)) + } } From 4a3c1ce3bca25910517b525627c6e36230db7309 Mon Sep 17 00:00:00 2001 From: BlackBean99 <54030889+BlackBean99@users.noreply.github.com> Date: Mon, 3 Jul 2023 23:00:40 +0900 Subject: [PATCH 4/7] =?UTF-8?q?[DPMBE-91]=EB=AA=BD=EA=B3=A0=EB=94=94?= =?UTF-8?q?=EB=B9=84=20=EC=8A=A4=ED=8A=B8=EB=A6=BC=20=EC=BB=A4=EB=84=A5?= =?UTF-8?q?=EC=85=98=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95=20(#131)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor : exclude mongoAutoConfig - application.yml exclude add * refactor: yml 설정 변경 --- .../kotlin/com/depromeet/whatnow/WhatnowDomainApplication.kt | 3 --- .../src/main/resources/application-infrastructure.yml | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/WhatnowDomainApplication.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/WhatnowDomainApplication.kt index acfb8cae..f40ec9b2 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/WhatnowDomainApplication.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/WhatnowDomainApplication.kt @@ -1,12 +1,9 @@ package com.depromeet.whatnow -import com.depromeet.whatnow.config.mongo.MongoConfig import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication -import org.springframework.context.annotation.Import @SpringBootApplication -@Import(MongoConfig::class) class WhatnowDomainApplication fun main(args: Array) { diff --git a/Whatnow-Infrastructure/src/main/resources/application-infrastructure.yml b/Whatnow-Infrastructure/src/main/resources/application-infrastructure.yml index af537f25..0d282aa9 100644 --- a/Whatnow-Infrastructure/src/main/resources/application-infrastructure.yml +++ b/Whatnow-Infrastructure/src/main/resources/application-infrastructure.yml @@ -14,6 +14,10 @@ data: username: ${MONGO_USERNAME} password: ${MONGO_PASSWORD} spring: + autoconfigure: + exclude: + - org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration + - org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration redis: host: ${REDIS_HOST:localhost} port: ${REDIS_PORT:6379} From 3a47efa50ed2274ac9d9625a1a8baa24302cd66f Mon Sep 17 00:00:00 2001 From: BlackBean99 <54030889+BlackBean99@users.noreply.github.com> Date: Tue, 4 Jul 2023 00:44:34 +0900 Subject: [PATCH 5/7] =?UTF-8?q?[DPMBE-97]=20=EA=B2=80=EC=83=89=20=ED=82=A4?= =?UTF-8?q?=EC=9B=8C=EB=93=9C=20=EC=A1=B0=ED=9A=8C=20=EB=B2=84=EA=B7=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#138)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor : properties 변경 * refactor : test 코드 수정 --- .../whatnow/api/location/helper/NcpHelper.kt | 3 --- .../api/promise/controller/LocalController.kt | 3 ++- .../depromeet/whatnow/api/NcpLocalSearchClient.kt | 2 +- .../depromeet/whatnow/api/config/ncp/NcpConfig.kt | 13 ------------- .../main/resources/application-infrastructure.yml | 4 ++-- .../whatnow/config/ncp/NcpLocalSearchClientTest.kt | 9 +++++---- .../whatnow/config/ncp/NcpPropertiesTest.kt | 2 +- 7 files changed, 11 insertions(+), 25 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 6d0b4710..754ae8c2 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 @@ -14,9 +14,6 @@ class NcpHelper( // 검색 키워드 조회 fun getLocalSearch(keyword: String): NcpMapInfoResponse { - println("ncpPropertie.accessKey: ${ncpPropertie.accessKey}") - println("ncpPropertie.secretKey: ${ncpPropertie.secretKey}") - return ncpClient.searchByKeyword(ncpPropertie.accessKey, ncpPropertie.secretKey, keyword) } } diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/controller/LocalController.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/controller/LocalController.kt index 00cc322a..2e59afbe 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/controller/LocalController.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/promise/controller/LocalController.kt @@ -4,15 +4,16 @@ import com.depromeet.whatnow.api.dto.NcpMapInfoResponse import com.depromeet.whatnow.api.location.helper.NcpHelper import com.depromeet.whatnow.api.promise.usecase.GetDistrictUseCase import io.swagger.v3.oas.annotations.Operation +import io.swagger.v3.oas.annotations.security.SecurityRequirement import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController -// @SecurityRequirement(name = "access-token") @RestController @RequestMapping("/v1") +@SecurityRequirement(name = "access-token") @Tag(name = "3.1 [약속-장소]") class LocalController( val getDistrictUseCase: GetDistrictUseCase, 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 fe4952c1..cccc54f7 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 @@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RequestHeader import org.springframework.web.bind.annotation.RequestParam @FeignClient(name = "NcpLocalSearchClient", url = "\${ncp.local.search-url}", configuration = [NcpConfig::class]) interface NcpLocalSearchClient { - @GetMapping("/search") + @GetMapping("/local.json") fun searchByKeyword( @RequestHeader("X-Naver-Client-Id") accessKey: String, @RequestHeader("X-Naver-Client-Secret") secretKey: String, diff --git a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/ncp/NcpConfig.kt b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/ncp/NcpConfig.kt index e6bd1bd8..40bddd63 100644 --- a/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/ncp/NcpConfig.kt +++ b/Whatnow-Infrastructure/src/main/kotlin/com/depromeet/whatnow/api/config/ncp/NcpConfig.kt @@ -1,7 +1,5 @@ package com.depromeet.whatnow.api.config.ncp -import feign.RequestInterceptor -import feign.RequestTemplate import feign.codec.ErrorDecoder import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.context.annotation.Bean @@ -14,15 +12,4 @@ class NcpConfig { fun commonFeignErrorDecoder(): NcpInfoErrorDecoder { return NcpInfoErrorDecoder() } - - @Bean - fun basicAuthRequestInterceptor(): RequestInterceptor { - return ColonInterceptor() - } - - class ColonInterceptor : RequestInterceptor { - override fun apply(template: RequestTemplate) { - template.uri(template.path().replace("%3A".toRegex(), ":")) - } - } } diff --git a/Whatnow-Infrastructure/src/main/resources/application-infrastructure.yml b/Whatnow-Infrastructure/src/main/resources/application-infrastructure.yml index 0d282aa9..5749113e 100644 --- a/Whatnow-Infrastructure/src/main/resources/application-infrastructure.yml +++ b/Whatnow-Infrastructure/src/main/resources/application-infrastructure.yml @@ -59,8 +59,8 @@ ncp: local: access-key: ${NCP_LOCAL_ACCESS_KEY} secret-key: ${NCP_LOCAL_SECRET_KEY} - search-url: ${NCP_LOCAL_SEARCH_URL:https://openapi.naver.com/v1/search/local.json} - + search-url: ${NCP_LOCAL_SEARCH_URL:https://openapi.naver.com/v1/search} + certification: ${NCP_LOCAL_CERTIFICATION} fcm: certification: ${FCM_CERTIFICATION:} 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 bb8b3165..1308530d 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 @@ -27,20 +27,21 @@ import org.springframework.util.ResourceUtils @ActiveProfiles(resolver = InfraIntegrateProfileResolver::class) @TestPropertySource(properties = ["ncp.local.search-url=http://localhost:\${wiremock.server.port}"]) @ContextConfiguration(classes = [FeignClientsConfiguration::class, NcpConfig::class]) -class NcpLocalSearchClientTest { +class NcpLocalSearchClientTest() { @Autowired lateinit var client: NcpLocalSearchClient @Test fun `testSearchByKeyword`() { - val file = ResourceUtils.getFile("classpath:payload/ncp-local-search-response.json") - val responseJson = file.readText() +// application- + val file = ResourceUtils.getFile("classpath:payload/ncp-local-search-response.json").readText() + val responseJson = file val accessKey = "your-access-key" val secretKey = "your-secret-key" val query = "강남" WireMock.stubFor( - get(urlPathEqualTo("/search")) + get(urlPathEqualTo("/local.json")) .withHeader("X-Naver-Client-Id", equalTo(accessKey)) .withHeader("X-Naver-Client-Secret", equalTo(secretKey)) .withQueryParam("query", equalTo(query)) diff --git a/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/config/ncp/NcpPropertiesTest.kt b/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/config/ncp/NcpPropertiesTest.kt index d77aba6d..9a8d2294 100644 --- a/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/config/ncp/NcpPropertiesTest.kt +++ b/Whatnow-Infrastructure/src/test/kotlin/com/depromeet/whatnow/config/ncp/NcpPropertiesTest.kt @@ -13,6 +13,6 @@ class NcpPropertiesTest { @Test fun `ncp 프로퍼티가 제대로 init 되어야한다`() { - Assertions.assertEquals(ncpProperties.local.searchUrl, "https://openapi.naver.com/v1/search/local.json") + Assertions.assertEquals(ncpProperties.local.searchUrl, "https://openapi.naver.com/v1/search") } } From bffb93aba09fcb7973109fd4d02bd220ecf4eaf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EB=AA=A8?= Date: Tue, 4 Jul 2023 03:42:02 +0900 Subject: [PATCH 6/7] =?UTF-8?q?feat:=20=EC=9D=B8=ED=84=B0=EB=A0=89?= =?UTF-8?q?=EC=85=98=20=EC=A1=B0=ED=9A=8C=20=EC=9D=91=EB=8B=B5=EA=B0=92?= =?UTF-8?q?=EC=97=90=20Progress=20=EA=B0=92=EC=9D=84=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=ED=95=9C=EB=8B=A4=20(#127)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/interaction/dto/InteractionResponse.kt | 3 +++ .../interaction/usecase/InteractionReadUseCase.kt | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/interaction/dto/InteractionResponse.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/interaction/dto/InteractionResponse.kt index ba4bcc4b..cd1e42c1 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/interaction/dto/InteractionResponse.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/interaction/dto/InteractionResponse.kt @@ -1,5 +1,8 @@ package com.depromeet.whatnow.api.interaction.dto +import com.depromeet.whatnow.api.promiseprogress.dto.response.UserProgressResponse + data class InteractionResponse( + val userProgressResponse: UserProgressResponse, val interactionDtoList: List, ) diff --git a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/interaction/usecase/InteractionReadUseCase.kt b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/interaction/usecase/InteractionReadUseCase.kt index 6d315c45..3b43a517 100644 --- a/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/interaction/usecase/InteractionReadUseCase.kt +++ b/Whatnow-Api/src/main/kotlin/com/depromeet/whatnow/api/interaction/usecase/InteractionReadUseCase.kt @@ -3,17 +3,29 @@ package com.depromeet.whatnow.api.interaction.usecase import com.depromeet.whatnow.annotation.UseCase import com.depromeet.whatnow.api.interaction.dto.InteractionDto import com.depromeet.whatnow.api.interaction.dto.InteractionResponse +import com.depromeet.whatnow.api.promiseprogress.dto.response.UserProgressResponse import com.depromeet.whatnow.config.security.SecurityUtils import com.depromeet.whatnow.domains.interaction.service.InteractionDomainService +import com.depromeet.whatnow.domains.progresshistory.adapter.ProgressHistoryAdapter +import com.depromeet.whatnow.domains.user.adapter.UserAdapter @UseCase class InteractionReadUseCase( val interactionDomainService: InteractionDomainService, + val progressHistoryAdapter: ProgressHistoryAdapter, + val userAdapter: UserAdapter, ) { fun findMyInteraction(promiseId: Long): InteractionResponse { val userId: Long = SecurityUtils.currentUserId + val history = progressHistoryAdapter.findByPromiseIdAndUserId(promiseId, userId) + val userProgressResponse = UserProgressResponse( + userAdapter.queryUser(userId).toUserInfoVo(), + history.currentPromiseProgress, + history.prePromiseProgress, + ) return InteractionResponse( + userProgressResponse, interactionDomainService.queryAllInteraction(promiseId, userId).map { InteractionDto.from(it) }, ) } From 46af5f57628ea47800bc1c628f035aae404f874a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EB=AA=A8?= Date: Tue, 4 Jul 2023 03:42:13 +0900 Subject: [PATCH 7/7] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EB=8F=84=EB=A9=94=EC=9D=B8=EC=9D=84=20User=EC=99=80=20Promise?= =?UTF-8?q?=EB=A1=9C=20=EB=B6=84=EB=A6=AC=ED=95=98=EA=B3=A0=20Promise?= =?UTF-8?q?=EC=97=90=20=EC=A2=8C=ED=91=9C=EA=B0=92=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(#135)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/image/controller/ImageController.kt | 27 +++++--- .../usecase/ImageUploadSuccessUseCase.kt | 14 ++-- ...rTest.kt => PromiseImageControllerTest.kt} | 25 ++++--- ...> PromiseImageUploadSuccessUseCaseTest.kt} | 8 ++- .../depromeet/whatnow/consts/WhatNowStatic.kt | 2 +- .../domains/image/adapter/ImageAdapter.kt | 21 ------ .../image/adapter/PromiseImageAdapter.kt | 14 ++++ .../domains/image/adapter/UserImageAdapter.kt | 14 ++++ .../whatnow/domains/image/domain/Image.kt | 69 ------------------- .../whatnow/domains/image/domain/ImageType.kt | 5 -- .../domains/image/domain/PromiseImage.kt | 57 +++++++++++++++ ...mentType.kt => PromiseImageCommentType.kt} | 4 +- .../whatnow/domains/image/domain/UserImage.kt | 30 ++++++++ .../repository/PromiseImageRepository.kt | 8 +++ ...geRepository.kt => UserImageRepository.kt} | 4 +- .../image/service/ImageDomainService.kt | 40 +++++++---- .../whatnow/domains/user/domain/User.kt | 7 -- ...rEvent.kt => PromiseImageRegisterEvent.kt} | 2 +- .../handler/ImageRegisterEventHandler.kt | 10 +-- .../domains/image/adapter/ImageAdapterTest.kt | 57 --------------- .../adapter/PromisePromiseImageAdapterTest.kt | 42 +++++++++++ ...st.kt => PromiseImageDomainServiceTest.kt} | 40 +++++------ ...sePromiseImageRegisterEventHandlerTest.kt} | 23 ++----- 23 files changed, 274 insertions(+), 249 deletions(-) rename Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/controller/{ImageControllerTest.kt => PromiseImageControllerTest.kt} (73%) rename Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/usecase/{ImageUploadSuccessUseCaseTest.kt => PromiseImageUploadSuccessUseCaseTest.kt} (86%) delete mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/adapter/ImageAdapter.kt create mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/adapter/PromiseImageAdapter.kt create mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/adapter/UserImageAdapter.kt delete mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/Image.kt delete mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/ImageType.kt create mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/PromiseImage.kt rename Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/{ImageCommentType.kt => PromiseImageCommentType.kt} (86%) create mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/UserImage.kt create mode 100644 Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/repository/PromiseImageRepository.kt rename Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/repository/{ImageRepository.kt => UserImageRepository.kt} (59%) rename Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/{ImageRegisterEvent.kt => PromiseImageRegisterEvent.kt} (84%) delete mode 100644 Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/domains/image/adapter/ImageAdapterTest.kt create mode 100644 Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/domains/image/adapter/PromisePromiseImageAdapterTest.kt rename Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/domains/image/service/{ImageDomainServiceTest.kt => PromiseImageDomainServiceTest.kt} (77%) rename Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/handler/{ImageRegisterEventHandlerTest.kt => PromisePromiseImageRegisterEventHandlerTest.kt} (63%) 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 ad6d1a3b..94549e46 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 @@ -3,17 +3,20 @@ package com.depromeet.whatnow.api.image.controller import com.depromeet.whatnow.api.image.dto.ImageUrlResponse import com.depromeet.whatnow.api.image.usecase.GetPresignedUrlUseCase import com.depromeet.whatnow.api.image.usecase.ImageUploadSuccessUseCase +import com.depromeet.whatnow.common.vo.CoordinateVo import com.depromeet.whatnow.config.s3.ImageFileExtension -import com.depromeet.whatnow.domains.image.domain.ImageCommentType +import com.depromeet.whatnow.domains.image.domain.PromiseImageCommentType import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.security.SecurityRequirement import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController +import javax.validation.Valid @RestController @Tag(name = "6. [이미지]") @@ -23,8 +26,8 @@ class ImageController( val getPresignedUrlUseCase: GetPresignedUrlUseCase, val successUseCase: ImageUploadSuccessUseCase, ) { - @Operation(summary = "약속 관련 이미지 업로드 Presigned URL 발급") - @GetMapping("/promises/{promiseId}/images") + @Operation(summary = "약속 이미지 업로드 Presigned URL 발급") + @GetMapping("/images/promises/{promiseId}") fun getPresignedUrlOfPromise( @PathVariable promiseId: Long, @RequestParam fileExtension: ImageFileExtension, @@ -33,21 +36,27 @@ class ImageController( } @Operation(summary = "유저 프로필 이미지 업로드 Presigned URL 발급") - @GetMapping("/users/me/images") + @GetMapping("/images/users/me") fun getPresignedUrlOfUser( @RequestParam fileExtension: ImageFileExtension, ): ImageUrlResponse { return getPresignedUrlUseCase.forUser(fileExtension) } - @Operation(summary = "약속 관련 이미지 업로드 성공 요청") - @PostMapping("/promises/{promiseId}/images/success/{imageKey}") - fun promiseUploadImageSuccess(@PathVariable promiseId: Long, @PathVariable imageKey: String, @RequestParam imageCommentType: ImageCommentType) { - successUseCase.promiseUploadImageSuccess(promiseId, imageKey, imageCommentType) + @Operation(summary = "약속 이미지 업로드 성공 요청") + @PostMapping("/images/{imageKey}/promises/{promiseId}") + fun promiseUploadImageSuccess( + @PathVariable promiseId: Long, + @PathVariable imageKey: String, + @RequestParam promiseImageCommentType: PromiseImageCommentType, + @RequestBody @Valid + userLocation: CoordinateVo, + ) { + successUseCase.promiseUploadImageSuccess(promiseId, imageKey, promiseImageCommentType, userLocation) } @Operation(summary = "유저 프로필 이미지 업로드 성공 요청") - @PostMapping("/users/me/images/success/{imageKey}") + @PostMapping("/images/{imageKey}/users/me") fun userUploadImageSuccess(@PathVariable imageKey: String) { successUseCase.userUploadImageSuccess(imageKey) } 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 35b10402..cd5b78d7 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,21 +1,27 @@ package com.depromeet.whatnow.api.image.usecase import com.depromeet.whatnow.annotation.UseCase +import com.depromeet.whatnow.common.vo.CoordinateVo import com.depromeet.whatnow.config.security.SecurityUtils -import com.depromeet.whatnow.domains.image.domain.ImageCommentType +import com.depromeet.whatnow.domains.image.domain.PromiseImageCommentType import com.depromeet.whatnow.domains.image.service.ImageDomainService @UseCase class ImageUploadSuccessUseCase( val imageDomainService: ImageDomainService, ) { - fun promiseUploadImageSuccess(promiseId: Long, imageKey: String, imageCommentType: ImageCommentType) { + fun promiseUploadImageSuccess( + promiseId: Long, + imageKey: String, + promiseImageCommentType: PromiseImageCommentType, + userLocation: CoordinateVo, + ) { val currentUserId: Long = SecurityUtils.currentUserId - imageDomainService.promiseUploadImageSuccess(currentUserId, promiseId, imageKey, imageCommentType) + imageDomainService.promiseImageUploadSuccess(currentUserId, promiseId, imageKey, promiseImageCommentType, userLocation) } fun userUploadImageSuccess(imageKey: String) { val currentUserId: Long = SecurityUtils.currentUserId - imageDomainService.userUploadImageSuccess(currentUserId, imageKey) + imageDomainService.userImageUploadSuccess(currentUserId, imageKey) } } diff --git a/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/controller/ImageControllerTest.kt b/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/controller/PromiseImageControllerTest.kt similarity index 73% rename from Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/controller/ImageControllerTest.kt rename to Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/controller/PromiseImageControllerTest.kt index 61c84b83..fbf5e548 100644 --- a/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/controller/ImageControllerTest.kt +++ b/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/controller/PromiseImageControllerTest.kt @@ -2,13 +2,16 @@ package com.depromeet.whatnow.api.image.controller import com.depromeet.whatnow.api.image.usecase.GetPresignedUrlUseCase import com.depromeet.whatnow.api.image.usecase.ImageUploadSuccessUseCase +import com.depromeet.whatnow.common.vo.CoordinateVo import com.depromeet.whatnow.config.s3.ImageFileExtension -import com.depromeet.whatnow.domains.image.domain.ImageCommentType +import com.depromeet.whatnow.domains.image.domain.PromiseImageCommentType +import com.fasterxml.jackson.databind.ObjectMapper import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest import org.springframework.boot.test.mock.mockito.MockBean +import org.springframework.http.MediaType import org.springframework.test.context.ContextConfiguration import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders @@ -18,7 +21,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status @WebMvcTest(ImageController::class) @ContextConfiguration(classes = [ImageController::class]) @AutoConfigureMockMvc(addFilters = false) -class ImageControllerTest { +class PromiseImageControllerTest { @MockBean lateinit var getPresignedUrlUseCase: GetPresignedUrlUseCase @@ -28,6 +31,9 @@ class ImageControllerTest { @Autowired lateinit var mockMvc: MockMvc + @Autowired + lateinit var objectMapper: ObjectMapper + @Test fun `약속 이미지 presignedUrl 요청에 성공하면 200을 응답한다`() { // given @@ -36,7 +42,7 @@ class ImageControllerTest { // when, then mockMvc.perform( - get("/v1/promises/{promiseId}/images", promiseId) + get("/v1/images/promises/{promiseId}", promiseId) .param("fileExtension", fileExtension), ) .andExpect(status().isOk) @@ -50,7 +56,7 @@ class ImageControllerTest { // when, then mockMvc.perform( - get("/v1/users/me/images") + get("/v1/images/users/me") .param("fileExtension", fileExtension), ) .andExpect(status().isOk) @@ -62,12 +68,15 @@ class ImageControllerTest { // given val promiseId = 1 val imageKey = "imageKey" - val imageCommentType = ImageCommentType.SORRY_LATE + val promiseImageCommentType = PromiseImageCommentType.SORRY_LATE + val userLocation = CoordinateVo(127.3, 23.0) // when, then mockMvc.perform( - MockMvcRequestBuilders.post("/v1/promises/{promiseId}/images/success/{imageKey}", promiseId, imageKey) - .param("imageCommentType", imageCommentType.name), + MockMvcRequestBuilders.post("/v1/images/{imageKey}/promises/{promiseId}", imageKey, promiseId) + .param("promiseImageCommentType", promiseImageCommentType.name) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(userLocation)), ) .andExpect(status().isOk) .andDo { print(it) } @@ -80,7 +89,7 @@ class ImageControllerTest { // when, then mockMvc.perform( - MockMvcRequestBuilders.post("/v1/users/me/images/success/{imageKey}", imageKey), + MockMvcRequestBuilders.post("/v1/images/{imageKey}/users/me", imageKey), ) .andExpect(status().isOk) .andDo { print(it) } diff --git a/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/usecase/ImageUploadSuccessUseCaseTest.kt b/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/usecase/PromiseImageUploadSuccessUseCaseTest.kt similarity index 86% rename from Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/usecase/ImageUploadSuccessUseCaseTest.kt rename to Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/usecase/PromiseImageUploadSuccessUseCaseTest.kt index 0bf5aaa9..664f47fb 100644 --- a/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/usecase/ImageUploadSuccessUseCaseTest.kt +++ b/Whatnow-Api/src/test/kotlin/com/depromeet/whatnow/api/image/usecase/PromiseImageUploadSuccessUseCaseTest.kt @@ -1,6 +1,7 @@ package com.depromeet.whatnow.api.image.usecase -import com.depromeet.whatnow.domains.image.domain.ImageCommentType +import com.depromeet.whatnow.common.vo.CoordinateVo +import com.depromeet.whatnow.domains.image.domain.PromiseImageCommentType import com.depromeet.whatnow.domains.image.service.ImageDomainService import org.assertj.core.api.Assertions.assertThatCode import org.junit.jupiter.api.BeforeEach @@ -14,7 +15,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority import org.springframework.security.core.context.SecurityContextHolder @ExtendWith(MockitoExtension::class) -class ImageUploadSuccessUseCaseTest { +class PromiseImageUploadSuccessUseCaseTest { @Mock lateinit var imageDomainService: ImageDomainService @@ -32,12 +33,13 @@ class ImageUploadSuccessUseCaseTest { @Test fun `약속 이미지 업로드 성공 요청시 정상적이라면 에러가 발생하지 않는다`() { // given + val coordinateVo = CoordinateVo(1.0, 1.0) // when // then assertThatCode { - imageUploadSuccessUseCase.promiseUploadImageSuccess(1, "imageKey", ImageCommentType.SORRY_LATE) + imageUploadSuccessUseCase.promiseUploadImageSuccess(1, "imageKey", PromiseImageCommentType.SORRY_LATE, coordinateVo) }.doesNotThrowAnyException() } 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 050f09b1..298684b6 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,7 +26,7 @@ const val DEV = "dev" const val LOCAL = "local" const val WITHDRAW_PREFIX = "withdraw" -const val IMAGE_DOMAIN = "https://image.whatnow.kr/" +const val IMAGE_DOMAIN = "https://image.whatnow.kr" val SWAGGER_PATTERNS = arrayOf( "/swagger-resources/**", diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/adapter/ImageAdapter.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/adapter/ImageAdapter.kt deleted file mode 100644 index 46b1edbb..00000000 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/adapter/ImageAdapter.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.depromeet.whatnow.domains.image.adapter - -import com.depromeet.whatnow.annotation.Adapter -import com.depromeet.whatnow.domains.image.domain.Image -import com.depromeet.whatnow.domains.image.domain.ImageCommentType -import com.depromeet.whatnow.domains.image.repository.ImageRepository - -@Adapter -class ImageAdapter( - val imageRepository: ImageRepository, -) { - fun saveForPromise(userId: Long, promiseId: Long, imageUrl: String, imageKey: String, imageCommentType: ImageCommentType): Image { - val image = Image.createForPromise(userId, promiseId, imageUrl, imageKey, imageCommentType) - return imageRepository.save(image) - } - - fun saveForUser(userId: Long, imageUrl: String, imageKey: String): Image { - val image = Image.createForUser(userId, imageUrl, imageKey) - return imageRepository.save(image) - } -} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/adapter/PromiseImageAdapter.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/adapter/PromiseImageAdapter.kt new file mode 100644 index 00000000..05c09ea2 --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/adapter/PromiseImageAdapter.kt @@ -0,0 +1,14 @@ +package com.depromeet.whatnow.domains.image.adapter + +import com.depromeet.whatnow.annotation.Adapter +import com.depromeet.whatnow.domains.image.domain.PromiseImage +import com.depromeet.whatnow.domains.image.repository.PromiseImageRepository + +@Adapter +class PromiseImageAdapter( + val promiseImageRepository: PromiseImageRepository, +) { + fun save(promiseImage: PromiseImage): PromiseImage { + return promiseImageRepository.save(promiseImage) + } +} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/adapter/UserImageAdapter.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/adapter/UserImageAdapter.kt new file mode 100644 index 00000000..ac0480ae --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/adapter/UserImageAdapter.kt @@ -0,0 +1,14 @@ +package com.depromeet.whatnow.domains.image.adapter + +import com.depromeet.whatnow.annotation.Adapter +import com.depromeet.whatnow.domains.image.domain.UserImage +import com.depromeet.whatnow.domains.image.repository.UserImageRepository + +@Adapter +class UserImageAdapter( + val userImageRepository: UserImageRepository, +) { + fun save(userImage: UserImage): UserImage { + return userImageRepository.save(userImage) + } +} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/Image.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/Image.kt deleted file mode 100644 index a7c4a5b6..00000000 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/Image.kt +++ /dev/null @@ -1,69 +0,0 @@ -package com.depromeet.whatnow.domains.image.domain - -import com.depromeet.whatnow.common.BaseTimeEntity -import com.depromeet.whatnow.common.aop.event.Events -import com.depromeet.whatnow.events.domainEvent.ImageRegisterEvent -import javax.persistence.Column -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 -@Table(name = "tbl_image") -class Image( - var userId: Long, - - var promiseId: Long, - - var uri: String, - - var imageKey: String, - - @Enumerated(EnumType.STRING) - var imageType: ImageType, - - @Enumerated(EnumType.STRING) - var imageCommentType: ImageCommentType = ImageCommentType.NONE, - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "picture_id") - val id: Long? = null, -) : BaseTimeEntity() { - companion object { - fun createForPromise(userId: Long, promiseId: Long, uri: String, imageKey: String, imageCommentType: ImageCommentType): Image { - return Image( - userId = userId, - promiseId = promiseId, - uri = uri, - imageKey = imageKey, - imageType = ImageType.PROMISE, - imageCommentType = imageCommentType, - ) - } - - fun createForUser(userId: Long, uri: String, imageKey: String): Image { - return Image( - userId = userId, - promiseId = 0, - uri = uri, - imageKey = imageKey, - imageType = ImageType.USER, - imageCommentType = ImageCommentType.NONE, - ) - } - } - - @PostPersist - fun createImageEvent() { - if (this.imageType == ImageType.USER) { - return - } - Events.raise(ImageRegisterEvent(userId, promiseId)) - } -} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/ImageType.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/ImageType.kt deleted file mode 100644 index dc7ee6f5..00000000 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/ImageType.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.depromeet.whatnow.domains.image.domain - -enum class ImageType { - PROMISE, USER -} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/PromiseImage.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/PromiseImage.kt new file mode 100644 index 00000000..21863485 --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/PromiseImage.kt @@ -0,0 +1,57 @@ +package com.depromeet.whatnow.domains.image.domain + +import com.depromeet.whatnow.common.BaseTimeEntity +import com.depromeet.whatnow.common.aop.event.Events +import com.depromeet.whatnow.common.vo.CoordinateVo +import com.depromeet.whatnow.events.domainEvent.PromiseImageRegisterEvent +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 +@Table(name = "tbl_promise_image") +class PromiseImage( + var userId: Long, + + var promiseId: Long, + + var uri: String, + + var imageKey: String, + + @Enumerated(EnumType.STRING) + var promiseImageCommentType: PromiseImageCommentType, + + @Embedded + var userLocation: CoordinateVo? = null, + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "promise_image_id") + val id: Long? = null, +) : BaseTimeEntity() { + companion object { + fun of( + userId: Long, + promiseId: Long, + uri: String, + imageKey: String, + promiseImageCommentType: PromiseImageCommentType, + userLocation: CoordinateVo, + ): PromiseImage { + return PromiseImage(userId, promiseId, uri, imageKey, promiseImageCommentType, userLocation) + } + } + + @PostPersist + fun createImageEvent() { + Events.raise(PromiseImageRegisterEvent(userId, promiseId)) + } +} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/ImageCommentType.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/PromiseImageCommentType.kt similarity index 86% rename from Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/ImageCommentType.kt rename to Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/PromiseImageCommentType.kt index 24fb877a..5587c6df 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/ImageCommentType.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/PromiseImageCommentType.kt @@ -2,9 +2,7 @@ package com.depromeet.whatnow.domains.image.domain import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType -enum class ImageCommentType(val value: String, val promiseUserType: PromiseUserType?) { - NONE("NONE", null), - +enum class PromiseImageCommentType(val value: String, val promiseUserType: PromiseUserType?) { // Can LATE RUNNING("달려가는 중️", PromiseUserType.LATE), GASPING("헐레벌떡", PromiseUserType.LATE), diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/UserImage.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/UserImage.kt new file mode 100644 index 00000000..425279d9 --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/domain/UserImage.kt @@ -0,0 +1,30 @@ +package com.depromeet.whatnow.domains.image.domain + +import com.depromeet.whatnow.common.BaseTimeEntity +import javax.persistence.Column +import javax.persistence.Entity +import javax.persistence.GeneratedValue +import javax.persistence.GenerationType +import javax.persistence.Id +import javax.persistence.Table + +@Entity +@Table(name = "tbl_user_image") +class UserImage( + var userId: Long, + + var uri: String, + + var imageKey: String, + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "user_image_id") + val id: Long? = null, +) : BaseTimeEntity() { + companion object { + fun of(userId: Long, uri: String, imageKey: String): UserImage { + return UserImage(userId, uri, imageKey) + } + } +} diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/repository/PromiseImageRepository.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/repository/PromiseImageRepository.kt new file mode 100644 index 00000000..87f0d213 --- /dev/null +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/repository/PromiseImageRepository.kt @@ -0,0 +1,8 @@ +package com.depromeet.whatnow.domains.image.repository + +import com.depromeet.whatnow.domains.image.domain.PromiseImage +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository + +@Repository +interface PromiseImageRepository : JpaRepository diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/repository/ImageRepository.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/repository/UserImageRepository.kt similarity index 59% rename from Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/repository/ImageRepository.kt rename to Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/repository/UserImageRepository.kt index c1c07eac..a2c86e52 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/repository/ImageRepository.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/image/repository/UserImageRepository.kt @@ -1,8 +1,8 @@ package com.depromeet.whatnow.domains.image.repository -import com.depromeet.whatnow.domains.image.domain.Image +import com.depromeet.whatnow.domains.image.domain.UserImage import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository @Repository -interface ImageRepository : JpaRepository +interface UserImageRepository : JpaRepository 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 0b5bf74a..8247afb9 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 @@ -1,8 +1,12 @@ package com.depromeet.whatnow.domains.image.service +import com.depromeet.whatnow.common.vo.CoordinateVo import com.depromeet.whatnow.consts.IMAGE_DOMAIN -import com.depromeet.whatnow.domains.image.adapter.ImageAdapter -import com.depromeet.whatnow.domains.image.domain.ImageCommentType +import com.depromeet.whatnow.domains.image.adapter.PromiseImageAdapter +import com.depromeet.whatnow.domains.image.adapter.UserImageAdapter +import com.depromeet.whatnow.domains.image.domain.PromiseImage +import com.depromeet.whatnow.domains.image.domain.PromiseImageCommentType +import com.depromeet.whatnow.domains.image.domain.UserImage import com.depromeet.whatnow.domains.image.exception.CancelledUserUploadException import com.depromeet.whatnow.domains.image.exception.InvalidCommentTypeException import com.depromeet.whatnow.domains.image.exception.UploadBeforeTrackingException @@ -15,33 +19,41 @@ import org.springframework.transaction.annotation.Transactional @Service class ImageDomainService( - val imageAdapter: ImageAdapter, + val promiseImageAdapter: PromiseImageAdapter, + val userImageAdapter: UserImageAdapter, val promiseUserAdapter: PromiseUserAdaptor, val userAdapter: UserAdapter, val springEnvironmentHelper: SpringEnvironmentHelper, ) { @Transactional - fun promiseUploadImageSuccess(userId: Long, promiseId: Long, imageKey: String, imageCommentType: ImageCommentType) { + fun promiseImageUploadSuccess( + userId: Long, + promiseId: Long, + imageKey: String, + promiseImageCommentType: PromiseImageCommentType, + userLocation: CoordinateVo, + ) { val promiseUser = promiseUserAdapter.findByPromiseIdAndUserId(promiseId, userId) - validatePromiseUserType(promiseUser.promiseUserType!!, imageCommentType) + validatePromiseUserType(promiseUser.promiseUserType!!, promiseImageCommentType) - val imageUrl = IMAGE_DOMAIN + springEnvironmentHelper.activeProfile + "/" + "promise/$promiseId/$imageKey" - imageAdapter.saveForPromise(userId, promiseId, imageUrl, imageKey, imageCommentType) + val imageUrl = IMAGE_DOMAIN + "/" + springEnvironmentHelper.activeProfile + "/" + "promise/$promiseId/$imageKey" + promiseImageAdapter.save( + PromiseImage.of(promiseId, userId, imageUrl, imageKey, promiseImageCommentType, userLocation), + ) } - fun userUploadImageSuccess(userId: Long, imageKey: String) { - val user = userAdapter.queryUser(userId) - val imageUrl = IMAGE_DOMAIN + springEnvironmentHelper.activeProfile + "/" + "user/$userId/$imageKey" - imageAdapter.saveForUser(userId, imageUrl, imageKey) - user.updateProfileImg(imageUrl) + @Transactional + fun userImageUploadSuccess(userId: Long, imageKey: String) { + val imageUrl = IMAGE_DOMAIN + "/" + springEnvironmentHelper.activeProfile + "/" + "user/$userId/$imageKey" + userImageAdapter.save(UserImage.of(userId, imageUrl, imageKey)) } - private fun validatePromiseUserType(promiseUserType: PromiseUserType, imageCommentType: ImageCommentType) { + private fun validatePromiseUserType(promiseUserType: PromiseUserType, promiseImageCommentType: PromiseImageCommentType) { when (promiseUserType) { PromiseUserType.READY -> throw UploadBeforeTrackingException.EXCEPTION PromiseUserType.CANCEL -> throw CancelledUserUploadException.EXCEPTION PromiseUserType.WAIT, PromiseUserType.LATE -> { - if (imageCommentType.promiseUserType != promiseUserType) { + if (promiseImageCommentType.promiseUserType != promiseUserType) { throw InvalidCommentTypeException.EXCEPTION } } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/user/domain/User.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/user/domain/User.kt index aa2db305..6a1e76fd 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/user/domain/User.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/domains/user/domain/User.kt @@ -99,13 +99,6 @@ class User( nickname = username } - fun updateProfileImg(imageUrl: String) { - if (profileImg != imageUrl) { - isDefaultImg = false - } - profileImg = imageUrl - } - fun toUserInfoVo(): UserInfoVo { return UserInfoVo.from(this) } diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/ImageRegisterEvent.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/PromiseImageRegisterEvent.kt similarity index 84% rename from Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/ImageRegisterEvent.kt rename to Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/PromiseImageRegisterEvent.kt index f46f4f08..4a36457e 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/ImageRegisterEvent.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/domainEvent/PromiseImageRegisterEvent.kt @@ -2,7 +2,7 @@ package com.depromeet.whatnow.events.domainEvent import com.depromeet.whatnow.common.aop.event.DomainEvent -class ImageRegisterEvent( +class PromiseImageRegisterEvent( val userId: Long, val promiseId: Long, ) : DomainEvent() diff --git a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/ImageRegisterEventHandler.kt b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/ImageRegisterEventHandler.kt index 5d57b349..a47bc846 100644 --- a/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/ImageRegisterEventHandler.kt +++ b/Whatnow-Domain/src/main/kotlin/com/depromeet/whatnow/events/handler/ImageRegisterEventHandler.kt @@ -1,7 +1,7 @@ package com.depromeet.whatnow.events.handler import com.depromeet.whatnow.annotation.Handler -import com.depromeet.whatnow.events.domainEvent.ImageRegisterEvent +import com.depromeet.whatnow.events.domainEvent.PromiseImageRegisterEvent import org.springframework.scheduling.annotation.Async import org.springframework.transaction.event.TransactionPhase import org.springframework.transaction.event.TransactionalEventListener @@ -9,10 +9,10 @@ import org.springframework.transaction.event.TransactionalEventListener @Handler class ImageRegisterEventHandler { @Async - @TransactionalEventListener(classes = [ImageRegisterEvent::class], phase = TransactionPhase.AFTER_COMMIT) - fun handleRegisterPictureEvent(imageRegisterEvent: ImageRegisterEvent) { - val userId: Long = imageRegisterEvent.userId - val promiseId: Long = imageRegisterEvent.promiseId + @TransactionalEventListener(classes = [PromiseImageRegisterEvent::class], phase = TransactionPhase.AFTER_COMMIT) + fun handleRegisterPictureEvent(promiseImageRegisterEvent: PromiseImageRegisterEvent) { + val userId: Long = promiseImageRegisterEvent.userId + val promiseId: Long = promiseImageRegisterEvent.promiseId // TODO: FCM 토큰 발급 후 약속ID 기준 참여자들에게 푸시 알림 보내기 } } diff --git a/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/domains/image/adapter/ImageAdapterTest.kt b/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/domains/image/adapter/ImageAdapterTest.kt deleted file mode 100644 index 4f538f5c..00000000 --- a/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/domains/image/adapter/ImageAdapterTest.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.depromeet.whatnow.domains.image.adapter - -import com.depromeet.whatnow.domains.image.domain.Image -import com.depromeet.whatnow.domains.image.domain.ImageCommentType -import com.depromeet.whatnow.domains.image.domain.ImageType -import com.depromeet.whatnow.domains.image.repository.ImageRepository -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.ExtendWith -import org.mockito.InjectMocks -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.junit.jupiter.MockitoExtension -import org.mockito.kotlin.given -import kotlin.test.assertEquals - -@ExtendWith(MockitoExtension::class) -class ImageAdapterTest { - @Mock - lateinit var imageRepository: ImageRepository - - @InjectMocks - lateinit var imageAdapter: ImageAdapter - - @Test - fun `약속 이미지 Picture 저장 시 정상적으로 저장된다`() { - given(imageRepository.save(Mockito.any(Image::class.java))) - .willReturn(Image.createForPromise(1, 1, "imageUri", "imageKey", ImageCommentType.RUNNING)) - - // when - val picture = imageAdapter.saveForPromise(1, 1, "imageUri", "imageKey", ImageCommentType.RUNNING) - - // then - assertEquals(picture.userId, 1) - assertEquals(picture.promiseId, 1) - assertEquals(picture.uri, "imageUri") - assertEquals(picture.imageKey, "imageKey") - assertEquals(picture.imageType, ImageType.PROMISE) - assertEquals(picture.imageCommentType, ImageCommentType.RUNNING) - } - - @Test - fun `유저 프로필 Picture 저장 시 정상적으로 저장된다`() { - given(imageRepository.save(Mockito.any(Image::class.java))) - .willReturn(Image.createForUser(1, "imageUri", "imageKey")) - - // when - val picture = imageAdapter.saveForUser(1, "imageUri", "imageKey") - - // then - assertEquals(picture.userId, 1) - assertEquals(picture.promiseId, 0) - assertEquals(picture.uri, "imageUri") - assertEquals(picture.imageKey, "imageKey") - assertEquals(picture.imageType, ImageType.USER) - assertEquals(picture.imageCommentType, ImageCommentType.NONE) - } -} diff --git a/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/domains/image/adapter/PromisePromiseImageAdapterTest.kt b/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/domains/image/adapter/PromisePromiseImageAdapterTest.kt new file mode 100644 index 00000000..19f08cd7 --- /dev/null +++ b/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/domains/image/adapter/PromisePromiseImageAdapterTest.kt @@ -0,0 +1,42 @@ +package com.depromeet.whatnow.domains.image.adapter + +import com.depromeet.whatnow.common.vo.CoordinateVo +import com.depromeet.whatnow.domains.image.domain.PromiseImage +import com.depromeet.whatnow.domains.image.domain.PromiseImageCommentType +import com.depromeet.whatnow.domains.image.repository.PromiseImageRepository +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.InjectMocks +import org.mockito.Mock +import org.mockito.Mockito +import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.given +import kotlin.test.assertEquals + +@ExtendWith(MockitoExtension::class) +class PromisePromiseImageAdapterTest { + @Mock + lateinit var promiseImageRepository: PromiseImageRepository + + @InjectMocks + lateinit var promiseImageAdapter: PromiseImageAdapter + + @Test + fun `약속 이미지 저장 시 정상적으로 저장된다`() { + val userLocation = CoordinateVo(37.2, 128.05) + val promiseImage = PromiseImage.of(1, 1, "imageUri", "imageKey", PromiseImageCommentType.RUNNING, userLocation) + given(promiseImageRepository.save(Mockito.any(PromiseImage::class.java))) + .willReturn(promiseImage) + + // when + val savedPromiseImage = promiseImageAdapter.save(promiseImage) + + // then + assertEquals(savedPromiseImage.userId, 1) + assertEquals(savedPromiseImage.promiseId, 1) + assertEquals(savedPromiseImage.uri, "imageUri") + assertEquals(savedPromiseImage.imageKey, "imageKey") + assertEquals(savedPromiseImage.promiseImageCommentType, PromiseImageCommentType.RUNNING) + assertEquals(savedPromiseImage.userLocation, userLocation) + } +} diff --git a/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/domains/image/service/ImageDomainServiceTest.kt b/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/domains/image/service/PromiseImageDomainServiceTest.kt similarity index 77% rename from Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/domains/image/service/ImageDomainServiceTest.kt rename to Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/domains/image/service/PromiseImageDomainServiceTest.kt index db2b8714..faa2de8c 100644 --- a/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/domains/image/service/ImageDomainServiceTest.kt +++ b/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/domains/image/service/PromiseImageDomainServiceTest.kt @@ -1,8 +1,9 @@ package com.depromeet.whatnow.domains.image.service import com.depromeet.whatnow.common.vo.CoordinateVo -import com.depromeet.whatnow.domains.image.adapter.ImageAdapter -import com.depromeet.whatnow.domains.image.domain.ImageCommentType +import com.depromeet.whatnow.domains.image.adapter.PromiseImageAdapter +import com.depromeet.whatnow.domains.image.adapter.UserImageAdapter +import com.depromeet.whatnow.domains.image.domain.PromiseImageCommentType import com.depromeet.whatnow.domains.image.exception.CancelledUserUploadException import com.depromeet.whatnow.domains.image.exception.InvalidCommentTypeException import com.depromeet.whatnow.domains.image.exception.UploadBeforeTrackingException @@ -11,7 +12,6 @@ import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUser import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType import com.depromeet.whatnow.domains.user.adapter.UserAdapter import com.depromeet.whatnow.helper.SpringEnvironmentHelper -import com.depromeet.whatnow.helper.user_id_1_fixture import org.assertj.core.api.Assertions import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -22,13 +22,16 @@ import org.mockito.junit.jupiter.MockitoExtension import org.mockito.kotlin.given @ExtendWith(MockitoExtension::class) -class ImageDomainServiceTest { +class PromiseImageDomainServiceTest { @Mock - lateinit var imageAdapter: ImageAdapter + lateinit var promiseImageAdapter: PromiseImageAdapter @Mock lateinit var promiseUserAdapter: PromiseUserAdaptor + @Mock + lateinit var userImageAdapter: UserImageAdapter + @Mock lateinit var userAdapter: UserAdapter @@ -47,12 +50,13 @@ class ImageDomainServiceTest { userLocation = CoordinateVo(1.0, 1.0), promiseUserType = PromiseUserType.LATE, ) + val userLocation = CoordinateVo(37.2, 128.05) given(promiseUserAdapter.findByPromiseIdAndUserId(anyLong(), anyLong())) .willReturn(promiseUser) // when, then Assertions.assertThatCode { - imageDomainService.promiseUploadImageSuccess(1, 1, "imageKey", ImageCommentType.RUNNING) + imageDomainService.promiseImageUploadSuccess(1, 1, "imageKey", PromiseImageCommentType.RUNNING, userLocation) }.doesNotThrowAnyException() } @@ -65,12 +69,13 @@ class ImageDomainServiceTest { userLocation = CoordinateVo(1.0, 1.0), promiseUserType = PromiseUserType.READY, ) + val userLocation = CoordinateVo(37.2, 128.05) given(promiseUserAdapter.findByPromiseIdAndUserId(anyLong(), anyLong())) .willReturn(promiseUser) // when, then Assertions.assertThatThrownBy { - imageDomainService.promiseUploadImageSuccess(1, 1, "imageKey", ImageCommentType.RUNNING) + imageDomainService.promiseImageUploadSuccess(1, 1, "imageKey", PromiseImageCommentType.RUNNING, userLocation) }.isInstanceOf(UploadBeforeTrackingException::class.java) } @@ -83,12 +88,13 @@ class ImageDomainServiceTest { userLocation = CoordinateVo(1.0, 1.0), promiseUserType = PromiseUserType.CANCEL, ) + val userLocation = CoordinateVo(37.2, 128.05) given(promiseUserAdapter.findByPromiseIdAndUserId(anyLong(), anyLong())) .willReturn(promiseUser) // when, then Assertions.assertThatThrownBy { - imageDomainService.promiseUploadImageSuccess(1, 1, "imageKey", ImageCommentType.RUNNING) + imageDomainService.promiseImageUploadSuccess(1, 1, "imageKey", PromiseImageCommentType.RUNNING, userLocation) }.isInstanceOf(CancelledUserUploadException::class.java) } @@ -101,12 +107,13 @@ class ImageDomainServiceTest { userLocation = CoordinateVo(1.0, 1.0), promiseUserType = PromiseUserType.LATE, ) + val userLocation = CoordinateVo(37.2, 128.05) given(promiseUserAdapter.findByPromiseIdAndUserId(anyLong(), anyLong())) .willReturn(promiseUser) // when, then Assertions.assertThatThrownBy { - imageDomainService.promiseUploadImageSuccess(1, 1, "imageKey", ImageCommentType.DID_YOU_COME) + imageDomainService.promiseImageUploadSuccess(1, 1, "imageKey", PromiseImageCommentType.DID_YOU_COME, userLocation) }.isInstanceOf(InvalidCommentTypeException::class.java) } @@ -119,24 +126,13 @@ class ImageDomainServiceTest { userLocation = CoordinateVo(1.0, 1.0), promiseUserType = PromiseUserType.WAIT, ) + val userLocation = CoordinateVo(37.2, 128.05) given(promiseUserAdapter.findByPromiseIdAndUserId(anyLong(), anyLong())) .willReturn(promiseUser) // when, then Assertions.assertThatThrownBy { - imageDomainService.promiseUploadImageSuccess(1, 1, "imageKey", ImageCommentType.WAIT_A_BIT) + imageDomainService.promiseImageUploadSuccess(1, 1, "imageKey", PromiseImageCommentType.WAIT_A_BIT, userLocation) }.isInstanceOf(InvalidCommentTypeException::class.java) } - - @Test - fun `유저 프로필 업로드 성공 요청시 정상적이라면 에러를 반환하지 않는다`() { - // given - given(userAdapter.queryUser(anyLong())) - .willReturn(user_id_1_fixture()) - - // when, then - Assertions.assertThatCode { - imageDomainService.userUploadImageSuccess(1, "imageKey") - }.doesNotThrowAnyException() - } } diff --git a/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/handler/ImageRegisterEventHandlerTest.kt b/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/handler/PromisePromiseImageRegisterEventHandlerTest.kt similarity index 63% rename from Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/handler/ImageRegisterEventHandlerTest.kt rename to Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/handler/PromisePromiseImageRegisterEventHandlerTest.kt index f554ce2e..fc0d81c2 100644 --- a/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/handler/ImageRegisterEventHandlerTest.kt +++ b/Whatnow-Domain/src/test/kotlin/com/depromeet/whatnow/events/handler/PromisePromiseImageRegisterEventHandlerTest.kt @@ -2,13 +2,12 @@ package com.depromeet.whatnow.events.handler import com.depromeet.whatnow.common.vo.CoordinateVo import com.depromeet.whatnow.config.DomainIntegrateSpringBootTest -import com.depromeet.whatnow.domains.image.domain.ImageCommentType +import com.depromeet.whatnow.domains.image.domain.PromiseImageCommentType import com.depromeet.whatnow.domains.image.service.ImageDomainService import com.depromeet.whatnow.domains.promiseuser.adaptor.PromiseUserAdaptor import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUser import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType import com.depromeet.whatnow.domains.user.adapter.UserAdapter -import com.depromeet.whatnow.helper.user_id_1_fixture import org.junit.jupiter.api.Test import org.mockito.Mockito import org.mockito.kotlin.any @@ -18,7 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.mock.mockito.MockBean @DomainIntegrateSpringBootTest -class ImageRegisterEventHandlerTest { +class PromisePromiseImageRegisterEventHandlerTest { @Autowired lateinit var imageDomainService: ImageDomainService @@ -32,28 +31,16 @@ class ImageRegisterEventHandlerTest { lateinit var imageRegisterEventHandler: ImageRegisterEventHandler @Test - fun `이미지 등록 성공 시 이미지 타입이 Promise라면 이미지 등록 이벤트가 발행되어야한다`() { + fun `약속 이미지 등록 성공 시 이미지 등록 이벤트가 발행되어야한다`() { // given val promiseUser = PromiseUser(1, 1, CoordinateVo(1.0, 1.0), PromiseUserType.LATE) + val userLocation = CoordinateVo(37.2, 128.05) given(promiseUserAdaptor.findByPromiseIdAndUserId(1, 1)).willReturn(promiseUser) // when - imageDomainService.promiseUploadImageSuccess(1, 1, "imageKey", ImageCommentType.RUNNING) + imageDomainService.promiseImageUploadSuccess(1, 1, "imageKey", PromiseImageCommentType.RUNNING, userLocation) // then then(imageRegisterEventHandler).should(Mockito.times(1)).handleRegisterPictureEvent(any()) } - - @Test - fun `이미지 등록 성공 시 이미지 타입이 User라면 이미지 등록 이벤트가 발행되지 않아야한다`() { - // given - val user = user_id_1_fixture() - given(userAdapter.queryUser(any())).willReturn(user) - - // when - imageDomainService.userUploadImageSuccess(1, "imageKey") - - // then - then(imageRegisterEventHandler).should(Mockito.times(0)).handleRegisterPictureEvent(any()) - } }