From 188dd24989268c92ddefa1a0d32d7ef323e8dda7 Mon Sep 17 00:00:00 2001 From: "HKMC\\H2211843" <9417143@ict-companion.com> Date: Tue, 10 Oct 2023 17:34:26 +0900 Subject: [PATCH 01/19] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1=20=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/common/comp/impl/PurchaseManager.kt | 21 ++++++++ .../api/common/comp/impl/PurchaseReader.kt | 49 +++++++++++++++++++ .../api/purchase/PurchaseController.kt | 24 +++++++++ .../commerce/api/purchase/PurchaseService.kt | 28 +++++++++++ .../api/purchase/domain/GetPurchaseRequest.kt | 4 ++ .../purchase/domain/GetPurchaseResponse.kt | 15 ++++++ .../api/purchase/domain/GetPurchaseResult.kt | 4 ++ .../domain/PostPurchaseDeleteRequest.kt | 4 ++ .../purchase/domain/PostPurchaseRequest.kt | 4 ++ .../purchase/domain/PostPurchaseResponse.kt | 4 ++ .../domain/PostPurchaseUpdateRequest.kt | 4 ++ 11 files changed, 161 insertions(+) create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseReader.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResponse.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt new file mode 100644 index 0000000..b6682c4 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt @@ -0,0 +1,21 @@ +package com.hanghea99.commerce.api.common.comp.impl + +import com.hanghea99.commerce.api.common.comp.ManagerComponent +import com.hanghea99.commerce.database.entity.PurchaseEntity +import com.hanghea99.commerce.database.repository.PurchaseRepository +import org.springframework.stereotype.Component + +@Component +class PurchaseManager(var purchaseRepository :PurchaseRepository) : ManagerComponent() { + override fun update(entities: List): Long { + TODO("Not yet implemented") + } + + override fun delete(entityIds: List) { + TODO("Not yet implemented") + } + + override fun create(entities: List): List { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseReader.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseReader.kt new file mode 100644 index 0000000..f8649dc --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseReader.kt @@ -0,0 +1,49 @@ +package com.hanghea99.commerce.api.common.comp.impl + +import com.hanghea99.commerce.api.common.comp.ReaderComponent +import com.hanghea99.commerce.database.entity.PurchaseEntity + +import com.hanghea99.commerce.database.repository.PurchaseRepository +import com.querydsl.core.BooleanBuilder +import com.querydsl.core.types.OrderSpecifier +import com.querydsl.jpa.impl.JPAQueryFactory +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Component + +@Component +class PurchaseReader ( + val purchaseRepository: PurchaseRepository, + val jpaQueryFactory: JPAQueryFactory, +) : ReaderComponent( + ) { + private val log = LoggerFactory.getLogger("PurchaseReader") + + override fun read(id: Long): PurchaseEntity { + TODO("Not yet implemented") + } + + override fun read(where: BooleanBuilder): PurchaseEntity { + TODO("Not yet implemented") + } + + override fun readAll(ids: List): List { + TODO("Not yet implemented") + } + + override fun readAll( + where: BooleanBuilder, + offset: Long, + count: Long, + orders: MutableList> + ): List { + TODO("Not yet implemented") + } + + override fun readAllCount(ids: List): Long { + TODO("Not yet implemented") + } + + override fun readAllCount(where: BooleanBuilder): Long { + TODO("Not yet implemented") + } +} diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt new file mode 100644 index 0000000..7e67166 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt @@ -0,0 +1,24 @@ +package com.hanghea99.commerce.api.purchase + +import com.hanghea99.commerce.api.purchase.domain.GetPurchaseRequest +import com.hanghea99.commerce.api.purchase.domain.GetPurchaseResponse +import com.hanghea99.commerce.logger +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + + +@RestController +@RequestMapping("/api/purchase") +class PurchaseController(val purchaseService: PurchaseService) { + private val log = logger() + + @GetMapping("") + @Throws(Exception::class) + fun getPurchase(getPurchaseRequest: GetPurchaseRequest): GetPurchaseResponse{ + return purchaseService.getPurchase(getPurchaseRequest) + } + + +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt new file mode 100644 index 0000000..7b08ff2 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt @@ -0,0 +1,28 @@ +package com.hanghea99.commerce.api.purchase + +import com.hanghea99.commerce.api.common.ResultCodeMsg +import com.hanghea99.commerce.api.common.comp.impl.PurchaseManager +import com.hanghea99.commerce.api.common.comp.impl.PurchaseReader +import com.hanghea99.commerce.api.purchase.domain.GetPurchaseRequest +import com.hanghea99.commerce.api.purchase.domain.GetPurchaseResponse +import com.hanghea99.commerce.api.store.domain.GetStoreResponse +import com.hanghea99.commerce.logger +import org.springframework.stereotype.Service +import org.springframework.validation.annotation.Validated +import kotlin.jvm.Throws + +@Service +@Validated +class PurchaseService( + var purchaseManager: PurchaseManager, + var purchaseReader: PurchaseReader +){ + private val log = logger() + + @Throws(Exception::class) + fun getPurchase(getPurchaseRequest: GetPurchaseRequest): GetPurchaseResponse{ + + + return GetPurchaseResponse(ResultCodeMsg.SUCCESS) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt new file mode 100644 index 0000000..14835cd --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt @@ -0,0 +1,4 @@ +package com.hanghea99.commerce.api.purchase.domain + +class GetPurchaseRequest { +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResponse.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResponse.kt new file mode 100644 index 0000000..2b32d54 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResponse.kt @@ -0,0 +1,15 @@ +package com.hanghea99.commerce.api.purchase.domain + +import com.hanghea99.commerce.api.common.ResultCodeMsg + +data class GetPurchaseResponse( + val code: String, + val msg: String, + val result: Object? = null +){ + constructor(resultCodeMsg:ResultCodeMsg):this( + code = resultCodeMsg.code, + msg = resultCodeMsg.msg, + result = null + ) +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt new file mode 100644 index 0000000..1fbc711 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt @@ -0,0 +1,4 @@ +package com.hanghea99.commerce.api.purchase.domain + +class GetPurchaseResult { +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt new file mode 100644 index 0000000..a1deea4 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt @@ -0,0 +1,4 @@ +package com.hanghea99.commerce.api.purchase.domain + +class PostPurchaseDeleteRequest { +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt new file mode 100644 index 0000000..3d12e90 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt @@ -0,0 +1,4 @@ +package com.hanghea99.commerce.api.purchase.domain + +class PostPurchaseRequest { +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt new file mode 100644 index 0000000..d6683d4 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt @@ -0,0 +1,4 @@ +package com.hanghea99.commerce.api.purchase.domain + +class PostPurchaseResponse { +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt new file mode 100644 index 0000000..532a4a3 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt @@ -0,0 +1,4 @@ +package com.hanghea99.commerce.api.purchase.domain + +class PostPurchaseUpdateRequest { +} \ No newline at end of file From dec9f2124a54434de5f17dc044b757053a28d1f4 Mon Sep 17 00:00:00 2001 From: "HKMC\\H2211843" <9417143@ict-companion.com> Date: Tue, 10 Oct 2023 17:45:46 +0900 Subject: [PATCH 02/19] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1=20=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/purchase/PurchaseControllerTest.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/kotlin/com/hanghea99/commerce/api/purchase/PurchaseControllerTest.kt diff --git a/src/test/kotlin/com/hanghea99/commerce/api/purchase/PurchaseControllerTest.kt b/src/test/kotlin/com/hanghea99/commerce/api/purchase/PurchaseControllerTest.kt new file mode 100644 index 0000000..d8af5a1 --- /dev/null +++ b/src/test/kotlin/com/hanghea99/commerce/api/purchase/PurchaseControllerTest.kt @@ -0,0 +1,18 @@ +package com.hanghea99.commerce.api.purchase + +import org.junit.jupiter.api.Test + +import org.junit.jupiter.api.Assertions.* +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest + +@WebMvcTest(PurchaseController::class) +class PurchaseControllerTest { + + @Test + fun getPurchase() { + } + + @Test + fun getPurchaseService() { + } +} \ No newline at end of file From 563e375d3aa0190a81431aa319595b6cd617a0fa Mon Sep 17 00:00:00 2001 From: imdaebeen Date: Wed, 11 Oct 2023 00:33:14 +0900 Subject: [PATCH 03/19] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/common/domain/purchase/PurchaseVo.kt | 13 ++++++++++ .../api/purchase/domain/GetPurchaseRequest.kt | 24 +++++++++++++++++-- .../api/purchase/domain/GetPurchaseResult.kt | 8 +++++-- .../domain/PostPurchaseDeleteRequest.kt | 7 ++++-- .../purchase/domain/PostPurchaseRequest.kt | 7 ++++-- .../purchase/domain/PostPurchaseResponse.kt | 11 +++++++-- .../domain/PostPurchaseUpdateRequest.kt | 8 +++++-- 7 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/common/domain/purchase/PurchaseVo.kt diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/domain/purchase/PurchaseVo.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/domain/purchase/PurchaseVo.kt new file mode 100644 index 0000000..1df05e3 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/domain/purchase/PurchaseVo.kt @@ -0,0 +1,13 @@ +package com.hanghea99.commerce.api.common.domain.purchase + +import java.math.BigDecimal +import java.time.Instant + +data class PurchaseVo ( + var purchaseKey: Long? = null, + var userId: Long? = null, + var totalPrice: BigDecimal, + var purchaseDate: Instant, + var cancleDate: Instant, + var status: String, +) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt index 14835cd..5fc655e 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt @@ -1,4 +1,24 @@ package com.hanghea99.commerce.api.purchase.domain -class GetPurchaseRequest { -} \ No newline at end of file +import com.hanghea99.commerce.api.common.domain.GetRequest +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Positive +import jakarta.validation.constraints.PositiveOrZero + + +data class GetPurchaseRequest ( + @Pattern(regexp = "NAME|^$") + override val types: String?, + + override val values: String?, + + @Positive + override val page: Long = 1, + + @PositiveOrZero + override val count: Long = 10, + + @Pattern(regexp = "LATEST|NAME_ASC|NAME_DESC^$") + override val sort: String = "LATEST", + +):GetRequest(types, values, page, count, sort) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt index 1fbc711..b3b533e 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt @@ -1,4 +1,8 @@ package com.hanghea99.commerce.api.purchase.domain -class GetPurchaseResult { -} \ No newline at end of file +import com.hanghea99.commerce.api.common.domain.store.StoreVo + +data class GetPurchaseResult( + val totalCount: Long, + val stores: List, +) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt index a1deea4..a55614c 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt @@ -1,4 +1,7 @@ package com.hanghea99.commerce.api.purchase.domain -class PostPurchaseDeleteRequest { -} \ No newline at end of file +import com.hanghea99.commerce.api.common.domain.core.CoreRequest + +data class PostPurchaseDeleteRequest ( + val deleteKeys: List +): CoreRequest() \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt index 3d12e90..6f78181 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt @@ -1,4 +1,7 @@ package com.hanghea99.commerce.api.purchase.domain -class PostPurchaseRequest { -} \ No newline at end of file +import com.hanghea99.commerce.api.common.domain.core.CoreRequest +import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo + +data class PostPurchaseRequest(val purchase:PurchaseVo) : + CoreRequest() diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt index d6683d4..ede139c 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt @@ -1,4 +1,11 @@ package com.hanghea99.commerce.api.purchase.domain -class PostPurchaseResponse { -} \ No newline at end of file +import com.hanghea99.commerce.api.common.ResultCodeMsg +import com.hanghea99.commerce.api.common.domain.core.CoreResponse +import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo + +data class PostPurchaseResponse ( + var resultCodeMsg: ResultCodeMsg, override var result: PurchaseVo +) : CoreResponse(resultCodeMsg.code, resultCodeMsg.msg, result) { + +} diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt index 532a4a3..ca8cbbc 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt @@ -1,4 +1,8 @@ package com.hanghea99.commerce.api.purchase.domain -class PostPurchaseUpdateRequest { -} \ No newline at end of file +import com.hanghea99.commerce.api.common.domain.core.CoreRequest +import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo + +data class PostPurchaseUpdateRequest( + val purchase: PurchaseVo +): CoreRequest() \ No newline at end of file From 3e6d88ed9ca990df4b633bf75a9ccd49e5833b2c Mon Sep 17 00:00:00 2001 From: "HKMC\\H2211843" <9417143@ict-companion.com> Date: Tue, 10 Oct 2023 17:34:26 +0900 Subject: [PATCH 04/19] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1=20=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/common/comp/impl/PurchaseManager.kt | 21 ++++++++ .../api/common/comp/impl/PurchaseReader.kt | 49 +++++++++++++++++++ .../api/purchase/PurchaseController.kt | 24 +++++++++ .../commerce/api/purchase/PurchaseService.kt | 28 +++++++++++ .../api/purchase/domain/GetPurchaseRequest.kt | 4 ++ .../purchase/domain/GetPurchaseResponse.kt | 15 ++++++ .../api/purchase/domain/GetPurchaseResult.kt | 4 ++ .../domain/PostPurchaseDeleteRequest.kt | 4 ++ .../purchase/domain/PostPurchaseRequest.kt | 4 ++ .../purchase/domain/PostPurchaseResponse.kt | 4 ++ .../domain/PostPurchaseUpdateRequest.kt | 4 ++ 11 files changed, 161 insertions(+) create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseReader.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResponse.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt new file mode 100644 index 0000000..b6682c4 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt @@ -0,0 +1,21 @@ +package com.hanghea99.commerce.api.common.comp.impl + +import com.hanghea99.commerce.api.common.comp.ManagerComponent +import com.hanghea99.commerce.database.entity.PurchaseEntity +import com.hanghea99.commerce.database.repository.PurchaseRepository +import org.springframework.stereotype.Component + +@Component +class PurchaseManager(var purchaseRepository :PurchaseRepository) : ManagerComponent() { + override fun update(entities: List): Long { + TODO("Not yet implemented") + } + + override fun delete(entityIds: List) { + TODO("Not yet implemented") + } + + override fun create(entities: List): List { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseReader.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseReader.kt new file mode 100644 index 0000000..f8649dc --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseReader.kt @@ -0,0 +1,49 @@ +package com.hanghea99.commerce.api.common.comp.impl + +import com.hanghea99.commerce.api.common.comp.ReaderComponent +import com.hanghea99.commerce.database.entity.PurchaseEntity + +import com.hanghea99.commerce.database.repository.PurchaseRepository +import com.querydsl.core.BooleanBuilder +import com.querydsl.core.types.OrderSpecifier +import com.querydsl.jpa.impl.JPAQueryFactory +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Component + +@Component +class PurchaseReader ( + val purchaseRepository: PurchaseRepository, + val jpaQueryFactory: JPAQueryFactory, +) : ReaderComponent( + ) { + private val log = LoggerFactory.getLogger("PurchaseReader") + + override fun read(id: Long): PurchaseEntity { + TODO("Not yet implemented") + } + + override fun read(where: BooleanBuilder): PurchaseEntity { + TODO("Not yet implemented") + } + + override fun readAll(ids: List): List { + TODO("Not yet implemented") + } + + override fun readAll( + where: BooleanBuilder, + offset: Long, + count: Long, + orders: MutableList> + ): List { + TODO("Not yet implemented") + } + + override fun readAllCount(ids: List): Long { + TODO("Not yet implemented") + } + + override fun readAllCount(where: BooleanBuilder): Long { + TODO("Not yet implemented") + } +} diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt new file mode 100644 index 0000000..7e67166 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt @@ -0,0 +1,24 @@ +package com.hanghea99.commerce.api.purchase + +import com.hanghea99.commerce.api.purchase.domain.GetPurchaseRequest +import com.hanghea99.commerce.api.purchase.domain.GetPurchaseResponse +import com.hanghea99.commerce.logger +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + + +@RestController +@RequestMapping("/api/purchase") +class PurchaseController(val purchaseService: PurchaseService) { + private val log = logger() + + @GetMapping("") + @Throws(Exception::class) + fun getPurchase(getPurchaseRequest: GetPurchaseRequest): GetPurchaseResponse{ + return purchaseService.getPurchase(getPurchaseRequest) + } + + +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt new file mode 100644 index 0000000..7b08ff2 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt @@ -0,0 +1,28 @@ +package com.hanghea99.commerce.api.purchase + +import com.hanghea99.commerce.api.common.ResultCodeMsg +import com.hanghea99.commerce.api.common.comp.impl.PurchaseManager +import com.hanghea99.commerce.api.common.comp.impl.PurchaseReader +import com.hanghea99.commerce.api.purchase.domain.GetPurchaseRequest +import com.hanghea99.commerce.api.purchase.domain.GetPurchaseResponse +import com.hanghea99.commerce.api.store.domain.GetStoreResponse +import com.hanghea99.commerce.logger +import org.springframework.stereotype.Service +import org.springframework.validation.annotation.Validated +import kotlin.jvm.Throws + +@Service +@Validated +class PurchaseService( + var purchaseManager: PurchaseManager, + var purchaseReader: PurchaseReader +){ + private val log = logger() + + @Throws(Exception::class) + fun getPurchase(getPurchaseRequest: GetPurchaseRequest): GetPurchaseResponse{ + + + return GetPurchaseResponse(ResultCodeMsg.SUCCESS) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt new file mode 100644 index 0000000..14835cd --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt @@ -0,0 +1,4 @@ +package com.hanghea99.commerce.api.purchase.domain + +class GetPurchaseRequest { +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResponse.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResponse.kt new file mode 100644 index 0000000..2b32d54 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResponse.kt @@ -0,0 +1,15 @@ +package com.hanghea99.commerce.api.purchase.domain + +import com.hanghea99.commerce.api.common.ResultCodeMsg + +data class GetPurchaseResponse( + val code: String, + val msg: String, + val result: Object? = null +){ + constructor(resultCodeMsg:ResultCodeMsg):this( + code = resultCodeMsg.code, + msg = resultCodeMsg.msg, + result = null + ) +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt new file mode 100644 index 0000000..1fbc711 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt @@ -0,0 +1,4 @@ +package com.hanghea99.commerce.api.purchase.domain + +class GetPurchaseResult { +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt new file mode 100644 index 0000000..a1deea4 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt @@ -0,0 +1,4 @@ +package com.hanghea99.commerce.api.purchase.domain + +class PostPurchaseDeleteRequest { +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt new file mode 100644 index 0000000..3d12e90 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt @@ -0,0 +1,4 @@ +package com.hanghea99.commerce.api.purchase.domain + +class PostPurchaseRequest { +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt new file mode 100644 index 0000000..d6683d4 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt @@ -0,0 +1,4 @@ +package com.hanghea99.commerce.api.purchase.domain + +class PostPurchaseResponse { +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt new file mode 100644 index 0000000..532a4a3 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt @@ -0,0 +1,4 @@ +package com.hanghea99.commerce.api.purchase.domain + +class PostPurchaseUpdateRequest { +} \ No newline at end of file From 41ccae6bd6cf6bea257cb9426da9e811deb942d7 Mon Sep 17 00:00:00 2001 From: "HKMC\\H2211843" <9417143@ict-companion.com> Date: Tue, 10 Oct 2023 17:45:46 +0900 Subject: [PATCH 05/19] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1=20=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/purchase/PurchaseControllerTest.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/kotlin/com/hanghea99/commerce/api/purchase/PurchaseControllerTest.kt diff --git a/src/test/kotlin/com/hanghea99/commerce/api/purchase/PurchaseControllerTest.kt b/src/test/kotlin/com/hanghea99/commerce/api/purchase/PurchaseControllerTest.kt new file mode 100644 index 0000000..d8af5a1 --- /dev/null +++ b/src/test/kotlin/com/hanghea99/commerce/api/purchase/PurchaseControllerTest.kt @@ -0,0 +1,18 @@ +package com.hanghea99.commerce.api.purchase + +import org.junit.jupiter.api.Test + +import org.junit.jupiter.api.Assertions.* +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest + +@WebMvcTest(PurchaseController::class) +class PurchaseControllerTest { + + @Test + fun getPurchase() { + } + + @Test + fun getPurchaseService() { + } +} \ No newline at end of file From bcf2a77ee2998060ec5a114677eafd0059dbce38 Mon Sep 17 00:00:00 2001 From: imdaebeen Date: Wed, 11 Oct 2023 00:33:14 +0900 Subject: [PATCH 06/19] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/common/domain/purchase/PurchaseVo.kt | 13 ++++++++++ .../api/purchase/domain/GetPurchaseRequest.kt | 24 +++++++++++++++++-- .../api/purchase/domain/GetPurchaseResult.kt | 8 +++++-- .../domain/PostPurchaseDeleteRequest.kt | 7 ++++-- .../purchase/domain/PostPurchaseRequest.kt | 7 ++++-- .../purchase/domain/PostPurchaseResponse.kt | 11 +++++++-- .../domain/PostPurchaseUpdateRequest.kt | 8 +++++-- 7 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/common/domain/purchase/PurchaseVo.kt diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/domain/purchase/PurchaseVo.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/domain/purchase/PurchaseVo.kt new file mode 100644 index 0000000..1df05e3 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/domain/purchase/PurchaseVo.kt @@ -0,0 +1,13 @@ +package com.hanghea99.commerce.api.common.domain.purchase + +import java.math.BigDecimal +import java.time.Instant + +data class PurchaseVo ( + var purchaseKey: Long? = null, + var userId: Long? = null, + var totalPrice: BigDecimal, + var purchaseDate: Instant, + var cancleDate: Instant, + var status: String, +) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt index 14835cd..5fc655e 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt @@ -1,4 +1,24 @@ package com.hanghea99.commerce.api.purchase.domain -class GetPurchaseRequest { -} \ No newline at end of file +import com.hanghea99.commerce.api.common.domain.GetRequest +import jakarta.validation.constraints.Pattern +import jakarta.validation.constraints.Positive +import jakarta.validation.constraints.PositiveOrZero + + +data class GetPurchaseRequest ( + @Pattern(regexp = "NAME|^$") + override val types: String?, + + override val values: String?, + + @Positive + override val page: Long = 1, + + @PositiveOrZero + override val count: Long = 10, + + @Pattern(regexp = "LATEST|NAME_ASC|NAME_DESC^$") + override val sort: String = "LATEST", + +):GetRequest(types, values, page, count, sort) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt index 1fbc711..b3b533e 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt @@ -1,4 +1,8 @@ package com.hanghea99.commerce.api.purchase.domain -class GetPurchaseResult { -} \ No newline at end of file +import com.hanghea99.commerce.api.common.domain.store.StoreVo + +data class GetPurchaseResult( + val totalCount: Long, + val stores: List, +) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt index a1deea4..a55614c 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt @@ -1,4 +1,7 @@ package com.hanghea99.commerce.api.purchase.domain -class PostPurchaseDeleteRequest { -} \ No newline at end of file +import com.hanghea99.commerce.api.common.domain.core.CoreRequest + +data class PostPurchaseDeleteRequest ( + val deleteKeys: List +): CoreRequest() \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt index 3d12e90..6f78181 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt @@ -1,4 +1,7 @@ package com.hanghea99.commerce.api.purchase.domain -class PostPurchaseRequest { -} \ No newline at end of file +import com.hanghea99.commerce.api.common.domain.core.CoreRequest +import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo + +data class PostPurchaseRequest(val purchase:PurchaseVo) : + CoreRequest() diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt index d6683d4..ede139c 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt @@ -1,4 +1,11 @@ package com.hanghea99.commerce.api.purchase.domain -class PostPurchaseResponse { -} \ No newline at end of file +import com.hanghea99.commerce.api.common.ResultCodeMsg +import com.hanghea99.commerce.api.common.domain.core.CoreResponse +import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo + +data class PostPurchaseResponse ( + var resultCodeMsg: ResultCodeMsg, override var result: PurchaseVo +) : CoreResponse(resultCodeMsg.code, resultCodeMsg.msg, result) { + +} diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt index 532a4a3..ca8cbbc 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt @@ -1,4 +1,8 @@ package com.hanghea99.commerce.api.purchase.domain -class PostPurchaseUpdateRequest { -} \ No newline at end of file +import com.hanghea99.commerce.api.common.domain.core.CoreRequest +import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo + +data class PostPurchaseUpdateRequest( + val purchase: PurchaseVo +): CoreRequest() \ No newline at end of file From 934331cc986a62f38cb7dea01cb2a078f9bd4d0c Mon Sep 17 00:00:00 2001 From: "HKMC\\H2211843" <9417143@ict-companion.com> Date: Wed, 11 Oct 2023 17:36:11 +0900 Subject: [PATCH 07/19] =?UTF-8?q?=EC=A3=BC=EB=AC=B8=20=EC=A1=B0=ED=9A=8C,?= =?UTF-8?q?=20=EC=A3=BC=EB=AC=B8=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 4 +- .../api/purchase/PurchaseController.kt | 20 +++++++- .../commerce/api/purchase/PurchaseService.kt | 49 +++++++++++++++++-- .../domain/GetPurchaseDetailRequest.kt | 4 ++ .../domain/GetPurchaseDetailResponse.kt | 15 ++++++ .../domain/GetPurchaseDetailResult.kt | 4 ++ .../purchase/domain/GetPurchaseDetailVo.kt | 7 +++ .../api/purchase/domain/GetPurchaseRequest.kt | 2 +- .../purchase/domain/GetPurchaseResponse.kt | 6 +-- .../api/purchase/domain/GetPurchaseVo.kt | 8 +++ 10 files changed, 108 insertions(+), 11 deletions(-) create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailRequest.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResponse.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResult.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailVo.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseVo.kt diff --git a/build.gradle.kts b/build.gradle.kts index fc60a1f..47d45a6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -45,8 +45,8 @@ dependencies { implementation("com.querydsl:querydsl-jpa:5.0.0:jakarta") implementation("com.querydsl:querydsl-core:5.0.0") - kapt("com.querydsl:querydsl-apt:5.0.0:jakarta") - kapt("com.querydsl:querydsl-kotlin-codegen:5.0.0") +// kapt("com.querydsl:querydsl-apt:5.0.0:jakarta") +// kapt("com.querydsl:querydsl-kotlin-codegen:5.0.0") implementation("net.ttddyy:datasource-proxy:1.9") diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt index 7e67166..9347f7e 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt @@ -1,5 +1,6 @@ package com.hanghea99.commerce.api.purchase +import com.hanghea99.commerce.api.purchase.domain.GetPurchaseDetailRequest import com.hanghea99.commerce.api.purchase.domain.GetPurchaseRequest import com.hanghea99.commerce.api.purchase.domain.GetPurchaseResponse import com.hanghea99.commerce.logger @@ -14,11 +15,28 @@ import org.springframework.web.bind.annotation.RestController class PurchaseController(val purchaseService: PurchaseService) { private val log = logger() + + /** + * API명 : PURCHASE_004 + * API용도 : 주문 전체 조회 + * @param GetPurchaseRequest + * @return GetPurchaseResponse + */ @GetMapping("") @Throws(Exception::class) fun getPurchase(getPurchaseRequest: GetPurchaseRequest): GetPurchaseResponse{ return purchaseService.getPurchase(getPurchaseRequest) } - + /** + * API명 : PURCHASE_005 + * API용도 : 주문 상세 조회 + * @param GetPurchaseDetailRequest + * @return GetPurchaseDetailResponse + */ + @GetMapping("/purchase-id") + @Throws(Exception::class) + fun getPurchaseDetail(getPurchaseDetailRequest: GetPurchaseDetailRequest) : GetPurchaseResponse { + return purchaseService.getPurchaseDetail(getPurchaseDetailRequest) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt index 7b08ff2..e3ca416 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt @@ -3,10 +3,11 @@ package com.hanghea99.commerce.api.purchase import com.hanghea99.commerce.api.common.ResultCodeMsg import com.hanghea99.commerce.api.common.comp.impl.PurchaseManager import com.hanghea99.commerce.api.common.comp.impl.PurchaseReader -import com.hanghea99.commerce.api.purchase.domain.GetPurchaseRequest -import com.hanghea99.commerce.api.purchase.domain.GetPurchaseResponse -import com.hanghea99.commerce.api.store.domain.GetStoreResponse +import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo +import com.hanghea99.commerce.api.purchase.domain.* +import com.hanghea99.commerce.database.entity.PurchaseEntity import com.hanghea99.commerce.logger +import com.querydsl.core.BooleanBuilder import org.springframework.stereotype.Service import org.springframework.validation.annotation.Validated import kotlin.jvm.Throws @@ -19,10 +20,50 @@ class PurchaseService( ){ private val log = logger() + var qPurchaseEntity: QPurchaseEntity = QPurchaseEntity("s1") + @Throws(Exception::class) fun getPurchase(getPurchaseRequest: GetPurchaseRequest): GetPurchaseResponse{ + val booleanBuilder = BooleanBuilder() + + booleanBuilder.and(qPurchaseEntity.deletedAt.isNull) + val result = purchaseReader.readAll( + booleanBuilder, + offset = if (getPurchaseRequest.page > 0) getPurchaseRequest.page * getPurchaseRequest.count else 0, + count = getPurchaseRequest.count, + orders = when (getPurchaseRequest.sort) { + "LATEST" -> mutableListOf(qPurchaseEntity.purchaseDate.desc()) + else -> mutableListOf(qPurchaseEntity.purchaseDate.desc()) + } + ) - return GetPurchaseResponse(ResultCodeMsg.SUCCESS) + return GetPurchaseResponse( + code = ResultCodeMsg.SUCCESS.code, + msg = ResultCodeMsg.SUCCESS.msg, + result = GetPurchaseVo( + totalCount = purchaseReader.readAllCount(booleanBuilder), + purchases = result.map { purchaseEntity -> + PurchaseVo( + purchaseKey = purchaseEntity.purchaseKey, + userId = purchaseEntity.userId, + totalPrice = purchaseEntity.totalPrice, + purchaseDate = purchaseEntity.purchaseDate, + cancleDate = purchaseEntity.cancleDate, + status = purchaseEntity.status, + ) + } + ) + ) + } + + @Throws(Exception::class) + fun getPurchaseDetail(getPurchaseDetailRequest: GetPurchaseDetailRequest) : GetPurchaseDetailResponse { + return GetPurchaseDetailResponse( + code = ResultCodeMsg.SUCCESS, + msg = ResultCodeMsg.SUCCESS.msg, + result = null, + ) + ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailRequest.kt new file mode 100644 index 0000000..f5581b4 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailRequest.kt @@ -0,0 +1,4 @@ +package com.hanghea99.commerce.api.purchase.domain + +class GetPurchaseDetailRequest { +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResponse.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResponse.kt new file mode 100644 index 0000000..8a4f8a2 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResponse.kt @@ -0,0 +1,15 @@ +package com.hanghea99.commerce.api.purchase.domain + +import com.hanghea99.commerce.api.common.ResultCodeMsg + +data class GetPurchaseDetailResponse( + val code: ResultCodeMsg, + val msg: String, + val result: String? = null, +){ + constructor(resultCodeMsg: ResultCodeMsg, result: Nothing?? = null):this( + code = resultCodeMsg.code, + msg = resultCodeMsg.msg, + result = result, + ) +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResult.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResult.kt new file mode 100644 index 0000000..37bab1d --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResult.kt @@ -0,0 +1,4 @@ +package com.hanghea99.commerce.api.purchase.domain + +class GetPurchaseDetailResult { +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailVo.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailVo.kt new file mode 100644 index 0000000..b883c8d --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailVo.kt @@ -0,0 +1,7 @@ +package com.hanghea99.commerce.api.purchase.domain + +import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo + +data class GetPurchaseDetailVo ( + val purchase: PurchaseVo, +) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt index 5fc655e..ae82be5 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt @@ -18,7 +18,7 @@ data class GetPurchaseRequest ( @PositiveOrZero override val count: Long = 10, - @Pattern(regexp = "LATEST|NAME_ASC|NAME_DESC^$") + @Pattern(regexp = "LATEST|^$") override val sort: String = "LATEST", ):GetRequest(types, values, page, count, sort) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResponse.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResponse.kt index 2b32d54..63d11bb 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResponse.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResponse.kt @@ -5,11 +5,11 @@ import com.hanghea99.commerce.api.common.ResultCodeMsg data class GetPurchaseResponse( val code: String, val msg: String, - val result: Object? = null + val result: GetPurchaseVo, ){ - constructor(resultCodeMsg:ResultCodeMsg):this( + constructor(resultCodeMsg:ResultCodeMsg, result: GetPurchaseVo):this( code = resultCodeMsg.code, msg = resultCodeMsg.msg, - result = null + result = result, ) } \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseVo.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseVo.kt new file mode 100644 index 0000000..a9783db --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseVo.kt @@ -0,0 +1,8 @@ +package com.hanghea99.commerce.api.purchase.domain + +import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo + +data class GetPurchaseVo ( + val totalCount: Long, + val purchases: List, +) \ No newline at end of file From 9983c9ceccd7e3eaf8ef1cdc15ab3359d481c631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=ED=8F=89=EA=B7=BC=5B=ED=94=8C=EB=9E=AB=ED=8F=BC?= =?UTF-8?q?=EA=B0=9C=EB=B0=9C2=ED=8C=80=5D?= Date: Wed, 11 Oct 2023 20:48:23 +0900 Subject: [PATCH 08/19] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EB=8F=99=ED=95=98=EB=8F=84=EB=A1=9D=20Ent?= =?UTF-8?q?ity=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hanghea99/commerce/database/entity/CartEntity.kt | 2 +- .../hanghea99/commerce/database/entity/CartItemEntity.kt | 4 ++-- .../commerce/database/entity/DeliveryAddressEntity.kt | 2 +- .../hanghea99/commerce/database/entity/DeliveryEntity.kt | 3 ++- .../hanghea99/commerce/database/entity/FavoriteEntity.kt | 2 +- .../commerce/database/entity/FavoriteItemEntity.kt | 4 ++-- .../com/hanghea99/commerce/database/entity/PaymentEntity.kt | 2 +- .../hanghea99/commerce/database/entity/PurchaseEntity.kt | 2 +- .../commerce/database/entity/PurchaseItemEntity.kt | 6 +++--- .../database/entity/SellerRequestRegistrationEntity.kt | 2 +- .../com/hanghea99/commerce/database/entity/StoreEntity.kt | 2 +- .../com/hanghea99/commerce/database/entity/UserEntity.kt | 2 +- src/test/resources/application.yml | 2 +- 13 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/com/hanghea99/commerce/database/entity/CartEntity.kt b/src/main/kotlin/com/hanghea99/commerce/database/entity/CartEntity.kt index 0132f35..0019a90 100644 --- a/src/main/kotlin/com/hanghea99/commerce/database/entity/CartEntity.kt +++ b/src/main/kotlin/com/hanghea99/commerce/database/entity/CartEntity.kt @@ -30,7 +30,7 @@ open class CartEntity( @MapsId("userId") @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "USER_ID", nullable = false) + @JoinColumn(name = "USER_ID", nullable = false, foreignKey = ForeignKey(ConstraintMode.NO_CONSTRAINT)) open var userEntity: UserEntity? = userEntity @OneToMany(mappedBy = "cartEntity") diff --git a/src/main/kotlin/com/hanghea99/commerce/database/entity/CartItemEntity.kt b/src/main/kotlin/com/hanghea99/commerce/database/entity/CartItemEntity.kt index a59d2d4..03506ee 100644 --- a/src/main/kotlin/com/hanghea99/commerce/database/entity/CartItemEntity.kt +++ b/src/main/kotlin/com/hanghea99/commerce/database/entity/CartItemEntity.kt @@ -35,11 +35,11 @@ open class CartItemEntity( @MapsId("cartKey") @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "CART_KEY", nullable = false, referencedColumnName = "CART_KEY") + @JoinColumn(name = "CART_KEY", nullable = false, referencedColumnName = "CART_KEY", foreignKey = ForeignKey(ConstraintMode.NO_CONSTRAINT)) open var cartEntity: CartEntity? = cartEntity @MapsId("optionKey") @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "OPTION_KEY", nullable = false, referencedColumnName = "OPTION_KEY") + @JoinColumn(name = "OPTION_KEY", nullable = false, referencedColumnName = "OPTION_KEY", foreignKey = ForeignKey(ConstraintMode.NO_CONSTRAINT)) open var storeItemOptionEntity: StoreItemOptionEntity? = storeItemOptionEntity } \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/entity/DeliveryAddressEntity.kt b/src/main/kotlin/com/hanghea99/commerce/database/entity/DeliveryAddressEntity.kt index 9122f7b..a93d108 100644 --- a/src/main/kotlin/com/hanghea99/commerce/database/entity/DeliveryAddressEntity.kt +++ b/src/main/kotlin/com/hanghea99/commerce/database/entity/DeliveryAddressEntity.kt @@ -37,7 +37,7 @@ open class DeliveryAddressEntity( @MapsId("userId") @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "USER_ID", nullable = false) + @JoinColumn(name = "USER_ID", nullable = false, foreignKey = ForeignKey(ConstraintMode.NO_CONSTRAINT)) open var userEntity: UserEntity? = userEntity @Size(max = 20) diff --git a/src/main/kotlin/com/hanghea99/commerce/database/entity/DeliveryEntity.kt b/src/main/kotlin/com/hanghea99/commerce/database/entity/DeliveryEntity.kt index 27efabb..640b6ed 100644 --- a/src/main/kotlin/com/hanghea99/commerce/database/entity/DeliveryEntity.kt +++ b/src/main/kotlin/com/hanghea99/commerce/database/entity/DeliveryEntity.kt @@ -35,7 +35,8 @@ open class DeliveryEntity( @JoinColumn( name = "PURCHASE_ITEM_KEY", nullable = false, - referencedColumnName = "PURCHASE_ITEM_KEY" + referencedColumnName = "PURCHASE_ITEM_KEY", + foreignKey = ForeignKey(ConstraintMode.NO_CONSTRAINT), ) open var purchaseItemEntity: PurchaseItemEntity? = purchaseItemEntity diff --git a/src/main/kotlin/com/hanghea99/commerce/database/entity/FavoriteEntity.kt b/src/main/kotlin/com/hanghea99/commerce/database/entity/FavoriteEntity.kt index 38fde7d..2cf485b 100644 --- a/src/main/kotlin/com/hanghea99/commerce/database/entity/FavoriteEntity.kt +++ b/src/main/kotlin/com/hanghea99/commerce/database/entity/FavoriteEntity.kt @@ -30,7 +30,7 @@ open class FavoriteEntity( @MapsId("userId") @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "USER_ID", nullable = false) + @JoinColumn(name = "USER_ID", nullable = false, foreignKey = ForeignKey(ConstraintMode.NO_CONSTRAINT)) open var userEntity: UserEntity? = userEntity @OneToMany(mappedBy = "favoriteEntity") diff --git a/src/main/kotlin/com/hanghea99/commerce/database/entity/FavoriteItemEntity.kt b/src/main/kotlin/com/hanghea99/commerce/database/entity/FavoriteItemEntity.kt index f35c21b..25f9a44 100644 --- a/src/main/kotlin/com/hanghea99/commerce/database/entity/FavoriteItemEntity.kt +++ b/src/main/kotlin/com/hanghea99/commerce/database/entity/FavoriteItemEntity.kt @@ -35,11 +35,11 @@ open class FavoriteItemEntity( @MapsId("itemKey") @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "ITEM_KEY", nullable = false, referencedColumnName = "ITEM_KEY") + @JoinColumn(name = "ITEM_KEY", nullable = false, referencedColumnName = "ITEM_KEY", foreignKey = ForeignKey(ConstraintMode.NO_CONSTRAINT)) open var storeItemEntity: StoreItemEntity? = storeItemEntity @MapsId("favoriteKey") @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "FAVORITE_KEY", nullable = false, referencedColumnName = "FAVORITE_KEY") + @JoinColumn(name = "FAVORITE_KEY", nullable = false, referencedColumnName = "FAVORITE_KEY", foreignKey = ForeignKey(ConstraintMode.NO_CONSTRAINT)) open var favoriteEntity: FavoriteEntity? = favoriteEntity } \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/entity/PaymentEntity.kt b/src/main/kotlin/com/hanghea99/commerce/database/entity/PaymentEntity.kt index 2b10cfc..cea5f4a 100644 --- a/src/main/kotlin/com/hanghea99/commerce/database/entity/PaymentEntity.kt +++ b/src/main/kotlin/com/hanghea99/commerce/database/entity/PaymentEntity.kt @@ -31,7 +31,7 @@ open class PaymentEntity( @MapsId("purchaseKey") @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "PURCHASE_KEY", nullable = false, referencedColumnName = "PURCHASE_KEY") + @JoinColumn(name = "PURCHASE_KEY", nullable = false, referencedColumnName = "PURCHASE_KEY", foreignKey = ForeignKey(ConstraintMode.NO_CONSTRAINT)) open var purchaseEntity: PurchaseEntity? = purchaseEntity @Size(max = 20) diff --git a/src/main/kotlin/com/hanghea99/commerce/database/entity/PurchaseEntity.kt b/src/main/kotlin/com/hanghea99/commerce/database/entity/PurchaseEntity.kt index 5f25706..287aa53 100644 --- a/src/main/kotlin/com/hanghea99/commerce/database/entity/PurchaseEntity.kt +++ b/src/main/kotlin/com/hanghea99/commerce/database/entity/PurchaseEntity.kt @@ -38,7 +38,7 @@ open class PurchaseEntity( @MapsId("userId") @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "USER_ID", nullable = false) + @JoinColumn(name = "USER_ID", nullable = false, foreignKey = ForeignKey(ConstraintMode.NO_CONSTRAINT)) open var userEntity: UserEntity? = userEntity @Column(name = "TOTAL_PRICE", precision = 20, scale = 2) diff --git a/src/main/kotlin/com/hanghea99/commerce/database/entity/PurchaseItemEntity.kt b/src/main/kotlin/com/hanghea99/commerce/database/entity/PurchaseItemEntity.kt index 0f6c53d..d74c87c 100644 --- a/src/main/kotlin/com/hanghea99/commerce/database/entity/PurchaseItemEntity.kt +++ b/src/main/kotlin/com/hanghea99/commerce/database/entity/PurchaseItemEntity.kt @@ -42,17 +42,17 @@ open class PurchaseItemEntity( @MapsId("reviewId") @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "REVIEW_ID", nullable = false) + @JoinColumn(name = "REVIEW_ID", nullable = false, foreignKey = ForeignKey(ConstraintMode.NO_CONSTRAINT)) open var reviewEntity: ReviewEntity? = reviewEntity @MapsId("purchaseKey") @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "PURCHASE_KEY", nullable = false, referencedColumnName = "PURCHASE_KEY") + @JoinColumn(name = "PURCHASE_KEY", nullable = false, referencedColumnName = "PURCHASE_KEY", foreignKey = ForeignKey(ConstraintMode.NO_CONSTRAINT)) open var purchaseEntity: PurchaseEntity? = purchaseEntity @MapsId("optionKey") @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "OPTION_KEY", nullable = false, referencedColumnName = "OPTION_KEY") + @JoinColumn(name = "OPTION_KEY", nullable = false, referencedColumnName = "OPTION_KEY", foreignKey = ForeignKey(ConstraintMode.NO_CONSTRAINT)) open var storeItemoptionEntity: StoreItemOptionEntity? = storeItemoptionEntity @OneToMany(mappedBy = "purchaseItemEntity") diff --git a/src/main/kotlin/com/hanghea99/commerce/database/entity/SellerRequestRegistrationEntity.kt b/src/main/kotlin/com/hanghea99/commerce/database/entity/SellerRequestRegistrationEntity.kt index 1426304..689f767 100644 --- a/src/main/kotlin/com/hanghea99/commerce/database/entity/SellerRequestRegistrationEntity.kt +++ b/src/main/kotlin/com/hanghea99/commerce/database/entity/SellerRequestRegistrationEntity.kt @@ -35,7 +35,7 @@ open class SellerRequestRegistrationEntity( @MapsId("sellerId") @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "SELLER_ID", nullable = false) + @JoinColumn(name = "SELLER_ID", nullable = false, foreignKey = ForeignKey(ConstraintMode.NO_CONSTRAINT)) open var sellerEntity: SellerEntity? = sellerEntity @Size(max = 10) diff --git a/src/main/kotlin/com/hanghea99/commerce/database/entity/StoreEntity.kt b/src/main/kotlin/com/hanghea99/commerce/database/entity/StoreEntity.kt index 4faa4b2..ae5bf33 100644 --- a/src/main/kotlin/com/hanghea99/commerce/database/entity/StoreEntity.kt +++ b/src/main/kotlin/com/hanghea99/commerce/database/entity/StoreEntity.kt @@ -52,7 +52,7 @@ open class StoreEntity( @MapsId("sellerId") @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "SELLER_ID", nullable = false) + @JoinColumn(name = "SELLER_ID", nullable = false, foreignKey = ForeignKey(ConstraintMode.NO_CONSTRAINT)) open var sellerEntity: SellerEntity? = sellerEntity @Size(max = 10) diff --git a/src/main/kotlin/com/hanghea99/commerce/database/entity/UserEntity.kt b/src/main/kotlin/com/hanghea99/commerce/database/entity/UserEntity.kt index 2c7dd9a..fb512be 100644 --- a/src/main/kotlin/com/hanghea99/commerce/database/entity/UserEntity.kt +++ b/src/main/kotlin/com/hanghea99/commerce/database/entity/UserEntity.kt @@ -7,7 +7,7 @@ import org.hibernate.annotations.UpdateTimestamp import java.time.Instant @Entity -@Table(name = "USER") +@Table(name = "`USER`") open class UserEntity( id: Long? = null, email: Long? = null, diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index e0fd717..98cccc0 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -6,7 +6,7 @@ spring: jpa: hibernate: default_batch_fetch_size: 500 - ddl-auto: update + ddl-auto: create open-in-view: false properties: hibernate.jdbc.batch_size: 100 From bb39fa352ddf487d98a50e2f878c8aac8ade2d7c Mon Sep 17 00:00:00 2001 From: ujoo0408 Date: Wed, 11 Oct 2023 22:51:42 +0900 Subject: [PATCH 09/19] first commit --- .../Manager/Domain/PostManagerLoginRequest.kt | 8 +++ .../Domain/PostManagerSellerPermitRequest.kt | 9 +++ .../api/common/comp/impl/ManagerManager.kt | 24 +++++++ .../api/common/comp/impl/ManagerReader.kt | 65 +++++++++++++++++++ .../api/common/comp/impl/SellerManager.kt | 23 +++++++ .../api/common/comp/impl/SellerReader.kt | 63 ++++++++++++++++++ .../api/common/domain/seller/SellerVo.kt | 25 +++++++ .../repository/FavoriteItemRepository.kt | 8 --- .../database/repository/FavoriteRepository.kt | 8 --- .../database/repository/ManagerRepository.kt | 8 --- .../database/repository/PaymentRepository.kt | 8 --- .../repository/PurchaseItemRepository.kt | 8 --- .../database/repository/PurchaseRepository.kt | 8 --- .../database/repository/ReviewRepository.kt | 8 --- .../database/repository/SellerRepository.kt | 8 --- .../SellerRequestRegistrationRepository.kt | 9 --- .../repository/StoreItemOptionRepository.kt | 8 --- .../repository/StoreItemRepository.kt | 8 --- .../database/repository/StoreRepository.kt | 8 --- .../database/repository/UserRepository.kt | 8 --- 20 files changed, 217 insertions(+), 105 deletions(-) create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/Manager/Domain/PostManagerLoginRequest.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/Manager/Domain/PostManagerSellerPermitRequest.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/ManagerManager.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/ManagerReader.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/SellerManager.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/SellerReader.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/api/common/domain/seller/SellerVo.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/FavoriteItemRepository.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/FavoriteRepository.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/ManagerRepository.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/PaymentRepository.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/PurchaseItemRepository.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/PurchaseRepository.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/ReviewRepository.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/SellerRepository.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/SellerRequestRegistrationRepository.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/StoreItemOptionRepository.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/StoreItemRepository.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/StoreRepository.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/UserRepository.kt diff --git a/src/main/kotlin/com/hanghea99/commerce/api/Manager/Domain/PostManagerLoginRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/Manager/Domain/PostManagerLoginRequest.kt new file mode 100644 index 0000000..945b9de --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/Manager/Domain/PostManagerLoginRequest.kt @@ -0,0 +1,8 @@ +package com.hanghea99.commerce.api.manager.domain + +import com.hanghea99.commerce.api.common.domain.core.CoreRequest + +data class PostManagerLoginRequest( + val id: String, + val password: String +) : CoreRequest() \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/Manager/Domain/PostManagerSellerPermitRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/Manager/Domain/PostManagerSellerPermitRequest.kt new file mode 100644 index 0000000..3efea33 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/Manager/Domain/PostManagerSellerPermitRequest.kt @@ -0,0 +1,9 @@ +package com.hanghea99.commerce.api.manager.domain + +import com.hanghea99.commerce.api.common.domain.core.CoreRequest +import com.hanghea99.commerce.api.common.domain.seller.SellerVo + +data class PostManagerSellerPermitRequest ( + val sellers: List +): CoreRequest() + diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/ManagerManager.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/ManagerManager.kt new file mode 100644 index 0000000..d0048b3 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/ManagerManager.kt @@ -0,0 +1,24 @@ +package com.hanghea99.commerce.api.common.comp.impl + +import com.hanghea99.commerce.api.common.comp.ManagerComponent +import com.hanghea99.commerce.database.entity.ManagerEntity +import com.hanghea99.commerce.database.entity.StoreEntity +import com.hanghea99.commerce.database.repository.ManagerRepository +import com.hanghea99.commerce.database.repository.StoreRepository +import org.springframework.stereotype.Component + +@Component +class ManagerManager(var managerRepository: ManagerRepository) : ManagerComponent() { + override fun update(entities: List): Long { + return managerRepository.saveAllAndFlush(entities).count().toLong() + } + + override fun delete(entityIds: List) { + managerRepository.deleteAllById(entityIds) + } + + override fun create(entities: List): List { + return managerRepository.saveAllAndFlush(entities) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/ManagerReader.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/ManagerReader.kt new file mode 100644 index 0000000..56f3b7f --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/ManagerReader.kt @@ -0,0 +1,65 @@ +package com.hanghea99.commerce.api.common.comp.impl + +import com.hanghea99.commerce.api.common.comp.ReaderComponent +import com.hanghea99.commerce.database.entity.ManagerEntity +import com.hanghea99.commerce.database.repository.ManagerRepository +import com.querydsl.core.BooleanBuilder +import com.querydsl.core.types.OrderSpecifier +import com.querydsl.jpa.impl.JPAQueryFactory +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Component + +@Component +class ManagerReader( + val managerRepository: ManagerRepository, + val jpaQueryFactory: JPAQueryFactory, +) : + ReaderComponent( + ) { + private val log = LoggerFactory.getLogger("StoreReader") + + val qManagerEntity: QManagerEntity = QManagerEntity("m1") + + override fun read(id: String): ManagerEntity { + TODO("Not yet implemented") + } + + override fun readAll(ids: List): List { + TODO("Not yet implemented") + } + + override fun readAllCount(ids: List): Long { + TODO("Not yet implemented") + } + + override fun read(where: BooleanBuilder): ManagerEntity? { + val orders: MutableList> = mutableListOf() + return jpaQueryFactory.selectFrom(qManagerEntity) + .where(where) + .fetchFirst() + } + + override fun readAll( + where: BooleanBuilder, + offset: Long, + count: Long, + orders: MutableList>, + ): List { + val orders: MutableList> = mutableListOf() + return jpaQueryFactory.selectFrom(qManagerEntity) + .where(where) + .orderBy(*orders.toTypedArray()) + .offset(offset) + .limit(count) + .fetch() + } + + override fun readAllCount( + where: BooleanBuilder, + ): Long { + return jpaQueryFactory.selectFrom(qManagerEntity) + .where(where) + .fetchCount() + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/SellerManager.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/SellerManager.kt new file mode 100644 index 0000000..cbcf663 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/SellerManager.kt @@ -0,0 +1,23 @@ +package com.hanghea99.commerce.api.common.comp.impl + +import com.hanghea99.commerce.api.common.comp.ManagerComponent +import com.hanghea99.commerce.database.entity.SellerEntity +import com.hanghea99.commerce.database.repository.SellerRepository +import org.springframework.stereotype.Component + +@Component +class SellerManager(var sellerRepository: SellerRepository) : + ManagerComponent() { + override fun update(entities: List): Long { + return sellerRepository.saveAllAndFlush(entities).count().toLong() + } + + override fun delete(entityIds: List) { + sellerRepository.deleteAllById(entityIds) + } + + override fun create(entities: List): List { + return sellerRepository.saveAllAndFlush(entities) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/SellerReader.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/SellerReader.kt new file mode 100644 index 0000000..a2dd40e --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/SellerReader.kt @@ -0,0 +1,63 @@ +package com.hanghea99.commerce.api.common.comp.impl + +import com.hanghea99.commerce.api.common.comp.ReaderComponent +import com.hanghea99.commerce.database.entity.QSellerEntity +import com.hanghea99.commerce.database.entity.SellerEntity +import com.hanghea99.commerce.database.repository.SellerRepository +import com.querydsl.core.BooleanBuilder +import com.querydsl.core.types.OrderSpecifier +import com.querydsl.jpa.impl.JPAQueryFactory +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Component + +@Component +class SellerReader( + val selerRepository: SellerRepository, + val jpaQueryFactory: JPAQueryFactory, +) : + ReaderComponent( + ) { + private val log = LoggerFactory.getLogger("StoreReader") + + val qSellerEntity: QSellerEntity = QSellerEntity("m1") + + override fun read(id: Long): SellerEntity { + TODO("Not yet implemented") + } + + override fun readAll(ids: List): List { + TODO("Not yet implemented") + } + + override fun readAllCount(ids: List): Long { + TODO("Not yet implemented") + } + + override fun read(where: BooleanBuilder): SellerEntity { + TODO("Not yet implemented") + } + + override fun readAll( + where: BooleanBuilder, + offset: Long, + count: Long, + orders: MutableList>, + ): List { + val orders: MutableList> = mutableListOf() + return jpaQueryFactory.selectFrom(qSellerEntity) + .where(where) + .orderBy(*orders.toTypedArray()) + .offset(offset) + .limit(count) + .fetch() + } + + override fun readAllCount( + where: BooleanBuilder, + ): Long { + return jpaQueryFactory.selectFrom(qSellerEntity) + .where(where) + .fetchCount() + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/domain/seller/SellerVo.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/domain/seller/SellerVo.kt new file mode 100644 index 0000000..8e8a3af --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/domain/seller/SellerVo.kt @@ -0,0 +1,25 @@ +package com.hanghea99.commerce.api.common.domain.seller + +import java.time.Instant + +data class SellerVo( + var sellerId: String?, + var status: String?, + var password: String?, + var name: String?, + var ssn: String?, + var telecomName: String?, + var phoneNumber: String?, + var companyName: String?, + var businessRegestraionNumber: String?, + var representativeName: String?, + var representativeTelephoneNumber: String?, + var faxNumber: String?, + var businessZipCode: String?, + var businiessAddress: String?, + var createdAt: Instant?, + var updatedAt: Instant?, + var deletedAt: Instant?, + var allowedAt: Instant?, + var blockedAt: Instant?, +) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/FavoriteItemRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/FavoriteItemRepository.kt deleted file mode 100644 index b441a62..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/database/repository/FavoriteItemRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.hanghea99.commerce.database.repository - -import com.hanghea99.commerce.database.entity.FavoriteItemEntity -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.JpaSpecificationExecutor - -interface FavoriteItemRepository : JpaRepository, - JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/FavoriteRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/FavoriteRepository.kt deleted file mode 100644 index 2600641..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/database/repository/FavoriteRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.hanghea99.commerce.database.repository - -import com.hanghea99.commerce.database.entity.FavoriteEntity -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.JpaSpecificationExecutor - -interface FavoriteRepository : JpaRepository, - JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/ManagerRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/ManagerRepository.kt deleted file mode 100644 index 1d2ddcd..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/database/repository/ManagerRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.hanghea99.commerce.database.repository - -import com.hanghea99.commerce.database.entity.ManagerEntity -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.JpaSpecificationExecutor - -interface ManagerRepository : JpaRepository, - JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/PaymentRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/PaymentRepository.kt deleted file mode 100644 index 32cdcae..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/database/repository/PaymentRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.hanghea99.commerce.database.repository - -import com.hanghea99.commerce.database.entity.PaymentEntity -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.JpaSpecificationExecutor - -interface PaymentRepository : JpaRepository, - JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/PurchaseItemRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/PurchaseItemRepository.kt deleted file mode 100644 index 79b816a..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/database/repository/PurchaseItemRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.hanghea99.commerce.database.repository - -import com.hanghea99.commerce.database.entity.PurchaseItemEntity -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.JpaSpecificationExecutor - -interface PurchaseItemRepository : JpaRepository, - JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/PurchaseRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/PurchaseRepository.kt deleted file mode 100644 index 8723dbf..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/database/repository/PurchaseRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.hanghea99.commerce.database.repository - -import com.hanghea99.commerce.database.entity.PurchaseEntity -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.JpaSpecificationExecutor - -interface PurchaseRepository : JpaRepository, - JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/ReviewRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/ReviewRepository.kt deleted file mode 100644 index 1beea92..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/database/repository/ReviewRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.hanghea99.commerce.database.repository - -import com.hanghea99.commerce.database.entity.ReviewEntity -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.JpaSpecificationExecutor - -interface ReviewRepository : JpaRepository, - JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/SellerRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/SellerRepository.kt deleted file mode 100644 index eed357b..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/database/repository/SellerRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.hanghea99.commerce.database.repository - -import com.hanghea99.commerce.database.entity.SellerEntity -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.JpaSpecificationExecutor - -interface SellerRepository : JpaRepository, - JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/SellerRequestRegistrationRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/SellerRequestRegistrationRepository.kt deleted file mode 100644 index 3375e04..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/database/repository/SellerRequestRegistrationRepository.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.hanghea99.commerce.database.repository - -import com.hanghea99.commerce.database.entity.SellerRequestRegistrationEntity -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.JpaSpecificationExecutor - -interface SellerRequestRegistrationRepository : - JpaRepository, - JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreItemOptionRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreItemOptionRepository.kt deleted file mode 100644 index 0389f02..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreItemOptionRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.hanghea99.commerce.database.repository - -import com.hanghea99.commerce.database.entity.StoreItemOptionEntity -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.JpaSpecificationExecutor - -interface StoreItemOptionRepository : JpaRepository, - JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreItemRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreItemRepository.kt deleted file mode 100644 index a85d8fc..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreItemRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.hanghea99.commerce.database.repository - -import com.hanghea99.commerce.database.entity.StoreItemEntity -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.JpaSpecificationExecutor - -interface StoreItemRepository : JpaRepository, - JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreRepository.kt deleted file mode 100644 index 0c34438..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.hanghea99.commerce.database.repository - -import com.hanghea99.commerce.database.entity.StoreEntity -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.JpaSpecificationExecutor - -interface StoreRepository : JpaRepository, - JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/UserRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/UserRepository.kt deleted file mode 100644 index 2c8b236..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/database/repository/UserRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.hanghea99.commerce.database.repository - -import com.hanghea99.commerce.database.entity.UserEntity -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.JpaSpecificationExecutor - -interface UserRepository : JpaRepository, - JpaSpecificationExecutor \ No newline at end of file From f426849938cd54d6940e9154e890be6f929b1799 Mon Sep 17 00:00:00 2001 From: ujoo0408 Date: Thu, 12 Oct 2023 00:00:43 +0900 Subject: [PATCH 10/19] seceond --- .../commerce/api/common/comp/impl/ManagerReader.kt | 1 + .../commerce/api/common/domain/seller/SellerVo.kt | 2 +- .../database/repository/FavoriteItemRepository.kt | 8 ++++++++ .../commerce/database/repository/FavoriteRepository.kt | 8 ++++++++ .../commerce/database/repository/ManagerRepository.kt | 8 ++++++++ .../commerce/database/repository/PaymentRepository.kt | 8 ++++++++ .../database/repository/PurchaseItemRepository.kt | 8 ++++++++ .../commerce/database/repository/PurchaseRepository.kt | 8 ++++++++ .../commerce/database/repository/ReviewRepository.kt | 8 ++++++++ .../commerce/database/repository/SellerRepository.kt | 8 ++++++++ .../repository/SellerRequestRegistrationRepository.kt | 9 +++++++++ .../database/repository/StoreItemOptionRepository.kt | 8 ++++++++ .../commerce/database/repository/StoreItemRepository.kt | 8 ++++++++ .../commerce/database/repository/StoreRepository.kt | 8 ++++++++ .../commerce/database/repository/UserRepository.kt | 8 ++++++++ 15 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/FavoriteItemRepository.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/FavoriteRepository.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/ManagerRepository.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/PaymentRepository.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/PurchaseItemRepository.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/PurchaseRepository.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/ReviewRepository.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/SellerRepository.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/SellerRequestRegistrationRepository.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/StoreItemOptionRepository.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/StoreItemRepository.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/StoreRepository.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/database/repository/UserRepository.kt diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/ManagerReader.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/ManagerReader.kt index 56f3b7f..6a0a7f8 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/ManagerReader.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/ManagerReader.kt @@ -2,6 +2,7 @@ package com.hanghea99.commerce.api.common.comp.impl import com.hanghea99.commerce.api.common.comp.ReaderComponent import com.hanghea99.commerce.database.entity.ManagerEntity +import com.hanghea99.commerce.database.entity.QManagerEntity import com.hanghea99.commerce.database.repository.ManagerRepository import com.querydsl.core.BooleanBuilder import com.querydsl.core.types.OrderSpecifier diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/domain/seller/SellerVo.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/domain/seller/SellerVo.kt index 8e8a3af..4f78caa 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/common/domain/seller/SellerVo.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/domain/seller/SellerVo.kt @@ -22,4 +22,4 @@ data class SellerVo( var deletedAt: Instant?, var allowedAt: Instant?, var blockedAt: Instant?, -) \ No newline at end of file +) diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/FavoriteItemRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/FavoriteItemRepository.kt new file mode 100644 index 0000000..b441a62 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/database/repository/FavoriteItemRepository.kt @@ -0,0 +1,8 @@ +package com.hanghea99.commerce.database.repository + +import com.hanghea99.commerce.database.entity.FavoriteItemEntity +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.JpaSpecificationExecutor + +interface FavoriteItemRepository : JpaRepository, + JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/FavoriteRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/FavoriteRepository.kt new file mode 100644 index 0000000..2600641 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/database/repository/FavoriteRepository.kt @@ -0,0 +1,8 @@ +package com.hanghea99.commerce.database.repository + +import com.hanghea99.commerce.database.entity.FavoriteEntity +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.JpaSpecificationExecutor + +interface FavoriteRepository : JpaRepository, + JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/ManagerRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/ManagerRepository.kt new file mode 100644 index 0000000..1d2ddcd --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/database/repository/ManagerRepository.kt @@ -0,0 +1,8 @@ +package com.hanghea99.commerce.database.repository + +import com.hanghea99.commerce.database.entity.ManagerEntity +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.JpaSpecificationExecutor + +interface ManagerRepository : JpaRepository, + JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/PaymentRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/PaymentRepository.kt new file mode 100644 index 0000000..32cdcae --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/database/repository/PaymentRepository.kt @@ -0,0 +1,8 @@ +package com.hanghea99.commerce.database.repository + +import com.hanghea99.commerce.database.entity.PaymentEntity +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.JpaSpecificationExecutor + +interface PaymentRepository : JpaRepository, + JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/PurchaseItemRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/PurchaseItemRepository.kt new file mode 100644 index 0000000..79b816a --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/database/repository/PurchaseItemRepository.kt @@ -0,0 +1,8 @@ +package com.hanghea99.commerce.database.repository + +import com.hanghea99.commerce.database.entity.PurchaseItemEntity +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.JpaSpecificationExecutor + +interface PurchaseItemRepository : JpaRepository, + JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/PurchaseRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/PurchaseRepository.kt new file mode 100644 index 0000000..8723dbf --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/database/repository/PurchaseRepository.kt @@ -0,0 +1,8 @@ +package com.hanghea99.commerce.database.repository + +import com.hanghea99.commerce.database.entity.PurchaseEntity +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.JpaSpecificationExecutor + +interface PurchaseRepository : JpaRepository, + JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/ReviewRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/ReviewRepository.kt new file mode 100644 index 0000000..1beea92 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/database/repository/ReviewRepository.kt @@ -0,0 +1,8 @@ +package com.hanghea99.commerce.database.repository + +import com.hanghea99.commerce.database.entity.ReviewEntity +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.JpaSpecificationExecutor + +interface ReviewRepository : JpaRepository, + JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/SellerRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/SellerRepository.kt new file mode 100644 index 0000000..eed357b --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/database/repository/SellerRepository.kt @@ -0,0 +1,8 @@ +package com.hanghea99.commerce.database.repository + +import com.hanghea99.commerce.database.entity.SellerEntity +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.JpaSpecificationExecutor + +interface SellerRepository : JpaRepository, + JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/SellerRequestRegistrationRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/SellerRequestRegistrationRepository.kt new file mode 100644 index 0000000..3375e04 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/database/repository/SellerRequestRegistrationRepository.kt @@ -0,0 +1,9 @@ +package com.hanghea99.commerce.database.repository + +import com.hanghea99.commerce.database.entity.SellerRequestRegistrationEntity +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.JpaSpecificationExecutor + +interface SellerRequestRegistrationRepository : + JpaRepository, + JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreItemOptionRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreItemOptionRepository.kt new file mode 100644 index 0000000..0389f02 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreItemOptionRepository.kt @@ -0,0 +1,8 @@ +package com.hanghea99.commerce.database.repository + +import com.hanghea99.commerce.database.entity.StoreItemOptionEntity +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.JpaSpecificationExecutor + +interface StoreItemOptionRepository : JpaRepository, + JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreItemRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreItemRepository.kt new file mode 100644 index 0000000..a85d8fc --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreItemRepository.kt @@ -0,0 +1,8 @@ +package com.hanghea99.commerce.database.repository + +import com.hanghea99.commerce.database.entity.StoreItemEntity +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.JpaSpecificationExecutor + +interface StoreItemRepository : JpaRepository, + JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreRepository.kt new file mode 100644 index 0000000..0c34438 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/database/repository/StoreRepository.kt @@ -0,0 +1,8 @@ +package com.hanghea99.commerce.database.repository + +import com.hanghea99.commerce.database.entity.StoreEntity +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.JpaSpecificationExecutor + +interface StoreRepository : JpaRepository, + JpaSpecificationExecutor \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/database/repository/UserRepository.kt b/src/main/kotlin/com/hanghea99/commerce/database/repository/UserRepository.kt new file mode 100644 index 0000000..2c8b236 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/database/repository/UserRepository.kt @@ -0,0 +1,8 @@ +package com.hanghea99.commerce.database.repository + +import com.hanghea99.commerce.database.entity.UserEntity +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.JpaSpecificationExecutor + +interface UserRepository : JpaRepository, + JpaSpecificationExecutor \ No newline at end of file From f6b5cbef059a41b2d92fe8c531bdc8724f7caabd Mon Sep 17 00:00:00 2001 From: imdaebeen Date: Thu, 12 Oct 2023 00:16:52 +0900 Subject: [PATCH 11/19] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 4 +-- .../api/common/comp/impl/PurchaseReader.kt | 11 +++++- .../api/common/domain/purchase/PurchaseVo.kt | 8 ++--- .../api/purchase/PurchaseController.kt | 21 ++++------- .../commerce/api/purchase/PurchaseService.kt | 22 ++++++------ .../domain/GetPurchaseDetailResponse.kt | 6 ++-- .../api/purchase/PurchaseControllerTest.kt | 36 +++++++++++++++++++ 7 files changed, 73 insertions(+), 35 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 47d45a6..fc60a1f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -45,8 +45,8 @@ dependencies { implementation("com.querydsl:querydsl-jpa:5.0.0:jakarta") implementation("com.querydsl:querydsl-core:5.0.0") -// kapt("com.querydsl:querydsl-apt:5.0.0:jakarta") -// kapt("com.querydsl:querydsl-kotlin-codegen:5.0.0") + kapt("com.querydsl:querydsl-apt:5.0.0:jakarta") + kapt("com.querydsl:querydsl-kotlin-codegen:5.0.0") implementation("net.ttddyy:datasource-proxy:1.9") diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseReader.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseReader.kt index f8649dc..7c61e8e 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseReader.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseReader.kt @@ -2,6 +2,7 @@ package com.hanghea99.commerce.api.common.comp.impl import com.hanghea99.commerce.api.common.comp.ReaderComponent import com.hanghea99.commerce.database.entity.PurchaseEntity +import com.hanghea99.commerce.database.entity.QPurchaseEntity import com.hanghea99.commerce.database.repository.PurchaseRepository import com.querydsl.core.BooleanBuilder @@ -18,6 +19,8 @@ class PurchaseReader ( ) { private val log = LoggerFactory.getLogger("PurchaseReader") + val qPurchaseEntity: QPurchaseEntity = QPurchaseEntity("s1") + override fun read(id: Long): PurchaseEntity { TODO("Not yet implemented") } @@ -36,7 +39,13 @@ class PurchaseReader ( count: Long, orders: MutableList> ): List { - TODO("Not yet implemented") + val orders: MutableList> = mutableListOf() + return jpaQueryFactory.selectFrom(qPurchaseEntity) + .where(where) + .orderBy(*orders.toTypedArray()) + .offset(offset) + .limit(count) + .fetch() } override fun readAllCount(ids: List): Long { diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/domain/purchase/PurchaseVo.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/domain/purchase/PurchaseVo.kt index 1df05e3..4bcccc6 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/common/domain/purchase/PurchaseVo.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/domain/purchase/PurchaseVo.kt @@ -6,8 +6,8 @@ import java.time.Instant data class PurchaseVo ( var purchaseKey: Long? = null, var userId: Long? = null, - var totalPrice: BigDecimal, - var purchaseDate: Instant, - var cancleDate: Instant, - var status: String, + var totalPrice: BigDecimal? =null, + var purchaseDate: Instant? = null, + var cancleDate: Instant? = null, + var status: String? = null, ) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt index 9347f7e..b302690 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt @@ -1,21 +1,14 @@ package com.hanghea99.commerce.api.purchase -import com.hanghea99.commerce.api.purchase.domain.GetPurchaseDetailRequest -import com.hanghea99.commerce.api.purchase.domain.GetPurchaseRequest -import com.hanghea99.commerce.api.purchase.domain.GetPurchaseResponse +import com.hanghea99.commerce.api.purchase.domain.* import com.hanghea99.commerce.logger -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController - +import org.springframework.web.bind.annotation.* @RestController @RequestMapping("/api/purchase") class PurchaseController(val purchaseService: PurchaseService) { private val log = logger() - /** * API명 : PURCHASE_004 * API용도 : 주문 전체 조회 @@ -34,9 +27,9 @@ class PurchaseController(val purchaseService: PurchaseService) { * @param GetPurchaseDetailRequest * @return GetPurchaseDetailResponse */ - @GetMapping("/purchase-id") - @Throws(Exception::class) - fun getPurchaseDetail(getPurchaseDetailRequest: GetPurchaseDetailRequest) : GetPurchaseResponse { - return purchaseService.getPurchaseDetail(getPurchaseDetailRequest) - } +// @GetMapping("/purchase-id") +// @Throws(Exception::class) +// fun getPurchaseDetail(getPurchaseDetailRequest: GetPurchaseDetailRequest) : GetPurchaseDetailResponse { +// return purchaseService.getPurchaseDetail(getPurchaseDetailRequest) +// } } \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt index e3ca416..6535942 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt @@ -6,6 +6,7 @@ import com.hanghea99.commerce.api.common.comp.impl.PurchaseReader import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo import com.hanghea99.commerce.api.purchase.domain.* import com.hanghea99.commerce.database.entity.PurchaseEntity +import com.hanghea99.commerce.database.entity.QPurchaseEntity import com.hanghea99.commerce.logger import com.querydsl.core.BooleanBuilder import org.springframework.stereotype.Service @@ -26,8 +27,6 @@ class PurchaseService( fun getPurchase(getPurchaseRequest: GetPurchaseRequest): GetPurchaseResponse{ val booleanBuilder = BooleanBuilder() - booleanBuilder.and(qPurchaseEntity.deletedAt.isNull) - val result = purchaseReader.readAll( booleanBuilder, offset = if (getPurchaseRequest.page > 0) getPurchaseRequest.page * getPurchaseRequest.count else 0, @@ -57,13 +56,14 @@ class PurchaseService( ) } - @Throws(Exception::class) - fun getPurchaseDetail(getPurchaseDetailRequest: GetPurchaseDetailRequest) : GetPurchaseDetailResponse { - return GetPurchaseDetailResponse( - code = ResultCodeMsg.SUCCESS, - msg = ResultCodeMsg.SUCCESS.msg, - result = null, - ) - ) - } +// @Throws(Exception::class) +// fun getPurchaseDetail(getPurchaseDetailRequest: GetPurchaseDetailRequest) : GetPurchaseDetailResponse { +// return GetPurchaseDetailResponse( +// code = ResultCodeMsg.SUCCESS.code, +// msg = ResultCodeMsg.SUCCESS.msg, +// result = GetPurchaseVo( +// purchase = +// ) +// ) +// } } \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResponse.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResponse.kt index 8a4f8a2..cead28c 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResponse.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResponse.kt @@ -3,11 +3,11 @@ package com.hanghea99.commerce.api.purchase.domain import com.hanghea99.commerce.api.common.ResultCodeMsg data class GetPurchaseDetailResponse( - val code: ResultCodeMsg, + val code: String, val msg: String, - val result: String? = null, + val result: GetPurchaseDetailVo, ){ - constructor(resultCodeMsg: ResultCodeMsg, result: Nothing?? = null):this( + constructor(resultCodeMsg: ResultCodeMsg, result: GetPurchaseDetailVo):this( code = resultCodeMsg.code, msg = resultCodeMsg.msg, result = result, diff --git a/src/test/kotlin/com/hanghea99/commerce/api/purchase/PurchaseControllerTest.kt b/src/test/kotlin/com/hanghea99/commerce/api/purchase/PurchaseControllerTest.kt index d8af5a1..aecae4f 100644 --- a/src/test/kotlin/com/hanghea99/commerce/api/purchase/PurchaseControllerTest.kt +++ b/src/test/kotlin/com/hanghea99/commerce/api/purchase/PurchaseControllerTest.kt @@ -1,15 +1,51 @@ package com.hanghea99.commerce.api.purchase +import com.fasterxml.jackson.databind.ObjectMapper import org.junit.jupiter.api.Test import org.junit.jupiter.api.Assertions.* +import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest +import org.springframework.boot.test.mock.mockito.MockBean +import org.springframework.test.web.servlet.MockMvc +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get +import org.springframework.test.web.servlet.result.MockMvcResultHandlers +import org.springframework.test.web.servlet.result.MockMvcResultMatchers +import org.springframework.util.LinkedMultiValueMap @WebMvcTest(PurchaseController::class) class PurchaseControllerTest { + @Autowired + lateinit var mockMvc: MockMvc + + @Autowired + lateinit var objectMapper: ObjectMapper + + @MockBean + lateinit var purchaseService: PurchaseService + @Test fun getPurchase() { + + //GIVEN + val queryParams = LinkedMultiValueMap() + + queryParams.add("types", "NAME") + queryParams.add("values", "테스트") + queryParams.add("page", "1") + queryParams.add("count", "10") + queryParams.add("sort", "LATEST") + + //WHEN //THEN + mockMvc.perform( + get("/api/purchase") + .queryParams(queryParams) + ).andExpectAll( + MockMvcResultMatchers.status().isOk + ).andDo( + MockMvcResultHandlers.print() + ) } @Test From d827932be8745a492d63b541fdee54620c2ab9e1 Mon Sep 17 00:00:00 2001 From: "HKMC\\H2211843" <9417143@ict-companion.com> Date: Thu, 12 Oct 2023 17:13:28 +0900 Subject: [PATCH 12/19] =?UTF-8?q?=EC=A3=BC=EB=AC=B8=EC=9A=94=EC=B2=AD,=20?= =?UTF-8?q?=EC=A3=BC=EB=AC=B8=EC=88=98=EC=A0=95,=20=EC=A3=BC=EB=AC=B8?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EC=9E=91=EC=84=B1=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/common/comp/impl/PurchaseManager.kt | 4 +- .../api/purchase/PurchaseController.kt | 38 +++++++++++ .../commerce/api/purchase/PurchaseService.kt | 68 +++++++++++++++++++ 3 files changed, 108 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt index b6682c4..7bcf759 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt @@ -11,11 +11,11 @@ class PurchaseManager(var purchaseRepository :PurchaseRepository) : ManagerCompo TODO("Not yet implemented") } - override fun delete(entityIds: List) { + fun delete(entityIds: List) { TODO("Not yet implemented") } override fun create(entities: List): List { - TODO("Not yet implemented") + return purchaseRepository.saveAllAndFlush(entities) } } \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt index b302690..8e13868 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt @@ -1,5 +1,6 @@ package com.hanghea99.commerce.api.purchase +import com.hanghea99.commerce.api.common.domain.PostNullResultResponse import com.hanghea99.commerce.api.purchase.domain.* import com.hanghea99.commerce.logger import org.springframework.web.bind.annotation.* @@ -9,6 +10,42 @@ import org.springframework.web.bind.annotation.* class PurchaseController(val purchaseService: PurchaseService) { private val log = logger() + /** + * API명 : PURCHASE_001 + * API용도 : 주문 요청 + * @param PostPurchaseRequest + * @return PostPurchaseResponse + */ + @PostMapping("") + @Throws(Exception::class) + fun postPurchase(postPurchaseRequest: PostPurchaseRequest) : PostPurchaseResponse { + return purchaseService.postPurchase(postPurchaseRequest) + } + + /** + * API명 : PURCHASE_002 + * API용도 : 주문 수정 + * @param PostPurchaseUpdateRequest + * @return PostPurchaseUpdateResponse + */ + @PostMapping("/update") + @Throws(Exception::class) + fun postPurchaseUpdate(postPurchaseUpdateRequest: PostPurchaseUpdateRequest) : PostNullResultResponse { + return purchaseService.postPurchaseUpdate(postPurchaseUpdateRequest) + } + + /** + * API명 : PURCHASE_003 + * API용도 : 주문 취소 + * @param PostPurchaseDeleteRequest + * @return PostPurchaseDeleteResponse + */ + @PostMapping("/delete") + @Throws(Exception::class) + fun postPurchaseDelete(postPurchaseDeleteRequest: PostPurchaseDeleteRequest) : PostNullResultResponse { + return purchaseService.postPurchaseDelete(postPurchaseDeleteRequest) + } + /** * API명 : PURCHASE_004 * API용도 : 주문 전체 조회 @@ -32,4 +69,5 @@ class PurchaseController(val purchaseService: PurchaseService) { // fun getPurchaseDetail(getPurchaseDetailRequest: GetPurchaseDetailRequest) : GetPurchaseDetailResponse { // return purchaseService.getPurchaseDetail(getPurchaseDetailRequest) // } + } \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt index 6535942..ca603c2 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt @@ -3,6 +3,7 @@ package com.hanghea99.commerce.api.purchase import com.hanghea99.commerce.api.common.ResultCodeMsg import com.hanghea99.commerce.api.common.comp.impl.PurchaseManager import com.hanghea99.commerce.api.common.comp.impl.PurchaseReader +import com.hanghea99.commerce.api.common.domain.PostNullResultResponse import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo import com.hanghea99.commerce.api.purchase.domain.* import com.hanghea99.commerce.database.entity.PurchaseEntity @@ -11,6 +12,8 @@ import com.hanghea99.commerce.logger import com.querydsl.core.BooleanBuilder import org.springframework.stereotype.Service import org.springframework.validation.annotation.Validated +import org.springframework.web.bind.annotation.RequestBody +import java.time.Instant import kotlin.jvm.Throws @Service @@ -23,6 +26,71 @@ class PurchaseService( var qPurchaseEntity: QPurchaseEntity = QPurchaseEntity("s1") + @Throws(Exception::class) + fun postPurchase(@RequestBody postPurchaseRequest: PostPurchaseRequest) : PostPurchaseResponse { + + val createEntities: List = listOf( + PurchaseEntity( + userId = postPurchaseRequest.purchase.userId, + totalPrice = postPurchaseRequest.purchase.totalPrice, + purchaseDate = Instant.now(), + cancleDate = postPurchaseRequest.purchase.cancleDate, + status = postPurchaseRequest.purchase.status, + ) + ) + + val resultEntity: PurchaseEntity = purchaseManager.create(createEntities).first() + + return PostPurchaseResponse( + resultCodeMsg = ResultCodeMsg.SUCCESS, + result = PurchaseVo( + purchaseKey = resultEntity.purchaseKey, + userId = resultEntity.userId, + totalPrice = resultEntity.totalPrice, + cancleDate = resultEntity.cancleDate, + status = resultEntity.status + ) + ) + } + + @Throws(Exception::class) + fun postPurchaseUpdate(@RequestBody postPurchaseUpdateRequest: PostPurchaseUpdateRequest) : PostNullResultResponse{ + + purchaseManager.update( + listOf( + PurchaseEntity( + purchaseKey = postPurchaseUpdateRequest.purchase.purchaseKey, + userId = postPurchaseUpdateRequest.purchase.userId, + totalPrice = postPurchaseUpdateRequest.purchase.totalPrice, + purchaseDate = postPurchaseUpdateRequest.purchase.purchaseDate, + cancleDate = postPurchaseUpdateRequest.purchase.cancleDate, + status = postPurchaseUpdateRequest.purchase.status, + ) + ) + ) + + return PostNullResultResponse( + ResultCodeMsg.SUCCESS + ) + } + + @Throws(Exception::class) + fun postPurchaseDelete(@RequestBody postPurchaseDeleteRequest: PostPurchaseDeleteRequest): PostNullResultResponse { + + purchaseManager.delete( + postPurchaseDeleteRequest.deleteKeys.map{deleteKey -> + PurchaseEntity( + purchaseKey = deleteKey, + cancleDate = Instant.now(), + ) + } + ) + + return PostNullResultResponse( + ResultCodeMsg.SUCCESS + ) + } + @Throws(Exception::class) fun getPurchase(getPurchaseRequest: GetPurchaseRequest): GetPurchaseResponse{ val booleanBuilder = BooleanBuilder() From 7818d060192ed9a16ef2bfddfc05935d32b12a4c Mon Sep 17 00:00:00 2001 From: "HKMC\\H2211843" <9417143@ict-companion.com> Date: Thu, 12 Oct 2023 17:34:37 +0900 Subject: [PATCH 13/19] =?UTF-8?q?=EC=A3=BC=EB=AC=B8=20=EC=B7=A8=EC=86=8C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commerce/api/common/comp/impl/PurchaseManager.kt | 4 ++-- .../com/hanghea99/commerce/api/purchase/PurchaseService.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt index 7bcf759..4e1ef56 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt @@ -8,10 +8,10 @@ import org.springframework.stereotype.Component @Component class PurchaseManager(var purchaseRepository :PurchaseRepository) : ManagerComponent() { override fun update(entities: List): Long { - TODO("Not yet implemented") + return purchaseRepository.saveAllAndFlush(entities).count().toLong() } - fun delete(entityIds: List) { + override fun delete(entityIds: List) { TODO("Not yet implemented") } diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt index ca603c2..437dbbb 100644 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt +++ b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt @@ -77,7 +77,7 @@ class PurchaseService( @Throws(Exception::class) fun postPurchaseDelete(@RequestBody postPurchaseDeleteRequest: PostPurchaseDeleteRequest): PostNullResultResponse { - purchaseManager.delete( + purchaseManager.update( postPurchaseDeleteRequest.deleteKeys.map{deleteKey -> PurchaseEntity( purchaseKey = deleteKey, From 5e92f89494be0700f49196b71179b36f8dda78d6 Mon Sep 17 00:00:00 2001 From: "HKMC\\H2211843" <9417143@ict-companion.com> Date: Fri, 20 Oct 2023 17:19:28 +0900 Subject: [PATCH 14/19] =?UTF-8?q?=EA=B3=B5=ED=86=B5=20Exception=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commerce/exception/BusinessException.kt | 14 +++ .../exception/EntityNotFoundException.kt | 3 + .../hanghea99/commerce/exception/ErrorCode.kt | 29 +++++++ .../commerce/exception/ErrorResponse.kt | 72 +++++++++++++++ .../exception/GlobalExceptionHandler.kt | 87 +++++++++++++++++++ .../exception/InvalidValueException.kt | 6 ++ 6 files changed, 211 insertions(+) create mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/BusinessException.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/EntityNotFoundException.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/ErrorCode.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/ErrorResponse.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/GlobalExceptionHandler.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/InvalidValueException.kt diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/BusinessException.kt b/src/main/kotlin/com/hanghea99/commerce/exception/BusinessException.kt new file mode 100644 index 0000000..a334c1d --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/exception/BusinessException.kt @@ -0,0 +1,14 @@ +package com.hanghea99.commerce.exception + +open class BusinessException:RuntimeException { + var errorCode: ErrorCode + + private set + constructor(message: String?, errorCode: ErrorCode) : super(message) { + this.errorCode = errorCode + } + + constructor(errorCode: ErrorCode) : super(errorCode.message) { + this.errorCode = errorCode + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/EntityNotFoundException.kt b/src/main/kotlin/com/hanghea99/commerce/exception/EntityNotFoundException.kt new file mode 100644 index 0000000..794abae --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/exception/EntityNotFoundException.kt @@ -0,0 +1,3 @@ +package com.hanghea99.commerce.exception + +class EntityNotFoundException(message: String?) : BusinessException(message, ErrorCode.ENTITY_NOT_FOUND) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/ErrorCode.kt b/src/main/kotlin/com/hanghea99/commerce/exception/ErrorCode.kt new file mode 100644 index 0000000..bb5861a --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/exception/ErrorCode.kt @@ -0,0 +1,29 @@ +package com.hanghea99.commerce.exception + +import com.fasterxml.jackson.annotation.JsonFormat + +@JsonFormat(shape = JsonFormat.Shape.OBJECT) +enum class ErrorCode(val status: Int, val code: String, val message: String) { + // Common + INVALID_INPUT_VALUE(400, "C001", " Invalid Input Value"), METHOD_NOT_ALLOWED( + 405, + "C002", + " Invalid Input Value" + ), + ENTITY_NOT_FOUND(400, "C003", " Entity Not Found"), INTERNAL_SERVER_ERROR( + 500, + "C004", + "Server Error" + ), + INVALID_TYPE_VALUE(400, "C005", " Invalid Type Value"), HANDLE_ACCESS_DENIED( + 403, + "C006", + "Access is Denied" + ), // User + EMAIL_DUPLICATION(400, "M001", "Email is Duplication"), LOGIN_INPUT_INVALID( + 400, + "M002", + "Login input is invalid" + ), + +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/ErrorResponse.kt b/src/main/kotlin/com/hanghea99/commerce/exception/ErrorResponse.kt new file mode 100644 index 0000000..2c21035 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/exception/ErrorResponse.kt @@ -0,0 +1,72 @@ +package com.hanghea99.commerce.exception + +import org.springframework.validation.BindingResult +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException +import java.util.stream.Collectors +import java.util.ArrayList; + +class ErrorResponse { + private var message: String + private var status: Int + private var errors: List + private var code: String + + private constructor(code: ErrorCode, errors: List) { + this.message = code.message + this.status = code.status + this.errors = errors + this.code = code.code + } + + private constructor(code: ErrorCode) { + this.message = code.message + this.status = code.status + this.code = code.code + this.errors = ArrayList() + } + class FieldError private constructor( + private val field: String, + private val value: String, + private val reason: String? + ) { + companion object { + fun of(field: String, value: String, reason: String): List { + val fieldErrors: MutableList = ArrayList() + fieldErrors.add(FieldError(field, value, reason)) + return fieldErrors + } + fun of(bindingResult: BindingResult): List { + val fieldErrors: List = bindingResult.getFieldErrors() + return fieldErrors.stream() + .map { error -> + FieldError( + error.field, + if (error.rejectedValue == null) "" else error.rejectedValue.toString(), + error.defaultMessage + ) + } + .collect(Collectors.toList()) + } + } + } + + companion object { + fun of(code: ErrorCode, bindingResult: BindingResult): ErrorResponse { + return ErrorResponse(code, FieldError.of(bindingResult)) + } + + fun of(code: ErrorCode): ErrorResponse { + return ErrorResponse(code) + } + + fun of(code: ErrorCode, errors: List): ErrorResponse { + return ErrorResponse(code, errors) + } + + fun of(e: MethodArgumentTypeMismatchException): ErrorResponse { + val value = if (e.getValue() == null) "" else e.getValue().toString() + val errors = FieldError.of(e.getName(), value, e.getErrorCode()) + return ErrorResponse(ErrorCode.INVALID_TYPE_VALUE, errors) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/GlobalExceptionHandler.kt b/src/main/kotlin/com/hanghea99/commerce/exception/GlobalExceptionHandler.kt new file mode 100644 index 0000000..ee4740b --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/exception/GlobalExceptionHandler.kt @@ -0,0 +1,87 @@ +package com.hanghea99.commerce.exception + +import com.hanghea99.commerce.logger + +import java.nio.file.AccessDeniedException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.BindException; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; + +@ControllerAdvice +class GlobalExceptionHandler { + + private val log = logger() + /** + * javax.validation.Valid or @Validated 으로 binding error 발생시 발생한다. + * HttpMessageConverter 에서 등록한 HttpMessageConverter binding 못할경우 발생 + * 주로 @RequestBody, @RequestPart 어노테이션에서 발생 + */ + @ExceptionHandler(MethodArgumentNotValidException::class) + protected fun handleMethodArgumentNotValidException(e: MethodArgumentNotValidException): ResponseEntity { + log.error("handleMethodArgumentNotValidException", e) + val response = ErrorResponse.of(ErrorCode.INVALID_INPUT_VALUE, e.bindingResult) + return ResponseEntity(response, HttpStatus.BAD_REQUEST) + } + + /** + * @ModelAttribut 으로 binding error 발생시 BindException 발생한다. + * ref https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-ann-modelattrib-method-args + */ + @ExceptionHandler(BindException::class) + protected fun handleBindException(e: BindException): ResponseEntity { + log.error("handleBindException", e) + val response: ErrorResponse = ErrorResponse.of(ErrorCode.INVALID_INPUT_VALUE, e.getBindingResult()) + return ResponseEntity(response, HttpStatus.BAD_REQUEST) + } + + /** + * enum type 일치하지 않아 binding 못할 경우 발생 + * 주로 @RequestParam enum으로 binding 못했을 경우 발생 + */ + @ExceptionHandler(MethodArgumentTypeMismatchException::class) + protected fun handleMethodArgumentTypeMismatchException(e: MethodArgumentTypeMismatchException?): ResponseEntity { + log.error("handleMethodArgumentTypeMismatchException", e) + val response: ErrorResponse = ErrorResponse.of(ErrorCode.INVALID_TYPE_VALUE) + return ResponseEntity(response, HttpStatus.BAD_REQUEST) + } + + /** + * 지원하지 않은 HTTP method 호출 할 경우 발생 + */ + @ExceptionHandler(HttpRequestMethodNotSupportedException::class) + protected fun handleHttpRequestMethodNotSupportedException(e: HttpRequestMethodNotSupportedException?): ResponseEntity { + log.error("handleHttpRequestMethodNotSupportedException", e) + val response = ErrorResponse.of(ErrorCode.METHOD_NOT_ALLOWED) + return ResponseEntity(response, HttpStatus.METHOD_NOT_ALLOWED) + } + + /** + * Authentication 객체가 필요한 권한을 보유하지 않은 경우 발생합 + */ + @ExceptionHandler(AccessDeniedException::class) + protected fun handleAccessDeniedException(e: AccessDeniedException?): ResponseEntity { + log.error("handleAccessDeniedException", e) + val response = ErrorResponse.of(ErrorCode.HANDLE_ACCESS_DENIED) + return ResponseEntity(response, HttpStatus.valueOf(ErrorCode.HANDLE_ACCESS_DENIED.status)) + } + + @ExceptionHandler(BusinessException::class) + protected fun handleBusinessException(e: BusinessException): ResponseEntity { + log.error("handleEntityNotFoundException", e) + val errorCode: ErrorCode = e.errorCode + val response = ErrorResponse.of(errorCode) + return ResponseEntity(response, HttpStatus.valueOf(errorCode.status)) + } + + @ExceptionHandler(Exception::class) + protected fun handleException(e: Exception?): ResponseEntity { + log.error("handleEntityNotFoundException", e) + val response = ErrorResponse.of(ErrorCode.INTERNAL_SERVER_ERROR) + return ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/InvalidValueException.kt b/src/main/kotlin/com/hanghea99/commerce/exception/InvalidValueException.kt new file mode 100644 index 0000000..aa10ac5 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/exception/InvalidValueException.kt @@ -0,0 +1,6 @@ +package com.hanghea99.commerce.exception + +class InvalidValueException : BusinessException { + constructor(value: String?) : super(value, ErrorCode.INVALID_INPUT_VALUE) + constructor(value: String?, errorCode: ErrorCode?) : super(value, errorCode!!) +} \ No newline at end of file From cc09e11f83fcc41348d1a8fd9fb0b410f6f85a75 Mon Sep 17 00:00:00 2001 From: "HKMC\\H2211843" <9417143@ict-companion.com> Date: Fri, 20 Oct 2023 17:34:02 +0900 Subject: [PATCH 15/19] =?UTF-8?q?=EA=B3=B5=ED=86=B5=20=EC=A0=84=EC=97=AD?= =?UTF-8?q?=20Exception=20=EC=9E=91=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commerce/exception/BusinessException.kt | 14 --- .../exception/EntityNotFoundException.kt | 3 - .../hanghea99/commerce/exception/ErrorCode.kt | 29 ------- .../commerce/exception/ErrorResponse.kt | 72 --------------- .../exception/GlobalExceptionHandler.kt | 87 ------------------- .../exception/InvalidValueException.kt | 6 -- 6 files changed, 211 deletions(-) delete mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/BusinessException.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/EntityNotFoundException.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/ErrorCode.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/ErrorResponse.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/GlobalExceptionHandler.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/InvalidValueException.kt diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/BusinessException.kt b/src/main/kotlin/com/hanghea99/commerce/exception/BusinessException.kt deleted file mode 100644 index a334c1d..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/exception/BusinessException.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.hanghea99.commerce.exception - -open class BusinessException:RuntimeException { - var errorCode: ErrorCode - - private set - constructor(message: String?, errorCode: ErrorCode) : super(message) { - this.errorCode = errorCode - } - - constructor(errorCode: ErrorCode) : super(errorCode.message) { - this.errorCode = errorCode - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/EntityNotFoundException.kt b/src/main/kotlin/com/hanghea99/commerce/exception/EntityNotFoundException.kt deleted file mode 100644 index 794abae..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/exception/EntityNotFoundException.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.hanghea99.commerce.exception - -class EntityNotFoundException(message: String?) : BusinessException(message, ErrorCode.ENTITY_NOT_FOUND) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/ErrorCode.kt b/src/main/kotlin/com/hanghea99/commerce/exception/ErrorCode.kt deleted file mode 100644 index bb5861a..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/exception/ErrorCode.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.hanghea99.commerce.exception - -import com.fasterxml.jackson.annotation.JsonFormat - -@JsonFormat(shape = JsonFormat.Shape.OBJECT) -enum class ErrorCode(val status: Int, val code: String, val message: String) { - // Common - INVALID_INPUT_VALUE(400, "C001", " Invalid Input Value"), METHOD_NOT_ALLOWED( - 405, - "C002", - " Invalid Input Value" - ), - ENTITY_NOT_FOUND(400, "C003", " Entity Not Found"), INTERNAL_SERVER_ERROR( - 500, - "C004", - "Server Error" - ), - INVALID_TYPE_VALUE(400, "C005", " Invalid Type Value"), HANDLE_ACCESS_DENIED( - 403, - "C006", - "Access is Denied" - ), // User - EMAIL_DUPLICATION(400, "M001", "Email is Duplication"), LOGIN_INPUT_INVALID( - 400, - "M002", - "Login input is invalid" - ), - -} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/ErrorResponse.kt b/src/main/kotlin/com/hanghea99/commerce/exception/ErrorResponse.kt deleted file mode 100644 index 2c21035..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/exception/ErrorResponse.kt +++ /dev/null @@ -1,72 +0,0 @@ -package com.hanghea99.commerce.exception - -import org.springframework.validation.BindingResult -import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException -import java.util.stream.Collectors -import java.util.ArrayList; - -class ErrorResponse { - private var message: String - private var status: Int - private var errors: List - private var code: String - - private constructor(code: ErrorCode, errors: List) { - this.message = code.message - this.status = code.status - this.errors = errors - this.code = code.code - } - - private constructor(code: ErrorCode) { - this.message = code.message - this.status = code.status - this.code = code.code - this.errors = ArrayList() - } - class FieldError private constructor( - private val field: String, - private val value: String, - private val reason: String? - ) { - companion object { - fun of(field: String, value: String, reason: String): List { - val fieldErrors: MutableList = ArrayList() - fieldErrors.add(FieldError(field, value, reason)) - return fieldErrors - } - fun of(bindingResult: BindingResult): List { - val fieldErrors: List = bindingResult.getFieldErrors() - return fieldErrors.stream() - .map { error -> - FieldError( - error.field, - if (error.rejectedValue == null) "" else error.rejectedValue.toString(), - error.defaultMessage - ) - } - .collect(Collectors.toList()) - } - } - } - - companion object { - fun of(code: ErrorCode, bindingResult: BindingResult): ErrorResponse { - return ErrorResponse(code, FieldError.of(bindingResult)) - } - - fun of(code: ErrorCode): ErrorResponse { - return ErrorResponse(code) - } - - fun of(code: ErrorCode, errors: List): ErrorResponse { - return ErrorResponse(code, errors) - } - - fun of(e: MethodArgumentTypeMismatchException): ErrorResponse { - val value = if (e.getValue() == null) "" else e.getValue().toString() - val errors = FieldError.of(e.getName(), value, e.getErrorCode()) - return ErrorResponse(ErrorCode.INVALID_TYPE_VALUE, errors) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/GlobalExceptionHandler.kt b/src/main/kotlin/com/hanghea99/commerce/exception/GlobalExceptionHandler.kt deleted file mode 100644 index ee4740b..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/exception/GlobalExceptionHandler.kt +++ /dev/null @@ -1,87 +0,0 @@ -package com.hanghea99.commerce.exception - -import com.hanghea99.commerce.logger - -import java.nio.file.AccessDeniedException; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.validation.BindException; -import org.springframework.web.HttpRequestMethodNotSupportedException; -import org.springframework.web.bind.MethodArgumentNotValidException; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; - -@ControllerAdvice -class GlobalExceptionHandler { - - private val log = logger() - /** - * javax.validation.Valid or @Validated 으로 binding error 발생시 발생한다. - * HttpMessageConverter 에서 등록한 HttpMessageConverter binding 못할경우 발생 - * 주로 @RequestBody, @RequestPart 어노테이션에서 발생 - */ - @ExceptionHandler(MethodArgumentNotValidException::class) - protected fun handleMethodArgumentNotValidException(e: MethodArgumentNotValidException): ResponseEntity { - log.error("handleMethodArgumentNotValidException", e) - val response = ErrorResponse.of(ErrorCode.INVALID_INPUT_VALUE, e.bindingResult) - return ResponseEntity(response, HttpStatus.BAD_REQUEST) - } - - /** - * @ModelAttribut 으로 binding error 발생시 BindException 발생한다. - * ref https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-ann-modelattrib-method-args - */ - @ExceptionHandler(BindException::class) - protected fun handleBindException(e: BindException): ResponseEntity { - log.error("handleBindException", e) - val response: ErrorResponse = ErrorResponse.of(ErrorCode.INVALID_INPUT_VALUE, e.getBindingResult()) - return ResponseEntity(response, HttpStatus.BAD_REQUEST) - } - - /** - * enum type 일치하지 않아 binding 못할 경우 발생 - * 주로 @RequestParam enum으로 binding 못했을 경우 발생 - */ - @ExceptionHandler(MethodArgumentTypeMismatchException::class) - protected fun handleMethodArgumentTypeMismatchException(e: MethodArgumentTypeMismatchException?): ResponseEntity { - log.error("handleMethodArgumentTypeMismatchException", e) - val response: ErrorResponse = ErrorResponse.of(ErrorCode.INVALID_TYPE_VALUE) - return ResponseEntity(response, HttpStatus.BAD_REQUEST) - } - - /** - * 지원하지 않은 HTTP method 호출 할 경우 발생 - */ - @ExceptionHandler(HttpRequestMethodNotSupportedException::class) - protected fun handleHttpRequestMethodNotSupportedException(e: HttpRequestMethodNotSupportedException?): ResponseEntity { - log.error("handleHttpRequestMethodNotSupportedException", e) - val response = ErrorResponse.of(ErrorCode.METHOD_NOT_ALLOWED) - return ResponseEntity(response, HttpStatus.METHOD_NOT_ALLOWED) - } - - /** - * Authentication 객체가 필요한 권한을 보유하지 않은 경우 발생합 - */ - @ExceptionHandler(AccessDeniedException::class) - protected fun handleAccessDeniedException(e: AccessDeniedException?): ResponseEntity { - log.error("handleAccessDeniedException", e) - val response = ErrorResponse.of(ErrorCode.HANDLE_ACCESS_DENIED) - return ResponseEntity(response, HttpStatus.valueOf(ErrorCode.HANDLE_ACCESS_DENIED.status)) - } - - @ExceptionHandler(BusinessException::class) - protected fun handleBusinessException(e: BusinessException): ResponseEntity { - log.error("handleEntityNotFoundException", e) - val errorCode: ErrorCode = e.errorCode - val response = ErrorResponse.of(errorCode) - return ResponseEntity(response, HttpStatus.valueOf(errorCode.status)) - } - - @ExceptionHandler(Exception::class) - protected fun handleException(e: Exception?): ResponseEntity { - log.error("handleEntityNotFoundException", e) - val response = ErrorResponse.of(ErrorCode.INTERNAL_SERVER_ERROR) - return ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/InvalidValueException.kt b/src/main/kotlin/com/hanghea99/commerce/exception/InvalidValueException.kt deleted file mode 100644 index aa10ac5..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/exception/InvalidValueException.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.hanghea99.commerce.exception - -class InvalidValueException : BusinessException { - constructor(value: String?) : super(value, ErrorCode.INVALID_INPUT_VALUE) - constructor(value: String?, errorCode: ErrorCode?) : super(value, errorCode!!) -} \ No newline at end of file From 7c6376744af5f2e718eb5d69906fc35a1b1ea6ba Mon Sep 17 00:00:00 2001 From: "HKMC\\H2211843" <9417143@ict-companion.com> Date: Fri, 20 Oct 2023 17:35:59 +0900 Subject: [PATCH 16/19] =?UTF-8?q?Revert=20"=EA=B3=B5=ED=86=B5=20=EC=A0=84?= =?UTF-8?q?=EC=97=AD=20Exception=20=EC=9E=91=EC=97=85"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit cc09e11f83fcc41348d1a8fd9fb0b410f6f85a75. --- .../commerce/exception/BusinessException.kt | 14 +++ .../exception/EntityNotFoundException.kt | 3 + .../hanghea99/commerce/exception/ErrorCode.kt | 29 +++++++ .../commerce/exception/ErrorResponse.kt | 72 +++++++++++++++ .../exception/GlobalExceptionHandler.kt | 87 +++++++++++++++++++ .../exception/InvalidValueException.kt | 6 ++ 6 files changed, 211 insertions(+) create mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/BusinessException.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/EntityNotFoundException.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/ErrorCode.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/ErrorResponse.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/GlobalExceptionHandler.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/exception/InvalidValueException.kt diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/BusinessException.kt b/src/main/kotlin/com/hanghea99/commerce/exception/BusinessException.kt new file mode 100644 index 0000000..a334c1d --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/exception/BusinessException.kt @@ -0,0 +1,14 @@ +package com.hanghea99.commerce.exception + +open class BusinessException:RuntimeException { + var errorCode: ErrorCode + + private set + constructor(message: String?, errorCode: ErrorCode) : super(message) { + this.errorCode = errorCode + } + + constructor(errorCode: ErrorCode) : super(errorCode.message) { + this.errorCode = errorCode + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/EntityNotFoundException.kt b/src/main/kotlin/com/hanghea99/commerce/exception/EntityNotFoundException.kt new file mode 100644 index 0000000..794abae --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/exception/EntityNotFoundException.kt @@ -0,0 +1,3 @@ +package com.hanghea99.commerce.exception + +class EntityNotFoundException(message: String?) : BusinessException(message, ErrorCode.ENTITY_NOT_FOUND) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/ErrorCode.kt b/src/main/kotlin/com/hanghea99/commerce/exception/ErrorCode.kt new file mode 100644 index 0000000..bb5861a --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/exception/ErrorCode.kt @@ -0,0 +1,29 @@ +package com.hanghea99.commerce.exception + +import com.fasterxml.jackson.annotation.JsonFormat + +@JsonFormat(shape = JsonFormat.Shape.OBJECT) +enum class ErrorCode(val status: Int, val code: String, val message: String) { + // Common + INVALID_INPUT_VALUE(400, "C001", " Invalid Input Value"), METHOD_NOT_ALLOWED( + 405, + "C002", + " Invalid Input Value" + ), + ENTITY_NOT_FOUND(400, "C003", " Entity Not Found"), INTERNAL_SERVER_ERROR( + 500, + "C004", + "Server Error" + ), + INVALID_TYPE_VALUE(400, "C005", " Invalid Type Value"), HANDLE_ACCESS_DENIED( + 403, + "C006", + "Access is Denied" + ), // User + EMAIL_DUPLICATION(400, "M001", "Email is Duplication"), LOGIN_INPUT_INVALID( + 400, + "M002", + "Login input is invalid" + ), + +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/ErrorResponse.kt b/src/main/kotlin/com/hanghea99/commerce/exception/ErrorResponse.kt new file mode 100644 index 0000000..2c21035 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/exception/ErrorResponse.kt @@ -0,0 +1,72 @@ +package com.hanghea99.commerce.exception + +import org.springframework.validation.BindingResult +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException +import java.util.stream.Collectors +import java.util.ArrayList; + +class ErrorResponse { + private var message: String + private var status: Int + private var errors: List + private var code: String + + private constructor(code: ErrorCode, errors: List) { + this.message = code.message + this.status = code.status + this.errors = errors + this.code = code.code + } + + private constructor(code: ErrorCode) { + this.message = code.message + this.status = code.status + this.code = code.code + this.errors = ArrayList() + } + class FieldError private constructor( + private val field: String, + private val value: String, + private val reason: String? + ) { + companion object { + fun of(field: String, value: String, reason: String): List { + val fieldErrors: MutableList = ArrayList() + fieldErrors.add(FieldError(field, value, reason)) + return fieldErrors + } + fun of(bindingResult: BindingResult): List { + val fieldErrors: List = bindingResult.getFieldErrors() + return fieldErrors.stream() + .map { error -> + FieldError( + error.field, + if (error.rejectedValue == null) "" else error.rejectedValue.toString(), + error.defaultMessage + ) + } + .collect(Collectors.toList()) + } + } + } + + companion object { + fun of(code: ErrorCode, bindingResult: BindingResult): ErrorResponse { + return ErrorResponse(code, FieldError.of(bindingResult)) + } + + fun of(code: ErrorCode): ErrorResponse { + return ErrorResponse(code) + } + + fun of(code: ErrorCode, errors: List): ErrorResponse { + return ErrorResponse(code, errors) + } + + fun of(e: MethodArgumentTypeMismatchException): ErrorResponse { + val value = if (e.getValue() == null) "" else e.getValue().toString() + val errors = FieldError.of(e.getName(), value, e.getErrorCode()) + return ErrorResponse(ErrorCode.INVALID_TYPE_VALUE, errors) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/GlobalExceptionHandler.kt b/src/main/kotlin/com/hanghea99/commerce/exception/GlobalExceptionHandler.kt new file mode 100644 index 0000000..ee4740b --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/exception/GlobalExceptionHandler.kt @@ -0,0 +1,87 @@ +package com.hanghea99.commerce.exception + +import com.hanghea99.commerce.logger + +import java.nio.file.AccessDeniedException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.BindException; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; + +@ControllerAdvice +class GlobalExceptionHandler { + + private val log = logger() + /** + * javax.validation.Valid or @Validated 으로 binding error 발생시 발생한다. + * HttpMessageConverter 에서 등록한 HttpMessageConverter binding 못할경우 발생 + * 주로 @RequestBody, @RequestPart 어노테이션에서 발생 + */ + @ExceptionHandler(MethodArgumentNotValidException::class) + protected fun handleMethodArgumentNotValidException(e: MethodArgumentNotValidException): ResponseEntity { + log.error("handleMethodArgumentNotValidException", e) + val response = ErrorResponse.of(ErrorCode.INVALID_INPUT_VALUE, e.bindingResult) + return ResponseEntity(response, HttpStatus.BAD_REQUEST) + } + + /** + * @ModelAttribut 으로 binding error 발생시 BindException 발생한다. + * ref https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-ann-modelattrib-method-args + */ + @ExceptionHandler(BindException::class) + protected fun handleBindException(e: BindException): ResponseEntity { + log.error("handleBindException", e) + val response: ErrorResponse = ErrorResponse.of(ErrorCode.INVALID_INPUT_VALUE, e.getBindingResult()) + return ResponseEntity(response, HttpStatus.BAD_REQUEST) + } + + /** + * enum type 일치하지 않아 binding 못할 경우 발생 + * 주로 @RequestParam enum으로 binding 못했을 경우 발생 + */ + @ExceptionHandler(MethodArgumentTypeMismatchException::class) + protected fun handleMethodArgumentTypeMismatchException(e: MethodArgumentTypeMismatchException?): ResponseEntity { + log.error("handleMethodArgumentTypeMismatchException", e) + val response: ErrorResponse = ErrorResponse.of(ErrorCode.INVALID_TYPE_VALUE) + return ResponseEntity(response, HttpStatus.BAD_REQUEST) + } + + /** + * 지원하지 않은 HTTP method 호출 할 경우 발생 + */ + @ExceptionHandler(HttpRequestMethodNotSupportedException::class) + protected fun handleHttpRequestMethodNotSupportedException(e: HttpRequestMethodNotSupportedException?): ResponseEntity { + log.error("handleHttpRequestMethodNotSupportedException", e) + val response = ErrorResponse.of(ErrorCode.METHOD_NOT_ALLOWED) + return ResponseEntity(response, HttpStatus.METHOD_NOT_ALLOWED) + } + + /** + * Authentication 객체가 필요한 권한을 보유하지 않은 경우 발생합 + */ + @ExceptionHandler(AccessDeniedException::class) + protected fun handleAccessDeniedException(e: AccessDeniedException?): ResponseEntity { + log.error("handleAccessDeniedException", e) + val response = ErrorResponse.of(ErrorCode.HANDLE_ACCESS_DENIED) + return ResponseEntity(response, HttpStatus.valueOf(ErrorCode.HANDLE_ACCESS_DENIED.status)) + } + + @ExceptionHandler(BusinessException::class) + protected fun handleBusinessException(e: BusinessException): ResponseEntity { + log.error("handleEntityNotFoundException", e) + val errorCode: ErrorCode = e.errorCode + val response = ErrorResponse.of(errorCode) + return ResponseEntity(response, HttpStatus.valueOf(errorCode.status)) + } + + @ExceptionHandler(Exception::class) + protected fun handleException(e: Exception?): ResponseEntity { + log.error("handleEntityNotFoundException", e) + val response = ErrorResponse.of(ErrorCode.INTERNAL_SERVER_ERROR) + return ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/exception/InvalidValueException.kt b/src/main/kotlin/com/hanghea99/commerce/exception/InvalidValueException.kt new file mode 100644 index 0000000..aa10ac5 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/exception/InvalidValueException.kt @@ -0,0 +1,6 @@ +package com.hanghea99.commerce.exception + +class InvalidValueException : BusinessException { + constructor(value: String?) : super(value, ErrorCode.INVALID_INPUT_VALUE) + constructor(value: String?, errorCode: ErrorCode?) : super(value, errorCode!!) +} \ No newline at end of file From 9c6852d7b1776e49b056fa5646b6f60fa4b18c35 Mon Sep 17 00:00:00 2001 From: "HKMC\\H2211843" <9417143@ict-companion.com> Date: Fri, 20 Oct 2023 17:36:58 +0900 Subject: [PATCH 17/19] =?UTF-8?q?=EC=A3=BC=EB=AC=B8=20API=20=EC=9E=91?= =?UTF-8?q?=EC=97=85=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/common/comp/impl/PurchaseManager.kt | 21 --- .../api/common/comp/impl/PurchaseReader.kt | 58 -------- .../api/common/domain/purchase/PurchaseVo.kt | 13 -- .../api/purchase/PurchaseController.kt | 73 ---------- .../commerce/api/purchase/PurchaseService.kt | 137 ------------------ .../domain/GetPurchaseDetailRequest.kt | 4 - .../domain/GetPurchaseDetailResponse.kt | 15 -- .../domain/GetPurchaseDetailResult.kt | 4 - .../purchase/domain/GetPurchaseDetailVo.kt | 7 - .../api/purchase/domain/GetPurchaseRequest.kt | 24 --- .../purchase/domain/GetPurchaseResponse.kt | 15 -- .../api/purchase/domain/GetPurchaseResult.kt | 8 - .../api/purchase/domain/GetPurchaseVo.kt | 8 - .../domain/PostPurchaseDeleteRequest.kt | 7 - .../purchase/domain/PostPurchaseRequest.kt | 7 - .../purchase/domain/PostPurchaseResponse.kt | 11 -- .../domain/PostPurchaseUpdateRequest.kt | 8 - .../api/purchase/PurchaseControllerTest.kt | 54 ------- 18 files changed, 474 deletions(-) delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseReader.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/common/domain/purchase/PurchaseVo.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailRequest.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResponse.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResult.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailVo.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResponse.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseVo.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt delete mode 100644 src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt delete mode 100644 src/test/kotlin/com/hanghea99/commerce/api/purchase/PurchaseControllerTest.kt diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt deleted file mode 100644 index 4e1ef56..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseManager.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.hanghea99.commerce.api.common.comp.impl - -import com.hanghea99.commerce.api.common.comp.ManagerComponent -import com.hanghea99.commerce.database.entity.PurchaseEntity -import com.hanghea99.commerce.database.repository.PurchaseRepository -import org.springframework.stereotype.Component - -@Component -class PurchaseManager(var purchaseRepository :PurchaseRepository) : ManagerComponent() { - override fun update(entities: List): Long { - return purchaseRepository.saveAllAndFlush(entities).count().toLong() - } - - override fun delete(entityIds: List) { - TODO("Not yet implemented") - } - - override fun create(entities: List): List { - return purchaseRepository.saveAllAndFlush(entities) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseReader.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseReader.kt deleted file mode 100644 index 7c61e8e..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/common/comp/impl/PurchaseReader.kt +++ /dev/null @@ -1,58 +0,0 @@ -package com.hanghea99.commerce.api.common.comp.impl - -import com.hanghea99.commerce.api.common.comp.ReaderComponent -import com.hanghea99.commerce.database.entity.PurchaseEntity -import com.hanghea99.commerce.database.entity.QPurchaseEntity - -import com.hanghea99.commerce.database.repository.PurchaseRepository -import com.querydsl.core.BooleanBuilder -import com.querydsl.core.types.OrderSpecifier -import com.querydsl.jpa.impl.JPAQueryFactory -import org.slf4j.LoggerFactory -import org.springframework.stereotype.Component - -@Component -class PurchaseReader ( - val purchaseRepository: PurchaseRepository, - val jpaQueryFactory: JPAQueryFactory, -) : ReaderComponent( - ) { - private val log = LoggerFactory.getLogger("PurchaseReader") - - val qPurchaseEntity: QPurchaseEntity = QPurchaseEntity("s1") - - override fun read(id: Long): PurchaseEntity { - TODO("Not yet implemented") - } - - override fun read(where: BooleanBuilder): PurchaseEntity { - TODO("Not yet implemented") - } - - override fun readAll(ids: List): List { - TODO("Not yet implemented") - } - - override fun readAll( - where: BooleanBuilder, - offset: Long, - count: Long, - orders: MutableList> - ): List { - val orders: MutableList> = mutableListOf() - return jpaQueryFactory.selectFrom(qPurchaseEntity) - .where(where) - .orderBy(*orders.toTypedArray()) - .offset(offset) - .limit(count) - .fetch() - } - - override fun readAllCount(ids: List): Long { - TODO("Not yet implemented") - } - - override fun readAllCount(where: BooleanBuilder): Long { - TODO("Not yet implemented") - } -} diff --git a/src/main/kotlin/com/hanghea99/commerce/api/common/domain/purchase/PurchaseVo.kt b/src/main/kotlin/com/hanghea99/commerce/api/common/domain/purchase/PurchaseVo.kt deleted file mode 100644 index 4bcccc6..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/common/domain/purchase/PurchaseVo.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.hanghea99.commerce.api.common.domain.purchase - -import java.math.BigDecimal -import java.time.Instant - -data class PurchaseVo ( - var purchaseKey: Long? = null, - var userId: Long? = null, - var totalPrice: BigDecimal? =null, - var purchaseDate: Instant? = null, - var cancleDate: Instant? = null, - var status: String? = null, -) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt deleted file mode 100644 index 8e13868..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseController.kt +++ /dev/null @@ -1,73 +0,0 @@ -package com.hanghea99.commerce.api.purchase - -import com.hanghea99.commerce.api.common.domain.PostNullResultResponse -import com.hanghea99.commerce.api.purchase.domain.* -import com.hanghea99.commerce.logger -import org.springframework.web.bind.annotation.* - -@RestController -@RequestMapping("/api/purchase") -class PurchaseController(val purchaseService: PurchaseService) { - private val log = logger() - - /** - * API명 : PURCHASE_001 - * API용도 : 주문 요청 - * @param PostPurchaseRequest - * @return PostPurchaseResponse - */ - @PostMapping("") - @Throws(Exception::class) - fun postPurchase(postPurchaseRequest: PostPurchaseRequest) : PostPurchaseResponse { - return purchaseService.postPurchase(postPurchaseRequest) - } - - /** - * API명 : PURCHASE_002 - * API용도 : 주문 수정 - * @param PostPurchaseUpdateRequest - * @return PostPurchaseUpdateResponse - */ - @PostMapping("/update") - @Throws(Exception::class) - fun postPurchaseUpdate(postPurchaseUpdateRequest: PostPurchaseUpdateRequest) : PostNullResultResponse { - return purchaseService.postPurchaseUpdate(postPurchaseUpdateRequest) - } - - /** - * API명 : PURCHASE_003 - * API용도 : 주문 취소 - * @param PostPurchaseDeleteRequest - * @return PostPurchaseDeleteResponse - */ - @PostMapping("/delete") - @Throws(Exception::class) - fun postPurchaseDelete(postPurchaseDeleteRequest: PostPurchaseDeleteRequest) : PostNullResultResponse { - return purchaseService.postPurchaseDelete(postPurchaseDeleteRequest) - } - - /** - * API명 : PURCHASE_004 - * API용도 : 주문 전체 조회 - * @param GetPurchaseRequest - * @return GetPurchaseResponse - */ - @GetMapping("") - @Throws(Exception::class) - fun getPurchase(getPurchaseRequest: GetPurchaseRequest): GetPurchaseResponse{ - return purchaseService.getPurchase(getPurchaseRequest) - } - - /** - * API명 : PURCHASE_005 - * API용도 : 주문 상세 조회 - * @param GetPurchaseDetailRequest - * @return GetPurchaseDetailResponse - */ -// @GetMapping("/purchase-id") -// @Throws(Exception::class) -// fun getPurchaseDetail(getPurchaseDetailRequest: GetPurchaseDetailRequest) : GetPurchaseDetailResponse { -// return purchaseService.getPurchaseDetail(getPurchaseDetailRequest) -// } - -} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt deleted file mode 100644 index 437dbbb..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/PurchaseService.kt +++ /dev/null @@ -1,137 +0,0 @@ -package com.hanghea99.commerce.api.purchase - -import com.hanghea99.commerce.api.common.ResultCodeMsg -import com.hanghea99.commerce.api.common.comp.impl.PurchaseManager -import com.hanghea99.commerce.api.common.comp.impl.PurchaseReader -import com.hanghea99.commerce.api.common.domain.PostNullResultResponse -import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo -import com.hanghea99.commerce.api.purchase.domain.* -import com.hanghea99.commerce.database.entity.PurchaseEntity -import com.hanghea99.commerce.database.entity.QPurchaseEntity -import com.hanghea99.commerce.logger -import com.querydsl.core.BooleanBuilder -import org.springframework.stereotype.Service -import org.springframework.validation.annotation.Validated -import org.springframework.web.bind.annotation.RequestBody -import java.time.Instant -import kotlin.jvm.Throws - -@Service -@Validated -class PurchaseService( - var purchaseManager: PurchaseManager, - var purchaseReader: PurchaseReader -){ - private val log = logger() - - var qPurchaseEntity: QPurchaseEntity = QPurchaseEntity("s1") - - @Throws(Exception::class) - fun postPurchase(@RequestBody postPurchaseRequest: PostPurchaseRequest) : PostPurchaseResponse { - - val createEntities: List = listOf( - PurchaseEntity( - userId = postPurchaseRequest.purchase.userId, - totalPrice = postPurchaseRequest.purchase.totalPrice, - purchaseDate = Instant.now(), - cancleDate = postPurchaseRequest.purchase.cancleDate, - status = postPurchaseRequest.purchase.status, - ) - ) - - val resultEntity: PurchaseEntity = purchaseManager.create(createEntities).first() - - return PostPurchaseResponse( - resultCodeMsg = ResultCodeMsg.SUCCESS, - result = PurchaseVo( - purchaseKey = resultEntity.purchaseKey, - userId = resultEntity.userId, - totalPrice = resultEntity.totalPrice, - cancleDate = resultEntity.cancleDate, - status = resultEntity.status - ) - ) - } - - @Throws(Exception::class) - fun postPurchaseUpdate(@RequestBody postPurchaseUpdateRequest: PostPurchaseUpdateRequest) : PostNullResultResponse{ - - purchaseManager.update( - listOf( - PurchaseEntity( - purchaseKey = postPurchaseUpdateRequest.purchase.purchaseKey, - userId = postPurchaseUpdateRequest.purchase.userId, - totalPrice = postPurchaseUpdateRequest.purchase.totalPrice, - purchaseDate = postPurchaseUpdateRequest.purchase.purchaseDate, - cancleDate = postPurchaseUpdateRequest.purchase.cancleDate, - status = postPurchaseUpdateRequest.purchase.status, - ) - ) - ) - - return PostNullResultResponse( - ResultCodeMsg.SUCCESS - ) - } - - @Throws(Exception::class) - fun postPurchaseDelete(@RequestBody postPurchaseDeleteRequest: PostPurchaseDeleteRequest): PostNullResultResponse { - - purchaseManager.update( - postPurchaseDeleteRequest.deleteKeys.map{deleteKey -> - PurchaseEntity( - purchaseKey = deleteKey, - cancleDate = Instant.now(), - ) - } - ) - - return PostNullResultResponse( - ResultCodeMsg.SUCCESS - ) - } - - @Throws(Exception::class) - fun getPurchase(getPurchaseRequest: GetPurchaseRequest): GetPurchaseResponse{ - val booleanBuilder = BooleanBuilder() - - val result = purchaseReader.readAll( - booleanBuilder, - offset = if (getPurchaseRequest.page > 0) getPurchaseRequest.page * getPurchaseRequest.count else 0, - count = getPurchaseRequest.count, - orders = when (getPurchaseRequest.sort) { - "LATEST" -> mutableListOf(qPurchaseEntity.purchaseDate.desc()) - else -> mutableListOf(qPurchaseEntity.purchaseDate.desc()) - } - ) - - return GetPurchaseResponse( - code = ResultCodeMsg.SUCCESS.code, - msg = ResultCodeMsg.SUCCESS.msg, - result = GetPurchaseVo( - totalCount = purchaseReader.readAllCount(booleanBuilder), - purchases = result.map { purchaseEntity -> - PurchaseVo( - purchaseKey = purchaseEntity.purchaseKey, - userId = purchaseEntity.userId, - totalPrice = purchaseEntity.totalPrice, - purchaseDate = purchaseEntity.purchaseDate, - cancleDate = purchaseEntity.cancleDate, - status = purchaseEntity.status, - ) - } - ) - ) - } - -// @Throws(Exception::class) -// fun getPurchaseDetail(getPurchaseDetailRequest: GetPurchaseDetailRequest) : GetPurchaseDetailResponse { -// return GetPurchaseDetailResponse( -// code = ResultCodeMsg.SUCCESS.code, -// msg = ResultCodeMsg.SUCCESS.msg, -// result = GetPurchaseVo( -// purchase = -// ) -// ) -// } -} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailRequest.kt deleted file mode 100644 index f5581b4..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailRequest.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.hanghea99.commerce.api.purchase.domain - -class GetPurchaseDetailRequest { -} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResponse.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResponse.kt deleted file mode 100644 index cead28c..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResponse.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.hanghea99.commerce.api.purchase.domain - -import com.hanghea99.commerce.api.common.ResultCodeMsg - -data class GetPurchaseDetailResponse( - val code: String, - val msg: String, - val result: GetPurchaseDetailVo, -){ - constructor(resultCodeMsg: ResultCodeMsg, result: GetPurchaseDetailVo):this( - code = resultCodeMsg.code, - msg = resultCodeMsg.msg, - result = result, - ) -} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResult.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResult.kt deleted file mode 100644 index 37bab1d..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailResult.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.hanghea99.commerce.api.purchase.domain - -class GetPurchaseDetailResult { -} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailVo.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailVo.kt deleted file mode 100644 index b883c8d..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseDetailVo.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.hanghea99.commerce.api.purchase.domain - -import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo - -data class GetPurchaseDetailVo ( - val purchase: PurchaseVo, -) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt deleted file mode 100644 index ae82be5..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseRequest.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.hanghea99.commerce.api.purchase.domain - -import com.hanghea99.commerce.api.common.domain.GetRequest -import jakarta.validation.constraints.Pattern -import jakarta.validation.constraints.Positive -import jakarta.validation.constraints.PositiveOrZero - - -data class GetPurchaseRequest ( - @Pattern(regexp = "NAME|^$") - override val types: String?, - - override val values: String?, - - @Positive - override val page: Long = 1, - - @PositiveOrZero - override val count: Long = 10, - - @Pattern(regexp = "LATEST|^$") - override val sort: String = "LATEST", - -):GetRequest(types, values, page, count, sort) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResponse.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResponse.kt deleted file mode 100644 index 63d11bb..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResponse.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.hanghea99.commerce.api.purchase.domain - -import com.hanghea99.commerce.api.common.ResultCodeMsg - -data class GetPurchaseResponse( - val code: String, - val msg: String, - val result: GetPurchaseVo, -){ - constructor(resultCodeMsg:ResultCodeMsg, result: GetPurchaseVo):this( - code = resultCodeMsg.code, - msg = resultCodeMsg.msg, - result = result, - ) -} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt deleted file mode 100644 index b3b533e..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseResult.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.hanghea99.commerce.api.purchase.domain - -import com.hanghea99.commerce.api.common.domain.store.StoreVo - -data class GetPurchaseResult( - val totalCount: Long, - val stores: List, -) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseVo.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseVo.kt deleted file mode 100644 index a9783db..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/GetPurchaseVo.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.hanghea99.commerce.api.purchase.domain - -import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo - -data class GetPurchaseVo ( - val totalCount: Long, - val purchases: List, -) \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt deleted file mode 100644 index a55614c..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseDeleteRequest.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.hanghea99.commerce.api.purchase.domain - -import com.hanghea99.commerce.api.common.domain.core.CoreRequest - -data class PostPurchaseDeleteRequest ( - val deleteKeys: List -): CoreRequest() \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt deleted file mode 100644 index 6f78181..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseRequest.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.hanghea99.commerce.api.purchase.domain - -import com.hanghea99.commerce.api.common.domain.core.CoreRequest -import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo - -data class PostPurchaseRequest(val purchase:PurchaseVo) : - CoreRequest() diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt deleted file mode 100644 index ede139c..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseResponse.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.hanghea99.commerce.api.purchase.domain - -import com.hanghea99.commerce.api.common.ResultCodeMsg -import com.hanghea99.commerce.api.common.domain.core.CoreResponse -import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo - -data class PostPurchaseResponse ( - var resultCodeMsg: ResultCodeMsg, override var result: PurchaseVo -) : CoreResponse(resultCodeMsg.code, resultCodeMsg.msg, result) { - -} diff --git a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt b/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt deleted file mode 100644 index ca8cbbc..0000000 --- a/src/main/kotlin/com/hanghea99/commerce/api/purchase/domain/PostPurchaseUpdateRequest.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.hanghea99.commerce.api.purchase.domain - -import com.hanghea99.commerce.api.common.domain.core.CoreRequest -import com.hanghea99.commerce.api.common.domain.purchase.PurchaseVo - -data class PostPurchaseUpdateRequest( - val purchase: PurchaseVo -): CoreRequest() \ No newline at end of file diff --git a/src/test/kotlin/com/hanghea99/commerce/api/purchase/PurchaseControllerTest.kt b/src/test/kotlin/com/hanghea99/commerce/api/purchase/PurchaseControllerTest.kt deleted file mode 100644 index aecae4f..0000000 --- a/src/test/kotlin/com/hanghea99/commerce/api/purchase/PurchaseControllerTest.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.hanghea99.commerce.api.purchase - -import com.fasterxml.jackson.databind.ObjectMapper -import org.junit.jupiter.api.Test - -import org.junit.jupiter.api.Assertions.* -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest -import org.springframework.boot.test.mock.mockito.MockBean -import org.springframework.test.web.servlet.MockMvc -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get -import org.springframework.test.web.servlet.result.MockMvcResultHandlers -import org.springframework.test.web.servlet.result.MockMvcResultMatchers -import org.springframework.util.LinkedMultiValueMap - -@WebMvcTest(PurchaseController::class) -class PurchaseControllerTest { - - @Autowired - lateinit var mockMvc: MockMvc - - @Autowired - lateinit var objectMapper: ObjectMapper - - @MockBean - lateinit var purchaseService: PurchaseService - - @Test - fun getPurchase() { - - //GIVEN - val queryParams = LinkedMultiValueMap() - - queryParams.add("types", "NAME") - queryParams.add("values", "테스트") - queryParams.add("page", "1") - queryParams.add("count", "10") - queryParams.add("sort", "LATEST") - - //WHEN //THEN - mockMvc.perform( - get("/api/purchase") - .queryParams(queryParams) - ).andExpectAll( - MockMvcResultMatchers.status().isOk - ).andDo( - MockMvcResultHandlers.print() - ) - } - - @Test - fun getPurchaseService() { - } -} \ No newline at end of file From f2e3c21bd83538dd368fbb13d7d38d360d940d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=82=E1=85=A1=E1=84=91=E1=85=A7=E1=86=BC=E1=84=80?= =?UTF-8?q?=E1=85=B3=E1=86=AB?= Date: Sat, 21 Oct 2023 11:56:04 +0900 Subject: [PATCH 18/19] =?UTF-8?q?=EB=A1=9C=EC=BB=AC=20=EB=A1=9C=EA=B9=85?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 5 ++ .../hanghea99/commerce/CommerceApplication.kt | 1 - .../commerce/common/HttpLogMessage.kt | 65 ++++++++++++++ .../commerce/common/ReqResLogginFilter.kt | 52 +++++++++++ .../database/DataSourceConfig.kt | 41 +++++---- src/main/resources/application-prod.yaml | 20 +++++ src/main/resources/logback.xml | 86 +++++++++++++++++++ 7 files changed, 250 insertions(+), 20 deletions(-) create mode 100644 src/main/kotlin/com/hanghea99/commerce/common/HttpLogMessage.kt create mode 100644 src/main/kotlin/com/hanghea99/commerce/common/ReqResLogginFilter.kt create mode 100644 src/main/resources/logback.xml diff --git a/build.gradle.kts b/build.gradle.kts index fc60a1f..598f409 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -50,6 +50,11 @@ dependencies { implementation("net.ttddyy:datasource-proxy:1.9") + +// // 로그백 의존성 +// implementation(group = "ca.pjer", name = "logback-awslogs-appender", version = "1.6.0") + // 프로퍼티 제어 in xml + implementation("org.codehaus.janino:janino:3.1.7") } tasks.withType { diff --git a/src/main/kotlin/com/hanghea99/commerce/CommerceApplication.kt b/src/main/kotlin/com/hanghea99/commerce/CommerceApplication.kt index a1ad237..4771484 100644 --- a/src/main/kotlin/com/hanghea99/commerce/CommerceApplication.kt +++ b/src/main/kotlin/com/hanghea99/commerce/CommerceApplication.kt @@ -1,7 +1,6 @@ package com.hanghea99.commerce import org.slf4j.LoggerFactory -import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication import org.springframework.data.jpa.repository.config.EnableJpaAuditing diff --git a/src/main/kotlin/com/hanghea99/commerce/common/HttpLogMessage.kt b/src/main/kotlin/com/hanghea99/commerce/common/HttpLogMessage.kt new file mode 100644 index 0000000..ecbced4 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/common/HttpLogMessage.kt @@ -0,0 +1,65 @@ +package com.hanghea99.commerce.common + +import com.fasterxml.jackson.databind.ObjectMapper +import org.springframework.http.HttpStatus +import org.springframework.web.util.ContentCachingRequestWrapper +import org.springframework.web.util.ContentCachingResponseWrapper +import java.lang.StringBuilder +import java.nio.charset.Charset + +data class HttpLogMessage( + val httpMethod: String, + val requestUri: String, + val httpStatus: HttpStatus, + val clientIp: String, + val elapsedTime: Double, + val headers: String?, + val requestParam: String?, + val requestBody: String?, + val responseBody: String?, +) { + companion object { + val objectMapper = ObjectMapper() + + fun createInstance( + requestWrapper: ContentCachingRequestWrapper, + responseWrapper: ContentCachingResponseWrapper, + elapsedTime: Double + ): HttpLogMessage { + val headerMap = mutableMapOf() + val sb = StringBuilder() + for( headerName in requestWrapper.headerNames){ + sb.append("${headerName}=${requestWrapper.getHeader(headerName)} ") +// headerMap[headerName] = requestWrapper.getHeader(headerName) + } + + + + return HttpLogMessage( + httpMethod = requestWrapper.method, + requestUri = requestWrapper.requestURI, + httpStatus = HttpStatus.valueOf(responseWrapper.status), + clientIp = requestWrapper.remoteAddr, + elapsedTime = elapsedTime, +// headers = objectMapper.writeValueAsString(headerMap), + headers = sb.toString(), + requestParam = objectMapper.writeValueAsString(requestWrapper.parameterMap), + requestBody = requestWrapper.contentAsByteArray.toString(charset = Charset.defaultCharset()), + responseBody = responseWrapper.contentAsByteArray.toString(charset = Charset.defaultCharset()), + ) + } + } + + // 이부분은 각자 취향대로 포멧 정하는 것으로,,, + fun toPrettierLog(): String { + return """ + | + |[REQUEST] ${this.httpMethod} ${this.requestUri} ${this.httpStatus} (${this.elapsedTime}) + |>> CLIENT_IP: ${this.clientIp} + |>> HEADERS: ${this.headers} + |>> REQUEST_PARAM: ${this.requestParam} + |>> REQUEST_BODY: ${this.requestBody} + |>> RESPONSE_BODY: ${this.responseBody} + """.trimMargin() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/common/ReqResLogginFilter.kt b/src/main/kotlin/com/hanghea99/commerce/common/ReqResLogginFilter.kt new file mode 100644 index 0000000..a8ab007 --- /dev/null +++ b/src/main/kotlin/com/hanghea99/commerce/common/ReqResLogginFilter.kt @@ -0,0 +1,52 @@ +package com.hanghea99.commerce.common + +import jakarta.servlet.FilterChain +import jakarta.servlet.http.HttpServletRequest +import jakarta.servlet.http.HttpServletResponse +import org.slf4j.MDC +import org.springframework.stereotype.Component +import org.springframework.web.filter.OncePerRequestFilter +import org.springframework.web.util.ContentCachingRequestWrapper +import org.springframework.web.util.ContentCachingResponseWrapper +import java.util.* + +@Component +class ReqResLogginFilter : OncePerRequestFilter() { + private val log = logger + + companion object { + const val REQUEST_ID = "request_id" + } + + override fun doFilterInternal( + request: HttpServletRequest, + response: HttpServletResponse, + filterChain: FilterChain + ) { + val cachingRequestWrapper = ContentCachingRequestWrapper(request) + val cachingResponseWrapper = ContentCachingResponseWrapper(response) + val requestId = UUID.randomUUID().toString().substring(0, 8) + + MDC.put(REQUEST_ID, requestId)// -> MCD 저장시 멀티 스레드 스레드가 바뀌면서 MDC가 날아갈수 있다 req id 꼬일수 있음 + // 올바르게 잘 전달 되는지 테스트 및 확인 필요 + + + val startTime = System.currentTimeMillis() + filterChain.doFilter(cachingRequestWrapper, cachingResponseWrapper) + val end = System.currentTimeMillis() + + try { + log.info(HttpLogMessage.createInstance( + requestWrapper = cachingRequestWrapper, + responseWrapper = cachingResponseWrapper, + elapsedTime = (end - startTime) / 1000.0 + ).toPrettierLog()) + + cachingResponseWrapper.copyBodyToResponse() + } catch (e: Exception) { + log.error("Logging 실패", e) + } + + MDC.remove(REQUEST_ID) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/hanghea99/commerce/configuration/database/DataSourceConfig.kt b/src/main/kotlin/com/hanghea99/commerce/configuration/database/DataSourceConfig.kt index 4c36cf3..9c18e42 100644 --- a/src/main/kotlin/com/hanghea99/commerce/configuration/database/DataSourceConfig.kt +++ b/src/main/kotlin/com/hanghea99/commerce/configuration/database/DataSourceConfig.kt @@ -1,9 +1,8 @@ package com.hanghea99.commerce.configuration.database +import com.hanghea99.commerce.logger import jakarta.persistence.EntityManagerFactory -import net.ttddyy.dsproxy.listener.logging.DefaultQueryLogEntryCreator -import net.ttddyy.dsproxy.listener.logging.SLF4JQueryLoggingListener -import net.ttddyy.dsproxy.listener.logging.SystemOutQueryLoggingListener +import net.ttddyy.dsproxy.listener.logging.* import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder import org.hibernate.cfg.AvailableSettings import org.hibernate.engine.jdbc.internal.FormatStyle @@ -36,6 +35,8 @@ import javax.sql.DataSource ) class DataSourceConfig(var env: Environment) { + val log = logger() + @Primary @Bean(name = ["masterDataSource"]) @ConfigurationProperties(prefix = "spring.datasource.write") @@ -55,14 +56,22 @@ class DataSourceConfig(var env: Environment) { @Qualifier("masterDataSource") masterDataSource: DataSource?, @Qualifier("slaveDataSource") slaveDataSource: DataSource? ): DataSource { - return ReplicationRoutingDataSource(masterDataSource!!, slaveDataSource!!) - } - - private class PrettyQueryEntryCreator : DefaultQueryLogEntryCreator() { - private val formatter = FormatStyle.HIGHLIGHT.formatter - override fun formatQuery(query: String): String { - return formatter.format(query) - } + return ReplicationRoutingDataSource( + ProxyDataSourceBuilder + .create(masterDataSource) + .name("masterDataSource") + .countQuery() + .logQueryBySlf4j(SLF4JLogLevel.ERROR, this.javaClass.name) + .logSlowQueryToSysOut(1, TimeUnit.MINUTES) + .build(), + ProxyDataSourceBuilder + .create(slaveDataSource) + .name("slaveDataSource") + .countQuery() + .logQueryBySlf4j(SLF4JLogLevel.ERROR, this.javaClass.name) + .logSlowQueryToSysOut(1, TimeUnit.MINUTES) + .build() + ) } @Profile("dev|default") @@ -71,25 +80,19 @@ class DataSourceConfig(var env: Environment) { @Qualifier("masterDataSource") masterDataSource: DataSource?, @Qualifier("slaveDataSource") slaveDataSource: DataSource? ): DataSource { - val creator = PrettyQueryEntryCreator() - creator.isMultiline = true - val listener = SystemOutQueryLoggingListener() - listener.queryLogEntryCreator = creator return ReplicationRoutingDataSource( ProxyDataSourceBuilder .create(masterDataSource) .name("masterDataSource") .countQuery() - .multiline() - .listener(listener) + .logQueryBySlf4j(SLF4JLogLevel.INFO, this.javaClass.name) .logSlowQueryToSysOut(1, TimeUnit.MINUTES) .build(), ProxyDataSourceBuilder .create(slaveDataSource) .name("slaveDataSource") .countQuery() - .multiline() - .listener(listener) + .logQueryBySlf4j(SLF4JLogLevel.INFO, this.javaClass.name) .logSlowQueryToSysOut(1, TimeUnit.MINUTES) .build() ) diff --git a/src/main/resources/application-prod.yaml b/src/main/resources/application-prod.yaml index e69de29..f53e512 100644 --- a/src/main/resources/application-prod.yaml +++ b/src/main/resources/application-prod.yaml @@ -0,0 +1,20 @@ +spring: + datasource: + write: + jdbc-url: ${SPRING_DATASOURCE_URL}?serverTimezone=Asia/Seoul + username: ${SPRING_DATASOURCE_USERNAME} + password: ${SPRING_DATASOURCE_PASSWORD} + minimum-idle: 5 + maximum-pool-size: 5 + connection-test-query: SELECT 1 FROM dual + connection-timeout: 5000 + validation-timeout: 5000 + read: + jdbc-url: ${SPRING_DATASOURCE_URL}?serverTimezone=Asia/Seoul + username: ${SPRING_DATASOURCE_USERNAME} + password: ${SPRING_DATASOURCE_PASSWORD} + minimum-idle: 5 + maximum-pool-size: 5 + connection-test-query: SELECT 1 FROM dual + connection-timeout: 5000 + validation-timeout: 5000 \ No newline at end of file diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..5bed231 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + %d{yyyyMMdd'T'HHmmss} %thread %level %logger{15} %msg%n + + + + + + + + + + + + \ No newline at end of file From cb59ffe9d76ed35d92213dab6657711e1c925d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=82=E1=85=A1=E1=84=91=E1=85=A7=E1=86=BC=E1=84=80?= =?UTF-8?q?=E1=85=B3=E1=86=AB?= Date: Tue, 24 Oct 2023 22:15:44 +0900 Subject: [PATCH 19/19] =?UTF-8?q?aws-log=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- src/main/resources/logback.xml | 113 +++++++++++++-------------------- 2 files changed, 45 insertions(+), 70 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 598f409..a4255d4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,7 +52,7 @@ dependencies { implementation("net.ttddyy:datasource-proxy:1.9") // // 로그백 의존성 -// implementation(group = "ca.pjer", name = "logback-awslogs-appender", version = "1.6.0") + implementation(group = "ca.pjer", name = "logback-awslogs-appender", version = "1.6.0") // 프로퍼티 제어 in xml implementation("org.codehaus.janino:janino:3.1.7") } diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 5bed231..084b216 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -1,73 +1,42 @@ + + + INFO + + + %d{yyyyMMdd'T'HHmmss} %thread %level %logger{15} %msg%n + + + + + ${Log_Group_Name:local} + + + + + + ${Log_Group_Name:dev} + + + + + + ${Log_Group_Name:prod} + + + HANGHAE-99 + error- + ap-northeast-2 + 50 + 30000 + 5000 + 0 + ${AWS_ACCESS_KEY} + ${AWS_SECRET_KEY} + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -75,9 +44,15 @@ - - - + + + + + + + + +