From b855aba506a9f1f52bcc7d9d5a30f8d3fb41fd1b Mon Sep 17 00:00:00 2001 From: Savosin Denis Date: Tue, 6 May 2025 14:08:14 +0700 Subject: [PATCH] db dto = entity --- .../demo/db/entity/{City.kt => CityEntity.kt} | 6 ++---- .../demo/db/entity/{Customer.kt => CustomerEntity.kt} | 2 +- .../demo/db/entity/{Product.kt => ProductEntity.kt} | 2 +- .../demo/db/entity/order/{Order.kt => OrderEntity.kt} | 2 +- .../order/{OrderProduct.kt => OrderProductEntity.kt} | 2 +- .../dannecron/demo/db/repository/CityRepository.kt | 8 ++++---- .../dannecron/demo/db/repository/CustomerRepository.kt | 6 +++--- .../demo/db/repository/OrderProductRepository.kt | 6 +++--- .../dannecron/demo/db/repository/OrderRepository.kt | 6 +++--- .../dannecron/demo/db/repository/ProductRepository.kt | 8 ++++---- ...tyRepositoryTest.kt => CityEntityRepositoryTest.kt} | 10 +++++----- ...positoryTest.kt => CustomerEntityRepositoryTest.kt} | 8 ++++---- ...st.kt => OrderEntityProductEntityRepositoryTest.kt} | 8 ++++---- ...rRepositoryTest.kt => OrderEntityRepositoryTest.kt} | 8 ++++---- ...epositoryTest.kt => ProductEntityRepositoryTest.kt} | 8 ++++---- 15 files changed, 44 insertions(+), 46 deletions(-) rename db/src/main/kotlin/com/github/dannecron/demo/db/entity/{City.kt => CityEntity.kt} (93%) rename db/src/main/kotlin/com/github/dannecron/demo/db/entity/{Customer.kt => CustomerEntity.kt} (97%) rename db/src/main/kotlin/com/github/dannecron/demo/db/entity/{Product.kt => ProductEntity.kt} (98%) rename db/src/main/kotlin/com/github/dannecron/demo/db/entity/order/{Order.kt => OrderEntity.kt} (97%) rename db/src/main/kotlin/com/github/dannecron/demo/db/entity/order/{OrderProduct.kt => OrderProductEntity.kt} (97%) rename db/src/test/kotlin/com/github/dannecron/demo/db/repository/{CityRepositoryTest.kt => CityEntityRepositoryTest.kt} (84%) rename db/src/test/kotlin/com/github/dannecron/demo/db/repository/{CustomerRepositoryTest.kt => CustomerEntityRepositoryTest.kt} (84%) rename db/src/test/kotlin/com/github/dannecron/demo/db/repository/{OrderProductRepositoryTest.kt => OrderEntityProductEntityRepositoryTest.kt} (83%) rename db/src/test/kotlin/com/github/dannecron/demo/db/repository/{OrderRepositoryTest.kt => OrderEntityRepositoryTest.kt} (85%) rename db/src/test/kotlin/com/github/dannecron/demo/db/repository/{ProductRepositoryTest.kt => ProductEntityRepositoryTest.kt} (85%) diff --git a/db/src/main/kotlin/com/github/dannecron/demo/db/entity/City.kt b/db/src/main/kotlin/com/github/dannecron/demo/db/entity/CityEntity.kt similarity index 93% rename from db/src/main/kotlin/com/github/dannecron/demo/db/entity/City.kt rename to db/src/main/kotlin/com/github/dannecron/demo/db/entity/CityEntity.kt index 543f8b2..5266455 100644 --- a/db/src/main/kotlin/com/github/dannecron/demo/db/entity/City.kt +++ b/db/src/main/kotlin/com/github/dannecron/demo/db/entity/CityEntity.kt @@ -11,7 +11,7 @@ import java.util.UUID @Table("city") @Serializable -data class City( +data class CityEntity( @Id val id: Long?, @Serializable(with = UuidSerialization::class) @@ -26,6 +26,4 @@ data class City( @Serializable(with = OffsetDateTimeSerialization::class) @Column(value = "deleted_at") val deletedAt: OffsetDateTime?, -) { - fun isDeleted(): Boolean = deletedAt != null -} +) diff --git a/db/src/main/kotlin/com/github/dannecron/demo/db/entity/Customer.kt b/db/src/main/kotlin/com/github/dannecron/demo/db/entity/CustomerEntity.kt similarity index 97% rename from db/src/main/kotlin/com/github/dannecron/demo/db/entity/Customer.kt rename to db/src/main/kotlin/com/github/dannecron/demo/db/entity/CustomerEntity.kt index ddbde0f..257c2a4 100644 --- a/db/src/main/kotlin/com/github/dannecron/demo/db/entity/Customer.kt +++ b/db/src/main/kotlin/com/github/dannecron/demo/db/entity/CustomerEntity.kt @@ -11,7 +11,7 @@ import java.util.UUID @Table("customer") @Serializable -data class Customer( +data class CustomerEntity( @Id val id: Long?, @Serializable(with = UuidSerialization::class) diff --git a/db/src/main/kotlin/com/github/dannecron/demo/db/entity/Product.kt b/db/src/main/kotlin/com/github/dannecron/demo/db/entity/ProductEntity.kt similarity index 98% rename from db/src/main/kotlin/com/github/dannecron/demo/db/entity/Product.kt rename to db/src/main/kotlin/com/github/dannecron/demo/db/entity/ProductEntity.kt index b2d7d26..1881f6a 100644 --- a/db/src/main/kotlin/com/github/dannecron/demo/db/entity/Product.kt +++ b/db/src/main/kotlin/com/github/dannecron/demo/db/entity/ProductEntity.kt @@ -13,7 +13,7 @@ import kotlin.math.roundToInt @Table(value = "product") @Serializable -data class Product( +data class ProductEntity( @Id val id: Long?, @Serializable(with = UuidSerialization::class) diff --git a/db/src/main/kotlin/com/github/dannecron/demo/db/entity/order/Order.kt b/db/src/main/kotlin/com/github/dannecron/demo/db/entity/order/OrderEntity.kt similarity index 97% rename from db/src/main/kotlin/com/github/dannecron/demo/db/entity/order/Order.kt rename to db/src/main/kotlin/com/github/dannecron/demo/db/entity/order/OrderEntity.kt index 984a3b2..5422d07 100644 --- a/db/src/main/kotlin/com/github/dannecron/demo/db/entity/order/Order.kt +++ b/db/src/main/kotlin/com/github/dannecron/demo/db/entity/order/OrderEntity.kt @@ -11,7 +11,7 @@ import java.util.UUID @Table(value = "order") @Serializable -data class Order( +data class OrderEntity( @Id val id: Long?, @Serializable(with = UuidSerialization::class) diff --git a/db/src/main/kotlin/com/github/dannecron/demo/db/entity/order/OrderProduct.kt b/db/src/main/kotlin/com/github/dannecron/demo/db/entity/order/OrderProductEntity.kt similarity index 97% rename from db/src/main/kotlin/com/github/dannecron/demo/db/entity/order/OrderProduct.kt rename to db/src/main/kotlin/com/github/dannecron/demo/db/entity/order/OrderProductEntity.kt index a6b42ac..0ca7500 100644 --- a/db/src/main/kotlin/com/github/dannecron/demo/db/entity/order/OrderProduct.kt +++ b/db/src/main/kotlin/com/github/dannecron/demo/db/entity/order/OrderProductEntity.kt @@ -13,7 +13,7 @@ import java.util.UUID @Table(value = "order_product") @Serializable -data class OrderProduct( +data class OrderProductEntity( @Id @Serializable(with = UuidSerialization::class) val guid: UUID, diff --git a/db/src/main/kotlin/com/github/dannecron/demo/db/repository/CityRepository.kt b/db/src/main/kotlin/com/github/dannecron/demo/db/repository/CityRepository.kt index 9ec47ad..63f8a13 100644 --- a/db/src/main/kotlin/com/github/dannecron/demo/db/repository/CityRepository.kt +++ b/db/src/main/kotlin/com/github/dannecron/demo/db/repository/CityRepository.kt @@ -1,6 +1,6 @@ package com.github.dannecron.demo.db.repository -import com.github.dannecron.demo.db.entity.City +import com.github.dannecron.demo.db.entity.CityEntity import org.springframework.data.jdbc.repository.query.Query import org.springframework.data.repository.CrudRepository import org.springframework.data.repository.query.Param @@ -9,9 +9,9 @@ import java.time.OffsetDateTime import java.util.UUID @Repository -interface CityRepository: CrudRepository { - fun findByGuid(guid: UUID): City? +interface CityRepository: CrudRepository { + fun findByGuid(guid: UUID): CityEntity? @Query(value = "UPDATE city SET deleted_at = :deletedAt WHERE guid = :guid RETURNING *") - fun softDelete(@Param("guid") guid: UUID, @Param("deletedAt") deletedAt: OffsetDateTime): City? + fun softDelete(@Param("guid") guid: UUID, @Param("deletedAt") deletedAt: OffsetDateTime): CityEntity? } diff --git a/db/src/main/kotlin/com/github/dannecron/demo/db/repository/CustomerRepository.kt b/db/src/main/kotlin/com/github/dannecron/demo/db/repository/CustomerRepository.kt index 065eca0..41fb9b5 100644 --- a/db/src/main/kotlin/com/github/dannecron/demo/db/repository/CustomerRepository.kt +++ b/db/src/main/kotlin/com/github/dannecron/demo/db/repository/CustomerRepository.kt @@ -1,11 +1,11 @@ package com.github.dannecron.demo.db.repository -import com.github.dannecron.demo.db.entity.Customer +import com.github.dannecron.demo.db.entity.CustomerEntity import org.springframework.data.repository.CrudRepository import org.springframework.stereotype.Repository import java.util.UUID @Repository -interface CustomerRepository: CrudRepository { - fun findByGuid(guid: UUID): Customer? +interface CustomerRepository: CrudRepository { + fun findByGuid(guid: UUID): CustomerEntity? } diff --git a/db/src/main/kotlin/com/github/dannecron/demo/db/repository/OrderProductRepository.kt b/db/src/main/kotlin/com/github/dannecron/demo/db/repository/OrderProductRepository.kt index 90a6c85..3d88bb3 100644 --- a/db/src/main/kotlin/com/github/dannecron/demo/db/repository/OrderProductRepository.kt +++ b/db/src/main/kotlin/com/github/dannecron/demo/db/repository/OrderProductRepository.kt @@ -1,11 +1,11 @@ package com.github.dannecron.demo.db.repository -import com.github.dannecron.demo.db.entity.order.OrderProduct +import com.github.dannecron.demo.db.entity.order.OrderProductEntity import org.springframework.data.repository.CrudRepository import org.springframework.stereotype.Repository import java.util.UUID @Repository -interface OrderProductRepository: CrudRepository { - fun findByOrderId(orderId: Long): List +interface OrderProductRepository: CrudRepository { + fun findByOrderId(orderId: Long): List } diff --git a/db/src/main/kotlin/com/github/dannecron/demo/db/repository/OrderRepository.kt b/db/src/main/kotlin/com/github/dannecron/demo/db/repository/OrderRepository.kt index 05a8079..02384f9 100644 --- a/db/src/main/kotlin/com/github/dannecron/demo/db/repository/OrderRepository.kt +++ b/db/src/main/kotlin/com/github/dannecron/demo/db/repository/OrderRepository.kt @@ -1,10 +1,10 @@ package com.github.dannecron.demo.db.repository -import com.github.dannecron.demo.db.entity.order.Order +import com.github.dannecron.demo.db.entity.order.OrderEntity import org.springframework.data.repository.CrudRepository import org.springframework.stereotype.Repository @Repository -interface OrderRepository: CrudRepository { - fun findByCustomerId(customerId: Long): List +interface OrderRepository: CrudRepository { + fun findByCustomerId(customerId: Long): List } diff --git a/db/src/main/kotlin/com/github/dannecron/demo/db/repository/ProductRepository.kt b/db/src/main/kotlin/com/github/dannecron/demo/db/repository/ProductRepository.kt index d7407f7..2d2a354 100644 --- a/db/src/main/kotlin/com/github/dannecron/demo/db/repository/ProductRepository.kt +++ b/db/src/main/kotlin/com/github/dannecron/demo/db/repository/ProductRepository.kt @@ -1,6 +1,6 @@ package com.github.dannecron.demo.db.repository -import com.github.dannecron.demo.db.entity.Product +import com.github.dannecron.demo.db.entity.ProductEntity import org.springframework.data.jdbc.repository.query.Query import org.springframework.data.repository.CrudRepository import org.springframework.data.repository.PagingAndSortingRepository @@ -9,9 +9,9 @@ import java.time.OffsetDateTime import java.util.UUID @Repository -interface ProductRepository: CrudRepository, PagingAndSortingRepository { - fun findByGuid(guid: UUID): Product? +interface ProductRepository: CrudRepository, PagingAndSortingRepository { + fun findByGuid(guid: UUID): ProductEntity? @Query(value = "UPDATE Product SET deleted_at = :deletedAt WHERE guid = :guid RETURNING *") - fun softDelete(guid: UUID, deletedAt: OffsetDateTime): Product? + fun softDelete(guid: UUID, deletedAt: OffsetDateTime): ProductEntity? } diff --git a/db/src/test/kotlin/com/github/dannecron/demo/db/repository/CityRepositoryTest.kt b/db/src/test/kotlin/com/github/dannecron/demo/db/repository/CityEntityRepositoryTest.kt similarity index 84% rename from db/src/test/kotlin/com/github/dannecron/demo/db/repository/CityRepositoryTest.kt rename to db/src/test/kotlin/com/github/dannecron/demo/db/repository/CityEntityRepositoryTest.kt index d9a9ba2..730a129 100644 --- a/db/src/test/kotlin/com/github/dannecron/demo/db/repository/CityRepositoryTest.kt +++ b/db/src/test/kotlin/com/github/dannecron/demo/db/repository/CityEntityRepositoryTest.kt @@ -1,7 +1,7 @@ package com.github.dannecron.demo.db.repository import com.github.dannecron.demo.db.BaseDbTest -import com.github.dannecron.demo.db.entity.City +import com.github.dannecron.demo.db.entity.CityEntity import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.jdbc.Sql @@ -12,13 +12,13 @@ import kotlin.test.assertEquals import kotlin.test.assertNull @ContextConfiguration(classes = [CityRepository::class]) -class CityRepositoryTest : BaseDbTest() { +class CityEntityRepositoryTest : BaseDbTest() { @Autowired private lateinit var cityRepository: CityRepository private val cityGuid = UUID.fromString("21a1a3a8-621a-40f7-b64f-7e118aa241b9") - private val city = City( + private val cityEntity = CityEntity( id = 1000, guid = cityGuid, name = "Tokyo", @@ -31,7 +31,7 @@ class CityRepositoryTest : BaseDbTest() { @Sql(scripts = ["/sql/insert_city.sql"]) fun findByGuid() { val result = cityRepository.findByGuid(cityGuid) - assertEquals(city, result) + assertEquals(cityEntity, result) val emptyResult = cityRepository.findByGuid(UUID.randomUUID()) assertNull(emptyResult) @@ -41,7 +41,7 @@ class CityRepositoryTest : BaseDbTest() { @Sql(scripts = ["/sql/insert_city.sql"]) fun softDelete() { val deletedAt = OffsetDateTime.parse("2025-01-02T12:10:05+00:00") - val expectedCity = city.copy(deletedAt = deletedAt) + val expectedCity = cityEntity.copy(deletedAt = deletedAt) val result = cityRepository.softDelete(cityGuid, deletedAt) assertEquals(expectedCity, result) diff --git a/db/src/test/kotlin/com/github/dannecron/demo/db/repository/CustomerRepositoryTest.kt b/db/src/test/kotlin/com/github/dannecron/demo/db/repository/CustomerEntityRepositoryTest.kt similarity index 84% rename from db/src/test/kotlin/com/github/dannecron/demo/db/repository/CustomerRepositoryTest.kt rename to db/src/test/kotlin/com/github/dannecron/demo/db/repository/CustomerEntityRepositoryTest.kt index 868b514..63dbc1a 100644 --- a/db/src/test/kotlin/com/github/dannecron/demo/db/repository/CustomerRepositoryTest.kt +++ b/db/src/test/kotlin/com/github/dannecron/demo/db/repository/CustomerEntityRepositoryTest.kt @@ -1,7 +1,7 @@ package com.github.dannecron.demo.db.repository import com.github.dannecron.demo.db.BaseDbTest -import com.github.dannecron.demo.db.entity.Customer +import com.github.dannecron.demo.db.entity.CustomerEntity import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.jdbc.Sql @@ -12,13 +12,13 @@ import kotlin.test.assertEquals import kotlin.test.assertNull @ContextConfiguration(classes = [CustomerRepository::class]) -class CustomerRepositoryTest : BaseDbTest() { +class CustomerEntityRepositoryTest : BaseDbTest() { @Autowired private lateinit var customerRepository: CustomerRepository private val customerGuid = UUID.fromString("823c50de-4c81-49bd-a69a-2d52be42b728") - private val customer = Customer( + private val customerEntity = CustomerEntity( id = 1000, guid = customerGuid, name = "Customer", @@ -31,7 +31,7 @@ class CustomerRepositoryTest : BaseDbTest() { @Sql(scripts = ["/sql/insert_city.sql", "/sql/insert_customer.sql"]) fun findByGuid() { val result = customerRepository.findByGuid(customerGuid) - assertEquals(customer, result) + assertEquals(customerEntity, result) val emptyResult = customerRepository.findByGuid(UUID.randomUUID()) assertNull(emptyResult) diff --git a/db/src/test/kotlin/com/github/dannecron/demo/db/repository/OrderProductRepositoryTest.kt b/db/src/test/kotlin/com/github/dannecron/demo/db/repository/OrderEntityProductEntityRepositoryTest.kt similarity index 83% rename from db/src/test/kotlin/com/github/dannecron/demo/db/repository/OrderProductRepositoryTest.kt rename to db/src/test/kotlin/com/github/dannecron/demo/db/repository/OrderEntityProductEntityRepositoryTest.kt index a6dbe0f..25de0c5 100644 --- a/db/src/test/kotlin/com/github/dannecron/demo/db/repository/OrderProductRepositoryTest.kt +++ b/db/src/test/kotlin/com/github/dannecron/demo/db/repository/OrderEntityProductEntityRepositoryTest.kt @@ -1,7 +1,7 @@ package com.github.dannecron.demo.db.repository import com.github.dannecron.demo.db.BaseDbTest -import com.github.dannecron.demo.db.entity.order.OrderProduct +import com.github.dannecron.demo.db.entity.order.OrderProductEntity import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.jdbc.Sql @@ -11,13 +11,13 @@ import kotlin.test.Test import kotlin.test.assertEquals @ContextConfiguration(classes = [OrderProductRepository::class]) -class OrderProductRepositoryTest : BaseDbTest() { +class OrderEntityProductEntityRepositoryTest : BaseDbTest() { @Autowired private lateinit var orderProductRepository: OrderProductRepository private val orderId = 1000L - private val orderProduct = OrderProduct( + private val orderProductEntity = OrderProductEntity( guid = UUID.fromString("930f54e2-c60d-448e-83b1-0d259ff2c2d3"), orderId = orderId, productId = 1000, @@ -38,6 +38,6 @@ class OrderProductRepositoryTest : BaseDbTest() { fun findByOrderId() { val result = orderProductRepository.findByOrderId(orderId) assertEquals(1, result.size) - assertEquals(orderProduct, result[0]) + assertEquals(orderProductEntity, result[0]) } } diff --git a/db/src/test/kotlin/com/github/dannecron/demo/db/repository/OrderRepositoryTest.kt b/db/src/test/kotlin/com/github/dannecron/demo/db/repository/OrderEntityRepositoryTest.kt similarity index 85% rename from db/src/test/kotlin/com/github/dannecron/demo/db/repository/OrderRepositoryTest.kt rename to db/src/test/kotlin/com/github/dannecron/demo/db/repository/OrderEntityRepositoryTest.kt index 569439d..ae3d657 100644 --- a/db/src/test/kotlin/com/github/dannecron/demo/db/repository/OrderRepositoryTest.kt +++ b/db/src/test/kotlin/com/github/dannecron/demo/db/repository/OrderEntityRepositoryTest.kt @@ -1,7 +1,7 @@ package com.github.dannecron.demo.db.repository import com.github.dannecron.demo.db.BaseDbTest -import com.github.dannecron.demo.db.entity.order.Order +import com.github.dannecron.demo.db.entity.order.OrderEntity import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.jdbc.Sql @@ -11,14 +11,14 @@ import kotlin.test.Test import kotlin.test.assertEquals @ContextConfiguration(classes = [OrderRepository::class]) -class OrderRepositoryTest : BaseDbTest() { +class OrderEntityRepositoryTest : BaseDbTest() { @Autowired private lateinit var orderRepository: OrderRepository private val orderGuid = UUID.fromString("2c960a08-7187-4e91-9ef3-275c91b1342c") private val customerId = 1000L - private val order = Order( + private val orderEntity = OrderEntity( id = 1000, guid = orderGuid, customerId = customerId, @@ -38,6 +38,6 @@ class OrderRepositoryTest : BaseDbTest() { fun findByGuid() { val result = orderRepository.findByCustomerId(customerId) assertEquals(1, result.size) - assertEquals(order, result[0]) + assertEquals(orderEntity, result[0]) } } diff --git a/db/src/test/kotlin/com/github/dannecron/demo/db/repository/ProductRepositoryTest.kt b/db/src/test/kotlin/com/github/dannecron/demo/db/repository/ProductEntityRepositoryTest.kt similarity index 85% rename from db/src/test/kotlin/com/github/dannecron/demo/db/repository/ProductRepositoryTest.kt rename to db/src/test/kotlin/com/github/dannecron/demo/db/repository/ProductEntityRepositoryTest.kt index c8af2c3..cfb9360 100644 --- a/db/src/test/kotlin/com/github/dannecron/demo/db/repository/ProductRepositoryTest.kt +++ b/db/src/test/kotlin/com/github/dannecron/demo/db/repository/ProductEntityRepositoryTest.kt @@ -1,7 +1,7 @@ package com.github.dannecron.demo.db.repository import com.github.dannecron.demo.db.BaseDbTest -import com.github.dannecron.demo.db.entity.Product +import com.github.dannecron.demo.db.entity.ProductEntity import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.jdbc.Sql @@ -12,13 +12,13 @@ import kotlin.test.assertEquals import kotlin.test.assertNull @ContextConfiguration(classes = [ProductRepository::class]) -class ProductRepositoryTest : BaseDbTest() { +class ProductEntityRepositoryTest : BaseDbTest() { @Autowired private lateinit var productRepository: ProductRepository private val productGuid = UUID.fromString("1fb5c7e4-8ce2-43b8-8ca7-1089b04959b9") - private val product = Product( + private val productEntity = ProductEntity( id = 1000, guid = productGuid, name = "product", @@ -33,7 +33,7 @@ class ProductRepositoryTest : BaseDbTest() { @Sql(scripts = ["/sql/insert_product.sql"]) fun findByGuid() { val result = productRepository.findByGuid(productGuid) - assertEquals(product, result) + assertEquals(productEntity, result) val emptyResult = productRepository.findByGuid(UUID.randomUUID()) assertNull(emptyResult)