mirror of
https://github.com/Dannecron/spring-boot-demo.git
synced 2025-12-26 08:42:33 +03:00
add city table, improve dto
This commit is contained in:
@@ -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?,
|
||||
)
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user