mirror of
https://github.com/Dannecron/spring-boot-demo.git
synced 2025-12-26 00:32:34 +03:00
trying to add order and order_product tables
with dtos, repositories and service
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.github.dannecron.demo.models
|
||||
|
||||
data class CustomerLocal(val name: String, val city: City, val orders: List<Order>) {
|
||||
data class CustomerLocal(val name: String, val city: City, val orders: List<OrderLocal>) {
|
||||
/**
|
||||
* Return the most expensive product among all delivered products
|
||||
*/
|
||||
|
||||
@@ -1,3 +1,31 @@
|
||||
package com.github.dannecron.demo.models
|
||||
|
||||
data class Order(val products: List<Product>, val isDelivered: Boolean)
|
||||
import com.github.dannecron.demo.services.serializables.OffsetDateTimeSerialization
|
||||
import com.github.dannecron.demo.services.serializables.UuidSerialization
|
||||
import kotlinx.serialization.Serializable
|
||||
import org.springframework.data.annotation.Id
|
||||
import org.springframework.data.relational.core.mapping.Column
|
||||
import org.springframework.data.relational.core.mapping.Table
|
||||
import java.time.OffsetDateTime
|
||||
import java.util.*
|
||||
|
||||
@Table(value = "order")
|
||||
@Serializable
|
||||
data class Order(
|
||||
@Id
|
||||
val id: Long?,
|
||||
@Serializable(with = UuidSerialization::class)
|
||||
val guid: UUID,
|
||||
val customerId: Long,
|
||||
@Serializable(with = OffsetDateTimeSerialization::class)
|
||||
@Column(value = "delivered_at")
|
||||
val deliveredAt: OffsetDateTime?,
|
||||
@Serializable(with = OffsetDateTimeSerialization::class)
|
||||
@Column(value = "created_at")
|
||||
val createdAt: OffsetDateTime,
|
||||
@Serializable(with = OffsetDateTimeSerialization::class)
|
||||
@Column(value = "updated_at")
|
||||
val updatedAt: OffsetDateTime?
|
||||
) {
|
||||
fun isDelivered(): Boolean = deliveredAt != null
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.github.dannecron.demo.models
|
||||
|
||||
data class OrderLocal(val products: List<Product>, val isDelivered: Boolean)
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.github.dannecron.demo.models
|
||||
|
||||
import com.github.dannecron.demo.services.serializables.OffsetDateTimeSerialization
|
||||
import com.github.dannecron.demo.services.serializables.UuidSerialization
|
||||
import kotlinx.serialization.Serializable
|
||||
import org.springframework.data.annotation.Id
|
||||
import org.springframework.data.annotation.Transient
|
||||
import org.springframework.data.domain.Persistable
|
||||
import org.springframework.data.relational.core.mapping.Column
|
||||
import org.springframework.data.relational.core.mapping.Table
|
||||
import java.time.OffsetDateTime
|
||||
import java.util.*
|
||||
|
||||
@Table(value = "order_product")
|
||||
@Serializable
|
||||
data class OrderProduct(
|
||||
@Id
|
||||
@Serializable(with = UuidSerialization::class)
|
||||
val guid: UUID,
|
||||
@Column(value = "order_id")
|
||||
val orderId: Long,
|
||||
@Column(value = "product_id")
|
||||
val productId: Long,
|
||||
@Serializable(with = OffsetDateTimeSerialization::class)
|
||||
@Column(value = "created_at")
|
||||
val createdAt: OffsetDateTime,
|
||||
@Serializable(with = OffsetDateTimeSerialization::class)
|
||||
@Column(value = "updated_at")
|
||||
val updatedAt: OffsetDateTime?,
|
||||
): Persistable<UUID> {
|
||||
@Transient
|
||||
var isNewInstance: Boolean? = null
|
||||
|
||||
override fun getId(): UUID {
|
||||
return guid
|
||||
}
|
||||
|
||||
override fun isNew(): Boolean {
|
||||
return isNewInstance ?: true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user