From 4a779702b94a049ab8aa96c373b22702c71d0fa7 Mon Sep 17 00:00:00 2001 From: chs98412 Date: Mon, 17 Jun 2024 22:12:21 +0900 Subject: [PATCH] =?UTF-8?q?feat=20#2=20=EA=B3=B5=ED=86=B5=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commonLog/CommonLogQueryService.kt | 20 +++++++++++ .../model/CommonLogInfoGetSummary.kt | 32 ++++++++++++++++++ .../handler/commonLog/CommonLogHandler.kt | 16 ++++++--- .../commonLog/model/CommonLogInfoResponse.kt | 33 +++++++++++++++++++ .../router/commonLog/CommonLogRouter.kt | 1 + src/test/http/common-game.http | 7 +++- 6 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 src/main/kotlin/com/soon/common/application/commonLog/CommonLogQueryService.kt create mode 100644 src/main/kotlin/com/soon/common/application/commonLog/model/CommonLogInfoGetSummary.kt create mode 100644 src/main/kotlin/com/soon/common/presentation/handler/commonLog/model/CommonLogInfoResponse.kt diff --git a/src/main/kotlin/com/soon/common/application/commonLog/CommonLogQueryService.kt b/src/main/kotlin/com/soon/common/application/commonLog/CommonLogQueryService.kt new file mode 100644 index 0000000..05d9302 --- /dev/null +++ b/src/main/kotlin/com/soon/common/application/commonLog/CommonLogQueryService.kt @@ -0,0 +1,20 @@ +package com.soon.common.application.commonLog + +import com.soon.common.application.commonLog.model.CommonLogInfoGetSummary +import com.soon.common.domain.commonLog.CommonLogInfoRepository +import org.springframework.data.crossstore.ChangeSetPersister.NotFoundException +import org.springframework.data.repository.findByIdOrNull +import org.springframework.stereotype.Service + +@Service +class CommonLogQueryService +( + private val commonLogInfoRepository: CommonLogInfoRepository, +) { + suspend fun getCommonLogInfo(serviceNo: Int, commonLogInfoNo: Int): CommonLogInfoGetSummary { + + return commonLogInfoRepository.findByIdOrNull(commonLogInfoNo)?.let { + CommonLogInfoGetSummary.of(it) + } ?: throw NotFoundException() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/soon/common/application/commonLog/model/CommonLogInfoGetSummary.kt b/src/main/kotlin/com/soon/common/application/commonLog/model/CommonLogInfoGetSummary.kt new file mode 100644 index 0000000..f70439c --- /dev/null +++ b/src/main/kotlin/com/soon/common/application/commonLog/model/CommonLogInfoGetSummary.kt @@ -0,0 +1,32 @@ +package com.soon.common.application.commonLog.model + +import com.soon.common.domain.commonLog.CommonLogInfo +import java.time.LocalDateTime + +data class CommonLogInfoGetSummary( + val commonLogInfoNo: Int, + val logName: String, + val description: String, + val intColumn1Name: String?, + val intColumn2Name: String?, + val doubleColumn1Name: String?, + val doubleColumn2Name: String?, + val dateTimeColumn1Name: String?, + val dateTimeColumn2Name: String?, + val createdAt: LocalDateTime, +) { + companion object { + fun of(entity: CommonLogInfo) = CommonLogInfoGetSummary( + commonLogInfoNo = entity.no, + logName = entity.logName, + description = entity.description, + intColumn1Name = entity.intColumn1Name, + intColumn2Name = entity.intColumn2Name, + doubleColumn1Name = entity.doubleColumn1Name, + doubleColumn2Name = entity.doubleColumn2Name, + dateTimeColumn1Name = entity.dateTimeColumn1Name, + dateTimeColumn2Name = entity.dateTimeColumn2Name, + createdAt = entity.createdAt, + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/soon/common/presentation/handler/commonLog/CommonLogHandler.kt b/src/main/kotlin/com/soon/common/presentation/handler/commonLog/CommonLogHandler.kt index 7b8f92c..46b5d5c 100644 --- a/src/main/kotlin/com/soon/common/presentation/handler/commonLog/CommonLogHandler.kt +++ b/src/main/kotlin/com/soon/common/presentation/handler/commonLog/CommonLogHandler.kt @@ -1,19 +1,20 @@ package com.soon.common.presentation.handler.commonLog import com.soon.common.application.commonLog.CommonLogCommandService +import com.soon.common.application.commonLog.CommonLogQueryService import com.soon.common.application.util.coroutines.ApplicationDispatchers import com.soon.common.presentation.extension.extractServiceCodeHeader +import com.soon.common.presentation.extension.intQueryParam import com.soon.common.presentation.handler.commonLog.model.CommonLogInfoCreateRequest +import com.soon.common.presentation.handler.commonLog.model.CommonLogInfoResponse import kotlinx.coroutines.withContext import org.springframework.stereotype.Service -import org.springframework.web.reactive.function.server.ServerRequest -import org.springframework.web.reactive.function.server.ServerResponse -import org.springframework.web.reactive.function.server.awaitBodyOrNull -import org.springframework.web.reactive.function.server.buildAndAwait +import org.springframework.web.reactive.function.server.* @Service class CommonLogHandler( private val commonLogCommandService: CommonLogCommandService, + private val commonLogQueryService: CommonLogQueryService, ) { suspend fun createCommonLogInfo(request: ServerRequest): ServerResponse = withContext(ApplicationDispatchers.IO) { val serviceHeader = request.extractServiceCodeHeader() @@ -23,4 +24,11 @@ class CommonLogHandler( commonLogCommandService.createCommonLogInfo(command) ServerResponse.noContent().buildAndAwait() } + + suspend fun getCommonLogInfo(request: ServerRequest): ServerResponse = withContext(ApplicationDispatchers.IO) { + val serviceHeader = request.extractServiceCodeHeader() + val commonLogInfoNo = request.intQueryParam("commonLogInfoNo") + val summary = commonLogQueryService.getCommonLogInfo(serviceHeader.no, commonLogInfoNo) + ServerResponse.ok().bodyValueAndAwait(CommonLogInfoResponse.of(summary)) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/soon/common/presentation/handler/commonLog/model/CommonLogInfoResponse.kt b/src/main/kotlin/com/soon/common/presentation/handler/commonLog/model/CommonLogInfoResponse.kt new file mode 100644 index 0000000..dbf0ead --- /dev/null +++ b/src/main/kotlin/com/soon/common/presentation/handler/commonLog/model/CommonLogInfoResponse.kt @@ -0,0 +1,33 @@ +package com.soon.common.presentation.handler.commonLog.model + +import com.soon.common.application.commonLog.model.CommonLogInfoGetSummary +import java.time.LocalDateTime + +data class CommonLogInfoResponse( + val commonLogInfoNo: Int, + val logName: String, + val description: String, + val intColumn1Name: String?, + val intColumn2Name: String?, + val doubleColumn1Name: String?, + val doubleColumn2Name: String?, + val dateTimeColumn1Name: String?, + val dateTimeColumn2Name: String?, + val createdAt: LocalDateTime, +) { + companion object { + fun of(summary: CommonLogInfoGetSummary) = CommonLogInfoResponse( + commonLogInfoNo = summary.commonLogInfoNo, + logName = summary.logName, + description = summary.description, + intColumn1Name = summary.intColumn1Name, + intColumn2Name = summary.intColumn2Name, + doubleColumn1Name = summary.doubleColumn1Name, + doubleColumn2Name = summary.doubleColumn2Name, + dateTimeColumn1Name = summary.dateTimeColumn1Name, + dateTimeColumn2Name = summary.dateTimeColumn2Name, + createdAt = summary.createdAt, + ) + } +} + diff --git a/src/main/kotlin/com/soon/common/presentation/router/commonLog/CommonLogRouter.kt b/src/main/kotlin/com/soon/common/presentation/router/commonLog/CommonLogRouter.kt index fe16e69..8102655 100644 --- a/src/main/kotlin/com/soon/common/presentation/router/commonLog/CommonLogRouter.kt +++ b/src/main/kotlin/com/soon/common/presentation/router/commonLog/CommonLogRouter.kt @@ -15,6 +15,7 @@ class CommonLogRouter(private val commonLogHandler: CommonLogHandler) { return coRouter { (accept(MediaType.APPLICATION_JSON) and "/common/commonLog").nest { POST("info", commonLogHandler::createCommonLogInfo) + GET("info", commonLogHandler::getCommonLogInfo) } } } diff --git a/src/test/http/common-game.http b/src/test/http/common-game.http index 1122a58..0893bbf 100644 --- a/src/test/http/common-game.http +++ b/src/test/http/common-game.http @@ -32,4 +32,9 @@ Service-Code:eyJubyI6MSwidGl0bGUiOiJ0aXRsZSJ9 "doubleColumn1Name": "doubleColumn1Name", "doubleColumn2Name": "doubleColumn2Name", "dateTimeColumn1Name": "dateTimeColumn1Name" -} \ No newline at end of file +} + +### 로그 정보 조회 +GET localhost:8084/common/commonLog/info?commonLogInfoNo=1 +Content-Type: application/json +Service-Code:eyJubyI6MSwidGl0bGUiOiJ0aXRsZSJ9 \ No newline at end of file