Skip to content

Commit

Permalink
feat #2 공통 로그 정보 조회 api
Browse files Browse the repository at this point in the history
  • Loading branch information
chs98412 committed Jun 17, 2024
1 parent b88591f commit 4a77970
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -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,
)
}
}
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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))
}
}
Original file line number Diff line number Diff line change
@@ -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,
)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/test/http/common-game.http
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ Service-Code:eyJubyI6MSwidGl0bGUiOiJ0aXRsZSJ9
"doubleColumn1Name": "doubleColumn1Name",
"doubleColumn2Name": "doubleColumn2Name",
"dateTimeColumn1Name": "dateTimeColumn1Name"
}
}

### 로그 정보 조회
GET localhost:8084/common/commonLog/info?commonLogInfoNo=1
Content-Type: application/json
Service-Code:eyJubyI6MSwidGl0bGUiOiJ0aXRsZSJ9

0 comments on commit 4a77970

Please sign in to comment.