add city table, improve dto

This commit is contained in:
Denis Savosin
2024-10-01 15:16:13 +07:00
parent f9632ac568
commit dd4389e780
5 changed files with 78 additions and 29 deletions

View File

@@ -1,3 +1,24 @@
package com.example.demo.models
data class City(val name: String)
import com.example.demo.models.serializables.OffsetDateTimeSerialization
import kotlinx.serialization.Serializable
import org.springframework.data.relational.core.mapping.Column
import org.springframework.data.relational.core.mapping.Table
import java.time.OffsetDateTime
import java.util.*
@Table("city")
data class City(
val id: Long?,
val guid: UUID,
val name: String,
@Serializable(with = OffsetDateTimeSerialization::class)
@Column(value = "created_at")
val createdAt: OffsetDateTime,
@Serializable(with = OffsetDateTimeSerialization::class)
@Column(value = "updated_at")
val updatedAt: OffsetDateTime?,
@Serializable(with = OffsetDateTimeSerialization::class)
@Column(value = "deleted_at")
val deletedAt: OffsetDateTime?,
)

View File

@@ -14,7 +14,7 @@ class MockedShopProvider: ShopProvider {
return Shop(name="shop", customers= listOf(
Customer(
name = "Foo-1",
city = City(name= "Bar"),
city = makeCity(id = 1, name = "Foo"),
orders = listOf(
Order(products = listOf(productOne, productTwo), isDelivered = true),
Order(products = listOf(productThree), isDelivered = false),
@@ -22,7 +22,7 @@ class MockedShopProvider: ShopProvider {
),
Customer(
name = "Foo-2",
city = City(name= "Bar"),
city = makeCity(id = 2, name = "Bar"),
orders = listOf(
Order(products = listOf(productOne), isDelivered = false),
Order(products = listOf(productTwo), isDelivered = true),
@@ -32,16 +32,23 @@ class MockedShopProvider: ShopProvider {
))
}
private fun makeProduct(id: Long, name: String, price: Double): Product {
return Product(
id = id,
guid = UUID.randomUUID(),
name = name,
description = null,
price = (price * 100).toLong(),
createdAt = OffsetDateTime.now(),
updatedAt = null,
deletedAt = null,
)
}
private fun makeProduct(id: Long, name: String, price: Double): Product = Product(
id = id,
guid = UUID.randomUUID(),
name = name,
description = null,
price = (price * 100).toLong(),
createdAt = OffsetDateTime.now(),
updatedAt = null,
deletedAt = null,
)
private fun makeCity(id: Long, name: String): City = City(
id = id,
guid = UUID.randomUUID(),
name = name,
createdAt = OffsetDateTime.now(),
updatedAt = null,
deletedAt = null,
)
}