From 465c863942cf2c9558ed0b9723e27d439deb9a38 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 29 Jun 2024 16:25:39 +0900 Subject: [PATCH 01/14] feat: remove THUMBNAIL_LINK_SEPARATOR --- .../src/main/kotlin/com/piikii/application/consts/Consts.kt | 3 --- .../com/piikii/application/domain/generic/ThumbnailLinks.kt | 6 +++++- 2 files changed, 5 insertions(+), 4 deletions(-) delete mode 100644 piikii-application/src/main/kotlin/com/piikii/application/consts/Consts.kt diff --git a/piikii-application/src/main/kotlin/com/piikii/application/consts/Consts.kt b/piikii-application/src/main/kotlin/com/piikii/application/consts/Consts.kt deleted file mode 100644 index 5d0cc5c0..00000000 --- a/piikii-application/src/main/kotlin/com/piikii/application/consts/Consts.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.piikii.application.consts - -const val THUMBNAIL_LINK_SEPARATOR = "," diff --git a/piikii-application/src/main/kotlin/com/piikii/application/domain/generic/ThumbnailLinks.kt b/piikii-application/src/main/kotlin/com/piikii/application/domain/generic/ThumbnailLinks.kt index bc5b827c..ce240294 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/domain/generic/ThumbnailLinks.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/domain/generic/ThumbnailLinks.kt @@ -2,7 +2,6 @@ package com.piikii.application.domain.generic import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonProperty -import com.piikii.application.consts.THUMBNAIL_LINK_SEPARATOR import java.io.Serializable class ThumbnailLinks( @@ -14,4 +13,9 @@ class ThumbnailLinks( @get:JsonProperty("contents") val convertToList: List get() = contents?.split(THUMBNAIL_LINK_SEPARATOR) ?: emptyList() + + companion object { + const val THUMBNAIL_LINK_SEPARATOR = "," + } + } From d6c2fb50aec7670194f30a3b43ae51094ebcc820 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 29 Jun 2024 16:51:17 +0900 Subject: [PATCH 02/14] refactor: rename RoomVote to Vote --- .../application/domain/roomvote/RoomVote.kt | 9 ---- .../piikii/application/domain/vote/Vote.kt | 9 ++++ .../VoteService.kt} | 4 +- .../persistence/entity/RoomVoteEntity.kt | 39 ---------------- .../persistence/entity/VoteEntity.kt | 44 +++++++++++++++++++ ...teRepository.kt => PlaceVoteRepository.kt} | 4 +- 6 files changed, 57 insertions(+), 52 deletions(-) delete mode 100644 piikii-application/src/main/kotlin/com/piikii/application/domain/roomvote/RoomVote.kt create mode 100644 piikii-application/src/main/kotlin/com/piikii/application/domain/vote/Vote.kt rename piikii-application/src/main/kotlin/com/piikii/application/domain/{roomvote/RoomVoteService.kt => vote/VoteService.kt} (91%) delete mode 100644 piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/RoomVoteEntity.kt create mode 100644 piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/VoteEntity.kt rename piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/repository/{RoomVoteRepository.kt => PlaceVoteRepository.kt} (70%) diff --git a/piikii-application/src/main/kotlin/com/piikii/application/domain/roomvote/RoomVote.kt b/piikii-application/src/main/kotlin/com/piikii/application/domain/roomvote/RoomVote.kt deleted file mode 100644 index 16ce94d0..00000000 --- a/piikii-application/src/main/kotlin/com/piikii/application/domain/roomvote/RoomVote.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.piikii.application.domain.roomvote - -import java.util.UUID - -class RoomVote( - val userId: UUID, - val roomPlaceId: Long, - val content: String, -) diff --git a/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/Vote.kt b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/Vote.kt new file mode 100644 index 00000000..02d33f23 --- /dev/null +++ b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/Vote.kt @@ -0,0 +1,9 @@ +package com.piikii.application.domain.vote + +import java.util.UUID + +class Vote( + val userId: UUID, + val roomPlaceId: Long, + val result: VoteResult, +) diff --git a/piikii-application/src/main/kotlin/com/piikii/application/domain/roomvote/RoomVoteService.kt b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt similarity index 91% rename from piikii-application/src/main/kotlin/com/piikii/application/domain/roomvote/RoomVoteService.kt rename to piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt index 585dcce2..2d7c1b1b 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/domain/roomvote/RoomVoteService.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt @@ -1,4 +1,4 @@ -package com.piikii.application.domain.roomvote +package com.piikii.application.domain.vote import com.piikii.application.port.output.persistence.RoomQueryPort import com.piikii.common.exception.ExceptionCode @@ -7,7 +7,7 @@ import org.springframework.stereotype.Service import java.util.UUID @Service -class RoomVoteService( +class VoteService( private val roomQueryPort: RoomQueryPort, ) { fun vote(roomId: UUID) { diff --git a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/RoomVoteEntity.kt b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/RoomVoteEntity.kt deleted file mode 100644 index ced223fe..00000000 --- a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/RoomVoteEntity.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.piikii.output.persistence.postgresql.persistence.entity - -import com.piikii.application.domain.roomvote.RoomVote -import com.piikii.output.persistence.postgresql.persistence.common.BaseEntity -import jakarta.persistence.Column -import jakarta.persistence.Entity -import jakarta.persistence.Table -import org.hibernate.annotations.DynamicUpdate -import org.hibernate.annotations.SQLRestriction -import java.util.UUID - -@Entity -@Table(name = "room_vote", schema = "piikii") -@SQLRestriction("is_deleted = false") -@DynamicUpdate -class RoomVoteEntity( - @Column(name = "user_id", nullable = false) - val userId: UUID, - @Column(name = "room_place_id", nullable = false) - val roomPlaceId: Long, - @Column(name = "content", nullable = false, length = 10) - val content: String, -) : BaseEntity() - -fun RoomVoteEntity.toDomain(): RoomVote { - return RoomVote( - userId = this.userId, - roomPlaceId = this.roomPlaceId, - content = this.content, - ) -} - -fun RoomVote.toEntity(): RoomVoteEntity { - return RoomVoteEntity( - userId = this.userId, - roomPlaceId = this.roomPlaceId, - content = this.content, - ) -} diff --git a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/VoteEntity.kt b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/VoteEntity.kt new file mode 100644 index 00000000..2c83f342 --- /dev/null +++ b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/VoteEntity.kt @@ -0,0 +1,44 @@ +package com.piikii.output.persistence.postgresql.persistence.entity + +import com.piikii.application.domain.vote.Vote +import com.piikii.application.domain.vote.VoteResult +import com.piikii.output.persistence.postgresql.persistence.common.BaseEntity +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.Table +import org.hibernate.annotations.DynamicUpdate +import org.hibernate.annotations.SQLRestriction +import java.util.UUID + +@Entity +@Table(name = "vote", schema = "piikii") +@SQLRestriction("is_deleted = false") +@DynamicUpdate +class VoteEntity( + @Column(name = "user_id", nullable = false) + val userId: UUID, + @Column(name = "room_place_id", nullable = false) + val roomPlaceId: Long, + @Column(name = "result", nullable = false, length = 10) + val result: VoteResult, +) : BaseEntity() { + + fun toDomain(): Vote { + return Vote( + userId = this.userId, + roomPlaceId = this.roomPlaceId, + result = this.result, + ) + } + + companion object { + fun from(vote: Vote): VoteEntity { + return VoteEntity( + userId = vote.userId, + roomPlaceId = vote.roomPlaceId, + result = vote.result, + ) + } + } + +} diff --git a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/repository/RoomVoteRepository.kt b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/repository/PlaceVoteRepository.kt similarity index 70% rename from piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/repository/RoomVoteRepository.kt rename to piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/repository/PlaceVoteRepository.kt index f500237e..e2952307 100644 --- a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/repository/RoomVoteRepository.kt +++ b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/repository/PlaceVoteRepository.kt @@ -1,6 +1,6 @@ package com.piikii.output.persistence.postgresql.persistence.repository -import com.piikii.output.persistence.postgresql.persistence.entity.RoomVoteEntity +import com.piikii.output.persistence.postgresql.persistence.entity.VoteEntity import org.springframework.data.jpa.repository.JpaRepository -interface RoomVoteRepository : JpaRepository +interface PlaceVoteRepository : JpaRepository From 333b6f0bcf9cd522e10a1d0ba82fff379682e8c4 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 29 Jun 2024 16:57:20 +0900 Subject: [PATCH 03/14] refactor: input http repackage --- .../kotlin/com/piikii/input/http/advice/ExceptionAdvice.kt | 2 +- .../main/kotlin/com/piikii/input/http/config/WebMvcConfig.kt | 2 +- .../main/kotlin/com/piikii/input/http/controller/RoomApi.kt | 4 ++-- .../com/piikii/input/http/{ => controller}/TestController.kt | 4 ++-- .../src/main/kotlin/com/piikii/input/http/docs/RoomApiDocs.kt | 2 +- .../com/piikii/input/http/{generic => dto}/ResponseForm.kt | 2 +- .../com/piikii/input/http/{message => dto}/RoomMessage.kt | 2 +- .../http/{exception => dto/response}/ExceptionResponse.kt | 2 +- .../input/http/{ => web}/filter/ServletWrappingFilter.kt | 2 +- .../input/http/{ => web}/interceptor/LoggingInterceptor.kt | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) rename piikii-input-http/src/main/kotlin/com/piikii/input/http/{ => controller}/TestController.kt (94%) rename piikii-input-http/src/main/kotlin/com/piikii/input/http/{generic => dto}/ResponseForm.kt (78%) rename piikii-input-http/src/main/kotlin/com/piikii/input/http/{message => dto}/RoomMessage.kt (89%) rename piikii-input-http/src/main/kotlin/com/piikii/input/http/{exception => dto/response}/ExceptionResponse.kt (82%) rename piikii-input-http/src/main/kotlin/com/piikii/input/http/{ => web}/filter/ServletWrappingFilter.kt (95%) rename piikii-input-http/src/main/kotlin/com/piikii/input/http/{ => web}/interceptor/LoggingInterceptor.kt (98%) diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/advice/ExceptionAdvice.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/advice/ExceptionAdvice.kt index 9407c790..d46474a3 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/advice/ExceptionAdvice.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/advice/ExceptionAdvice.kt @@ -2,7 +2,7 @@ package com.piikii.input.http.advice import com.piikii.common.exception.PiikiiException import com.piikii.common.logutil.SystemLogger.logger -import com.piikii.input.http.exception.ExceptionResponse +import com.piikii.input.http.dto.response.ExceptionResponse import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.ExceptionHandler diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/config/WebMvcConfig.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/config/WebMvcConfig.kt index b8f272bf..03e841ec 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/config/WebMvcConfig.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/config/WebMvcConfig.kt @@ -1,6 +1,6 @@ package com.piikii.input.http.config -import com.piikii.input.http.interceptor.LoggingInterceptor +import com.piikii.input.http.web.interceptor.LoggingInterceptor import org.springframework.context.annotation.Configuration import org.springframework.web.servlet.config.annotation.InterceptorRegistry import org.springframework.web.servlet.config.annotation.WebMvcConfigurer diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/RoomApi.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/RoomApi.kt index 31836cd8..84c49207 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/RoomApi.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/RoomApi.kt @@ -7,8 +7,8 @@ import com.piikii.application.port.input.room.dto.request.VoteDeadlineSetRequest import com.piikii.application.port.input.room.dto.response.RoomGetResponseForm import com.piikii.application.port.input.room.dto.response.RoomSaveResponseForm import com.piikii.input.http.docs.RoomApiDocs -import com.piikii.input.http.generic.ResponseForm -import com.piikii.input.http.message.RoomMessage +import com.piikii.input.http.dto.ResponseForm +import com.piikii.input.http.dto.RoomMessage import org.springframework.http.HttpStatus import org.springframework.web.bind.annotation.DeleteMapping import org.springframework.web.bind.annotation.GetMapping diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/TestController.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/TestController.kt similarity index 94% rename from piikii-input-http/src/main/kotlin/com/piikii/input/http/TestController.kt rename to piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/TestController.kt index 5a4f800e..1e069c95 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/TestController.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/TestController.kt @@ -1,8 +1,8 @@ -package com.piikii.input.http +package com.piikii.input.http.controller import com.piikii.common.exception.ExceptionCode import com.piikii.common.exception.PiikiiException -import com.piikii.input.http.generic.ResponseForm +import com.piikii.input.http.dto.ResponseForm import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RestController diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/RoomApiDocs.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/RoomApiDocs.kt index 625c129f..9a5aec1b 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/RoomApiDocs.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/RoomApiDocs.kt @@ -5,7 +5,7 @@ import com.piikii.application.port.input.room.dto.request.RoomUpdateRequestForm import com.piikii.application.port.input.room.dto.request.VoteDeadlineSetRequest import com.piikii.application.port.input.room.dto.response.RoomGetResponseForm import com.piikii.application.port.input.room.dto.response.RoomSaveResponseForm -import com.piikii.input.http.generic.ResponseForm +import com.piikii.input.http.dto.ResponseForm import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.Parameter import io.swagger.v3.oas.annotations.responses.ApiResponse diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/generic/ResponseForm.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/ResponseForm.kt similarity index 78% rename from piikii-input-http/src/main/kotlin/com/piikii/input/http/generic/ResponseForm.kt rename to piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/ResponseForm.kt index 4176fed2..700f7dd4 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/generic/ResponseForm.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/ResponseForm.kt @@ -1,4 +1,4 @@ -package com.piikii.input.http.generic +package com.piikii.input.http.dto class ResponseForm( val data: T? = null, diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/message/RoomMessage.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/RoomMessage.kt similarity index 89% rename from piikii-input-http/src/main/kotlin/com/piikii/input/http/message/RoomMessage.kt rename to piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/RoomMessage.kt index ac66eb09..2855a96a 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/message/RoomMessage.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/RoomMessage.kt @@ -1,4 +1,4 @@ -package com.piikii.input.http.message +package com.piikii.input.http.dto object RoomMessage { const val SUCCESS_CREATE_ROOM = "방 생성 성공" diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/exception/ExceptionResponse.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/response/ExceptionResponse.kt similarity index 82% rename from piikii-input-http/src/main/kotlin/com/piikii/input/http/exception/ExceptionResponse.kt rename to piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/response/ExceptionResponse.kt index aaa70305..ccd65941 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/exception/ExceptionResponse.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/response/ExceptionResponse.kt @@ -1,4 +1,4 @@ -package com.piikii.input.http.exception +package com.piikii.input.http.dto.response import com.fasterxml.jackson.annotation.JsonInclude diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/filter/ServletWrappingFilter.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/web/filter/ServletWrappingFilter.kt similarity index 95% rename from piikii-input-http/src/main/kotlin/com/piikii/input/http/filter/ServletWrappingFilter.kt rename to piikii-input-http/src/main/kotlin/com/piikii/input/http/web/filter/ServletWrappingFilter.kt index 33b309c1..cc5edf36 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/filter/ServletWrappingFilter.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/web/filter/ServletWrappingFilter.kt @@ -1,4 +1,4 @@ -package com.piikii.input.http.filter +package com.piikii.input.http.web.filter import jakarta.servlet.FilterChain import jakarta.servlet.http.HttpServletRequest diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/interceptor/LoggingInterceptor.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/web/interceptor/LoggingInterceptor.kt similarity index 98% rename from piikii-input-http/src/main/kotlin/com/piikii/input/http/interceptor/LoggingInterceptor.kt rename to piikii-input-http/src/main/kotlin/com/piikii/input/http/web/interceptor/LoggingInterceptor.kt index 94eb5006..2326c75e 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/interceptor/LoggingInterceptor.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/web/interceptor/LoggingInterceptor.kt @@ -1,4 +1,4 @@ -package com.piikii.input.http.interceptor +package com.piikii.input.http.web.interceptor import com.fasterxml.jackson.databind.ObjectMapper import com.piikii.common.logutil.SlackHookLogger From 62098a21e14176e258bcab90499385fc4c2e9e3a Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 29 Jun 2024 20:23:04 +0900 Subject: [PATCH 04/14] feat: added SQLRestriction for soft delete select query --- .../persistence/postgresql/persistence/common/BaseEntity.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/common/BaseEntity.kt b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/common/BaseEntity.kt index 75b475b1..23b7b73a 100644 --- a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/common/BaseEntity.kt +++ b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/common/BaseEntity.kt @@ -6,12 +6,14 @@ import jakarta.persistence.GeneratedValue import jakarta.persistence.GenerationType import jakarta.persistence.Id import jakarta.persistence.MappedSuperclass +import org.hibernate.annotations.SQLRestriction import org.springframework.data.annotation.CreatedDate import org.springframework.data.annotation.LastModifiedDate import org.springframework.data.jpa.domain.support.AuditingEntityListener import java.time.LocalDateTime @EntityListeners(AuditingEntityListener::class) +@SQLRestriction("is_deleted = false") @MappedSuperclass abstract class BaseEntity { @Id From b8d1aa32b8321cae62c9e78e914dacff50c096b6 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 29 Jun 2024 20:23:17 +0900 Subject: [PATCH 05/14] feat: added EMPTY Response --- .../main/kotlin/com/piikii/input/http/dto/ResponseForm.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/ResponseForm.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/ResponseForm.kt index 700f7dd4..a6270839 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/ResponseForm.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/ResponseForm.kt @@ -4,4 +4,10 @@ class ResponseForm( val data: T? = null, val message: String? = null, val timestamp: Long = System.currentTimeMillis(), -) +) { + + companion object { + val EMPTY_RESPONSE = ResponseForm() + } + +} From bfe1a042e0c53dbaa25c83ce8a8b291089f7d4e0 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 29 Jun 2024 20:23:43 +0900 Subject: [PATCH 06/14] refactor: inline findByRoomId --- .../output/persistence/postgresql/adapter/room/RoomAdapter.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/room/RoomAdapter.kt b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/room/RoomAdapter.kt index 9694595a..2e390b6f 100644 --- a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/room/RoomAdapter.kt +++ b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/room/RoomAdapter.kt @@ -35,8 +35,7 @@ class RoomAdapter( } override fun retrieve(roomId: UUID): Room { - val foundRoom = findByRoomId(roomId) - return foundRoom.toDomain() + return findByRoomId(roomId).toDomain() } private fun findByRoomId(roomId: UUID): RoomEntity { From 72a88557e1e10f25b967b10f0092178564bd59a5 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 29 Jun 2024 20:32:35 +0900 Subject: [PATCH 07/14] feat: added Enumerated to VoteResult --- .../persistence/postgresql/persistence/entity/VoteEntity.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/VoteEntity.kt b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/VoteEntity.kt index 2c83f342..178865b5 100644 --- a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/VoteEntity.kt +++ b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/VoteEntity.kt @@ -5,6 +5,8 @@ import com.piikii.application.domain.vote.VoteResult import com.piikii.output.persistence.postgresql.persistence.common.BaseEntity import jakarta.persistence.Column import jakarta.persistence.Entity +import jakarta.persistence.EnumType +import jakarta.persistence.Enumerated import jakarta.persistence.Table import org.hibernate.annotations.DynamicUpdate import org.hibernate.annotations.SQLRestriction @@ -19,6 +21,7 @@ class VoteEntity( val userId: UUID, @Column(name = "room_place_id", nullable = false) val roomPlaceId: Long, + @Enumerated(EnumType.STRING) @Column(name = "result", nullable = false, length = 10) val result: VoteResult, ) : BaseEntity() { From 96a316036acc41f29f9f646634ba8379546984e4 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 29 Jun 2024 20:34:14 +0900 Subject: [PATCH 08/14] feat: added vote --- .../application/domain/vote/VoteResult.kt | 6 +++++ .../application/domain/vote/VoteService.kt | 18 ++++++------- .../port/input/vote/VoteUseCase.kt | 10 ++++++++ .../port/output/persistence/VotePort.kt | 13 ++++++++++ .../piikii/input/http/controller/VoteApi.kt | 25 +++++++++++++++++++ .../com/piikii/input/http/docs/VoteApiDocs.kt | 18 +++++++++++++ .../input/http/dto/request/VoteRequest.kt | 20 +++++++++++++++ .../postgresql/adapter/vote/VoteAdapter.kt | 22 ++++++++++++++++ ...aceVoteRepository.kt => VoteRepository.kt} | 2 +- 9 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteResult.kt create mode 100644 piikii-application/src/main/kotlin/com/piikii/application/port/input/vote/VoteUseCase.kt create mode 100644 piikii-application/src/main/kotlin/com/piikii/application/port/output/persistence/VotePort.kt create mode 100644 piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.kt create mode 100644 piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt create mode 100644 piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/request/VoteRequest.kt create mode 100644 piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/vote/VoteAdapter.kt rename piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/repository/{PlaceVoteRepository.kt => VoteRepository.kt} (76%) diff --git a/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteResult.kt b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteResult.kt new file mode 100644 index 00000000..5cf76e09 --- /dev/null +++ b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteResult.kt @@ -0,0 +1,6 @@ +package com.piikii.application.domain.vote + +enum class VoteResult { + O, + X, +} diff --git a/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt index 2d7c1b1b..9aaa924d 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt @@ -1,6 +1,8 @@ package com.piikii.application.domain.vote +import com.piikii.application.port.input.vote.VoteUseCase import com.piikii.application.port.output.persistence.RoomQueryPort +import com.piikii.application.port.output.persistence.VoteCommandPort import com.piikii.common.exception.ExceptionCode import com.piikii.common.exception.PiikiiException import org.springframework.stereotype.Service @@ -8,22 +10,20 @@ import java.util.UUID @Service class VoteService( + private val voteCommandPort: VoteCommandPort, private val roomQueryPort: RoomQueryPort, -) { - fun vote(roomId: UUID) { - val room = roomQueryPort.retrieve(roomId) - - if (room.isUnavailableToVote()) { +) : VoteUseCase { + override fun vote(roomId: UUID, votes: List) { + if (roomQueryPort.retrieve(roomId).isUnavailableToVote()) { throw PiikiiException( exceptionCode = ExceptionCode.ACCESS_DENIED, - detailMessage = VOTE_IS_CLOSED, + detailMessage = VOTE_ACCESS_DENIED, ) } - - TODO("implementation additional flow") + voteCommandPort.vote(votes) } companion object { - const val VOTE_IS_CLOSED = "투표가 마감되었습니다." + const val VOTE_ACCESS_DENIED = "투표가 시작되지 않았거나, 마감되었습니다." } } diff --git a/piikii-application/src/main/kotlin/com/piikii/application/port/input/vote/VoteUseCase.kt b/piikii-application/src/main/kotlin/com/piikii/application/port/input/vote/VoteUseCase.kt new file mode 100644 index 00000000..05ada4c4 --- /dev/null +++ b/piikii-application/src/main/kotlin/com/piikii/application/port/input/vote/VoteUseCase.kt @@ -0,0 +1,10 @@ +package com.piikii.application.port.input.vote + +import com.piikii.application.domain.vote.Vote +import java.util.UUID + +interface VoteUseCase { + + fun vote(roomId: UUID, votes: List) + +} diff --git a/piikii-application/src/main/kotlin/com/piikii/application/port/output/persistence/VotePort.kt b/piikii-application/src/main/kotlin/com/piikii/application/port/output/persistence/VotePort.kt new file mode 100644 index 00000000..e37b5571 --- /dev/null +++ b/piikii-application/src/main/kotlin/com/piikii/application/port/output/persistence/VotePort.kt @@ -0,0 +1,13 @@ +package com.piikii.application.port.output.persistence + +import com.piikii.application.domain.vote.Vote + +interface VoteQueryPort { + +} + +interface VoteCommandPort { + + fun vote(votes: List) + +} diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.kt new file mode 100644 index 00000000..055037d1 --- /dev/null +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.kt @@ -0,0 +1,25 @@ +package com.piikii.input.http.controller + +import com.piikii.application.port.input.vote.VoteUseCase +import com.piikii.input.http.docs.VoteApiDocs +import com.piikii.input.http.dto.ResponseForm +import com.piikii.input.http.dto.request.VoteRequest +import org.springframework.http.HttpStatus +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.ResponseStatus +import org.springframework.web.bind.annotation.RestController + +@RestController +@RequestMapping("/room/votes") +class VoteApi(private val voteUseCase: VoteUseCase) : VoteApiDocs { + + @ResponseStatus(HttpStatus.CREATED) + @PostMapping + override fun vote(@RequestBody voteRequest: VoteRequest): ResponseForm { + voteUseCase.vote(voteRequest.roomId, voteRequest.toDomain()) + return ResponseForm.EMPTY_RESPONSE + } + +} diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt new file mode 100644 index 00000000..1abbdb54 --- /dev/null +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt @@ -0,0 +1,18 @@ +package com.piikii.input.http.docs + +import com.piikii.input.http.dto.ResponseForm +import com.piikii.input.http.dto.request.VoteRequest +import io.swagger.v3.oas.annotations.Operation +import io.swagger.v3.oas.annotations.responses.ApiResponse +import io.swagger.v3.oas.annotations.responses.ApiResponses +import io.swagger.v3.oas.annotations.tags.Tag +import org.springframework.web.bind.annotation.RequestBody + +@Tag(name = "VoteApi", description = "Vote (투표) API") +interface VoteApiDocs { + + @Operation(summary = "투표 API", description = "투표를 진행합니다") + @ApiResponses(value = [ApiResponse(responseCode = "201", description = "Vote succeed")]) + fun vote(@RequestBody voteRequest: VoteRequest): ResponseForm + +} diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/request/VoteRequest.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/request/VoteRequest.kt new file mode 100644 index 00000000..2668e73f --- /dev/null +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/request/VoteRequest.kt @@ -0,0 +1,20 @@ +package com.piikii.input.http.dto.request + +import com.piikii.application.domain.vote.Vote +import com.piikii.application.domain.vote.VoteResult +import java.util.UUID + +data class VoteRequest( + val userId: UUID, + val roomId: UUID, + val votes: List +) { + fun toDomain(): List { + return this.votes.map { Vote(userId = userId, roomPlaceId = it.roomPlaceId, result = it.voteResult) } + } +} + +data class PlaceVoteResult( + val roomPlaceId: Long, + val voteResult: VoteResult +) diff --git a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/vote/VoteAdapter.kt b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/vote/VoteAdapter.kt new file mode 100644 index 00000000..b35462ec --- /dev/null +++ b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/vote/VoteAdapter.kt @@ -0,0 +1,22 @@ +package com.piikii.output.persistence.postgresql.adapter.vote + +import com.piikii.application.domain.vote.Vote +import com.piikii.application.port.output.persistence.VoteCommandPort +import com.piikii.application.port.output.persistence.VoteQueryPort +import com.piikii.output.persistence.postgresql.persistence.entity.VoteEntity +import com.piikii.output.persistence.postgresql.persistence.repository.VoteRepository +import org.springframework.stereotype.Repository +import org.springframework.transaction.annotation.Transactional + +@Repository +@Transactional(readOnly = true) +class VoteAdapter( + private val voteRepository: VoteRepository, +) : VoteCommandPort, VoteQueryPort { + + @Transactional + override fun vote(votes: List) { + voteRepository.saveAll(votes.map(VoteEntity::from)) + } + +} diff --git a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/repository/PlaceVoteRepository.kt b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/repository/VoteRepository.kt similarity index 76% rename from piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/repository/PlaceVoteRepository.kt rename to piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/repository/VoteRepository.kt index e2952307..14d635ef 100644 --- a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/repository/PlaceVoteRepository.kt +++ b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/repository/VoteRepository.kt @@ -3,4 +3,4 @@ package com.piikii.output.persistence.postgresql.persistence.repository import com.piikii.output.persistence.postgresql.persistence.entity.VoteEntity import org.springframework.data.jpa.repository.JpaRepository -interface PlaceVoteRepository : JpaRepository +interface VoteRepository : JpaRepository From de09f74d5c312d869278cbc80dc020415a0c7bfb Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 29 Jun 2024 21:11:17 +0900 Subject: [PATCH 09/14] feat: added TODO commment --- .../kotlin/com/piikii/application/domain/vote/VoteService.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt index 9aaa924d..bcc82083 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt @@ -20,6 +20,7 @@ class VoteService( detailMessage = VOTE_ACCESS_DENIED, ) } + // TODO: votes.map { it.roomPlaceId } 존재여부 검증 필요 -> 도현이 작업 완료되면 붙일 예정 voteCommandPort.vote(votes) } From 730fd7cbd5923c4cee2bd9af0d126c7e0ac53f8c Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 29 Jun 2024 21:16:13 +0900 Subject: [PATCH 10/14] style: ktlint --- .../domain/generic/ThumbnailLinks.kt | 1 - .../application/domain/vote/VoteService.kt | 5 +- .../port/input/vote/VoteUseCase.kt | 7 +-- .../port/output/persistence/VotePort.kt | 6 +-- .../piikii/input/http/controller/RoomApi.kt | 1 - .../piikii/input/http/controller/VoteApi.kt | 6 +-- .../com/piikii/input/http/docs/VoteApiDocs.kt | 6 +-- .../com/piikii/input/http/dto/ResponseForm.kt | 2 - .../input/http/dto/request/VoteRequest.kt | 4 +- .../postgresql/adapter/vote/VoteAdapter.kt | 2 - .../persistence/entity/RoomPlaceEntity.kt | 48 ++++++++++--------- .../persistence/entity/VoteEntity.kt | 2 - 12 files changed, 42 insertions(+), 48 deletions(-) diff --git a/piikii-application/src/main/kotlin/com/piikii/application/domain/generic/ThumbnailLinks.kt b/piikii-application/src/main/kotlin/com/piikii/application/domain/generic/ThumbnailLinks.kt index ce240294..af3b66b1 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/domain/generic/ThumbnailLinks.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/domain/generic/ThumbnailLinks.kt @@ -17,5 +17,4 @@ class ThumbnailLinks( companion object { const val THUMBNAIL_LINK_SEPARATOR = "," } - } diff --git a/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt index bcc82083..8bb91aee 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/VoteService.kt @@ -13,7 +13,10 @@ class VoteService( private val voteCommandPort: VoteCommandPort, private val roomQueryPort: RoomQueryPort, ) : VoteUseCase { - override fun vote(roomId: UUID, votes: List) { + override fun vote( + roomId: UUID, + votes: List, + ) { if (roomQueryPort.retrieve(roomId).isUnavailableToVote()) { throw PiikiiException( exceptionCode = ExceptionCode.ACCESS_DENIED, diff --git a/piikii-application/src/main/kotlin/com/piikii/application/port/input/vote/VoteUseCase.kt b/piikii-application/src/main/kotlin/com/piikii/application/port/input/vote/VoteUseCase.kt index 05ada4c4..be26b6ca 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/port/input/vote/VoteUseCase.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/port/input/vote/VoteUseCase.kt @@ -4,7 +4,8 @@ import com.piikii.application.domain.vote.Vote import java.util.UUID interface VoteUseCase { - - fun vote(roomId: UUID, votes: List) - + fun vote( + roomId: UUID, + votes: List, + ) } diff --git a/piikii-application/src/main/kotlin/com/piikii/application/port/output/persistence/VotePort.kt b/piikii-application/src/main/kotlin/com/piikii/application/port/output/persistence/VotePort.kt index e37b5571..06fa1094 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/port/output/persistence/VotePort.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/port/output/persistence/VotePort.kt @@ -2,12 +2,8 @@ package com.piikii.application.port.output.persistence import com.piikii.application.domain.vote.Vote -interface VoteQueryPort { - -} +interface VoteQueryPort interface VoteCommandPort { - fun vote(votes: List) - } diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/RoomApi.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/RoomApi.kt index 84c49207..7153f0e7 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/RoomApi.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/RoomApi.kt @@ -27,7 +27,6 @@ import java.util.UUID class RoomApi( private val roomUseCase: RoomUseCase, ) : RoomApiDocs { - @ResponseStatus(HttpStatus.CREATED) @PostMapping override fun generate( diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.kt index 055037d1..bf40a043 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.kt @@ -14,12 +14,12 @@ import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("/room/votes") class VoteApi(private val voteUseCase: VoteUseCase) : VoteApiDocs { - @ResponseStatus(HttpStatus.CREATED) @PostMapping - override fun vote(@RequestBody voteRequest: VoteRequest): ResponseForm { + override fun vote( + @RequestBody voteRequest: VoteRequest, + ): ResponseForm { voteUseCase.vote(voteRequest.roomId, voteRequest.toDomain()) return ResponseForm.EMPTY_RESPONSE } - } diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt index 1abbdb54..b0799680 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt @@ -10,9 +10,9 @@ import org.springframework.web.bind.annotation.RequestBody @Tag(name = "VoteApi", description = "Vote (투표) API") interface VoteApiDocs { - @Operation(summary = "투표 API", description = "투표를 진행합니다") @ApiResponses(value = [ApiResponse(responseCode = "201", description = "Vote succeed")]) - fun vote(@RequestBody voteRequest: VoteRequest): ResponseForm - + fun vote( + @RequestBody voteRequest: VoteRequest, + ): ResponseForm } diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/ResponseForm.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/ResponseForm.kt index a6270839..11a235e0 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/ResponseForm.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/ResponseForm.kt @@ -5,9 +5,7 @@ class ResponseForm( val message: String? = null, val timestamp: Long = System.currentTimeMillis(), ) { - companion object { val EMPTY_RESPONSE = ResponseForm() } - } diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/request/VoteRequest.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/request/VoteRequest.kt index 2668e73f..c76a5923 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/request/VoteRequest.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/request/VoteRequest.kt @@ -7,7 +7,7 @@ import java.util.UUID data class VoteRequest( val userId: UUID, val roomId: UUID, - val votes: List + val votes: List, ) { fun toDomain(): List { return this.votes.map { Vote(userId = userId, roomPlaceId = it.roomPlaceId, result = it.voteResult) } @@ -16,5 +16,5 @@ data class VoteRequest( data class PlaceVoteResult( val roomPlaceId: Long, - val voteResult: VoteResult + val voteResult: VoteResult, ) diff --git a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/vote/VoteAdapter.kt b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/vote/VoteAdapter.kt index b35462ec..963f8b70 100644 --- a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/vote/VoteAdapter.kt +++ b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/adapter/vote/VoteAdapter.kt @@ -13,10 +13,8 @@ import org.springframework.transaction.annotation.Transactional class VoteAdapter( private val voteRepository: VoteRepository, ) : VoteCommandPort, VoteQueryPort { - @Transactional override fun vote(votes: List) { voteRepository.saveAll(votes.map(VoteEntity::from)) } - } diff --git a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/RoomPlaceEntity.kt b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/RoomPlaceEntity.kt index dc3f681d..afe4d18c 100644 --- a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/RoomPlaceEntity.kt +++ b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/RoomPlaceEntity.kt @@ -31,28 +31,30 @@ class RoomPlaceEntity( val starGrade: Float? = null, @Enumerated(EnumType.STRING) val source: Source, -) : BaseEntity() +) : BaseEntity() { + fun toDomain(): RoomPlace { + return RoomPlace( + roomId = this.roomId, + url = this.url, + thumbnailLinks = ThumbnailLinks(this.thumbnailLinks), + address = this.address, + phoneNumber = this.phoneNumber, + starGrade = this.starGrade, + source = this.source, + ) + } -fun RoomPlaceEntity.toDomain(): RoomPlace { - return RoomPlace( - roomId = this.roomId, - url = this.url, - thumbnailLinks = ThumbnailLinks(this.thumbnailLinks), - address = this.address, - phoneNumber = this.phoneNumber, - starGrade = this.starGrade, - source = this.source, - ) -} - -fun RoomPlace.toEntity(): RoomPlaceEntity { - return RoomPlaceEntity( - roomId = this.roomId, - url = this.url, - thumbnailLinks = this.thumbnailLinks.contents.toString(), - address = this.address, - phoneNumber = this.phoneNumber, - starGrade = this.starGrade, - source = this.source, - ) + companion object { + fun toEntity(roomPlace: RoomPlace): RoomPlaceEntity { + return RoomPlaceEntity( + roomId = roomPlace.roomId, + url = roomPlace.url, + thumbnailLinks = roomPlace.thumbnailLinks.contents.toString(), + address = roomPlace.address, + phoneNumber = roomPlace.phoneNumber, + starGrade = roomPlace.starGrade, + source = roomPlace.source, + ) + } + } } diff --git a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/VoteEntity.kt b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/VoteEntity.kt index 178865b5..7929bef9 100644 --- a/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/VoteEntity.kt +++ b/piikii-output-persistence/postgresql/src/main/kotlin/com/piikii/output/persistence/postgresql/persistence/entity/VoteEntity.kt @@ -25,7 +25,6 @@ class VoteEntity( @Column(name = "result", nullable = false, length = 10) val result: VoteResult, ) : BaseEntity() { - fun toDomain(): Vote { return Vote( userId = this.userId, @@ -43,5 +42,4 @@ class VoteEntity( ) } } - } From 8ff97631e6d5f429432006e689eae69db2d369e7 Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 29 Jun 2024 21:27:53 +0900 Subject: [PATCH 11/14] feat: added RequestBody swagger annotation --- .../kotlin/com/piikii/input/http/docs/VoteApiDocs.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt index b0799680..7814999d 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/VoteApiDocs.kt @@ -3,16 +3,22 @@ package com.piikii.input.http.docs import com.piikii.input.http.dto.ResponseForm import com.piikii.input.http.dto.request.VoteRequest import io.swagger.v3.oas.annotations.Operation +import io.swagger.v3.oas.annotations.media.Content +import io.swagger.v3.oas.annotations.media.Schema +import io.swagger.v3.oas.annotations.parameters.RequestBody import io.swagger.v3.oas.annotations.responses.ApiResponse import io.swagger.v3.oas.annotations.responses.ApiResponses import io.swagger.v3.oas.annotations.tags.Tag -import org.springframework.web.bind.annotation.RequestBody @Tag(name = "VoteApi", description = "Vote (투표) API") interface VoteApiDocs { @Operation(summary = "투표 API", description = "투표를 진행합니다") @ApiResponses(value = [ApiResponse(responseCode = "201", description = "Vote succeed")]) fun vote( - @RequestBody voteRequest: VoteRequest, + @RequestBody( + description = "투표 생성 Request body", + required = true, + content = [Content(schema = Schema(implementation = VoteRequest::class))], + ) voteRequest: VoteRequest, ): ResponseForm } From 77eafbf59ca54c582cfd74b4531717b83387376a Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 29 Jun 2024 22:09:55 +0900 Subject: [PATCH 12/14] fix: fix Parameter anntation values --- .../com/piikii/input/http/docs/RoomApiDocs.kt | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/RoomApiDocs.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/RoomApiDocs.kt index 9a5aec1b..a84bd85c 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/RoomApiDocs.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/RoomApiDocs.kt @@ -8,6 +8,12 @@ import com.piikii.application.port.input.room.dto.response.RoomSaveResponseForm import com.piikii.input.http.dto.ResponseForm import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.Parameter + +<<<<<<< HEAD +======= +import io.swagger.v3.oas.annotations.enums.ParameterIn + +>>>>>>> 66e9487 (fix: fix Parameter anntation values) import io.swagger.v3.oas.annotations.responses.ApiResponse import io.swagger.v3.oas.annotations.responses.ApiResponses import io.swagger.v3.oas.annotations.tags.Tag @@ -26,13 +32,23 @@ interface RoomApiDocs { @Operation(summary = "방 삭제 api", description = "방(Room) 정보를 삭제합니다.") @ApiResponses(value = [ApiResponse(responseCode = "200", description = "DELETED success")]) fun remove( - @Parameter(name = "방 id", description = "삭제하고자 하는 방 id") roomId: UUID, + @Parameter( + name = "roomId", + description = "삭제하고자 하는 방 id", + required = true, + `in` = ParameterIn.PATH, + ) roomId: UUID, ): ResponseForm @Operation(summary = "방 조회 api", description = "방(Room) 정보를 조회합니다.") @ApiResponses(value = [ApiResponse(responseCode = "200", description = "GET success")]) fun search( - @Parameter(name = "방 id", description = "조회하고자 하는 방 id") roomId: UUID, + @Parameter( + name = "roomId", + description = "삭제하고자 하는 방 id", + required = true, + `in` = ParameterIn.PATH, + ) roomId: UUID, ): ResponseForm @Operation(summary = "방 투표 마감일 설정 api", description = "방(Room)의 투표 마감일을 설정합니다.") From b9ca4c9edf68db2aa1c8ee008f5d7e7ffda4bb8e Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 29 Jun 2024 21:35:38 +0900 Subject: [PATCH 13/14] chore: added ktlintCheck step --- .github/workflows/ci-pull-request.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-pull-request.yml b/.github/workflows/ci-pull-request.yml index 2ea6fe48..866c5cfd 100644 --- a/.github/workflows/ci-pull-request.yml +++ b/.github/workflows/ci-pull-request.yml @@ -29,12 +29,14 @@ jobs: restore-keys: | ${{ runner.os }}-gradle- + - name: ktlint check + run: ./gradlew ktlintCheck + - name: 프로젝트 빌드 env: SECRET_MANAGER_TOKEN: ${{ secrets.SECRET_MANAGER_TOKEN }} SECRET_MANAGER_WORKSPACE: ${{ secrets.SECRET_MANAGER_WORKSPACE }} - run: | - ./gradlew build + run: ./gradlew build - name: Set build status output id: set_status From 01e1ff551fda82a836a6e676eebdb4d5c863300f Mon Sep 17 00:00:00 2001 From: KimDoubleB Date: Sat, 29 Jun 2024 22:08:44 +0900 Subject: [PATCH 14/14] feat: apply reviews - `toDomain` to `toDomains` - Vote to Data Class --- .../main/kotlin/com/piikii/application/domain/vote/Vote.kt | 2 +- .../main/kotlin/com/piikii/input/http/controller/VoteApi.kt | 2 +- .../src/main/kotlin/com/piikii/input/http/docs/RoomApiDocs.kt | 4 ---- .../kotlin/com/piikii/input/http/dto/request/VoteRequest.kt | 2 +- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/Vote.kt b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/Vote.kt index 02d33f23..99ac45d6 100644 --- a/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/Vote.kt +++ b/piikii-application/src/main/kotlin/com/piikii/application/domain/vote/Vote.kt @@ -2,7 +2,7 @@ package com.piikii.application.domain.vote import java.util.UUID -class Vote( +data class Vote( val userId: UUID, val roomPlaceId: Long, val result: VoteResult, diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.kt index bf40a043..9b6d9e96 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/controller/VoteApi.kt @@ -19,7 +19,7 @@ class VoteApi(private val voteUseCase: VoteUseCase) : VoteApiDocs { override fun vote( @RequestBody voteRequest: VoteRequest, ): ResponseForm { - voteUseCase.vote(voteRequest.roomId, voteRequest.toDomain()) + voteUseCase.vote(voteRequest.roomId, voteRequest.toDomains()) return ResponseForm.EMPTY_RESPONSE } } diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/RoomApiDocs.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/RoomApiDocs.kt index a84bd85c..297a3015 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/RoomApiDocs.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/docs/RoomApiDocs.kt @@ -9,11 +9,7 @@ import com.piikii.input.http.dto.ResponseForm import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.Parameter -<<<<<<< HEAD -======= import io.swagger.v3.oas.annotations.enums.ParameterIn - ->>>>>>> 66e9487 (fix: fix Parameter anntation values) import io.swagger.v3.oas.annotations.responses.ApiResponse import io.swagger.v3.oas.annotations.responses.ApiResponses import io.swagger.v3.oas.annotations.tags.Tag diff --git a/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/request/VoteRequest.kt b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/request/VoteRequest.kt index c76a5923..6db5ec75 100644 --- a/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/request/VoteRequest.kt +++ b/piikii-input-http/src/main/kotlin/com/piikii/input/http/dto/request/VoteRequest.kt @@ -9,7 +9,7 @@ data class VoteRequest( val roomId: UUID, val votes: List, ) { - fun toDomain(): List { + fun toDomains(): List { return this.votes.map { Vote(userId = userId, roomPlaceId = it.roomPlaceId, result = it.voteResult) } } }