Implement contracts
This commit is contained in:
parent
31014d1a0c
commit
efdc50eb1d
33 changed files with 879 additions and 173 deletions
11
model/src/lu/foyer/contracts/Employee.scala
Normal file
11
model/src/lu/foyer/contracts/Employee.scala
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package lu.foyer
|
||||
package contracts
|
||||
|
||||
import zio.schema.*
|
||||
import java.util.Currency
|
||||
|
||||
opaque type EmployeeDisplayName <: String = String
|
||||
object EmployeeDisplayName extends NonBlankString[EmployeeDisplayName]
|
||||
|
||||
final case class Employee(uid: String, displayName: EmployeeDisplayName, email: Email)
|
||||
derives Schema
|
||||
27
model/src/lu/foyer/contracts/FormulaType.scala
Normal file
27
model/src/lu/foyer/contracts/FormulaType.scala
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package lu.foyer
|
||||
package contracts
|
||||
|
||||
import zio.schema.*
|
||||
|
||||
enum FormulaType(val maxCoverage: Long, val basePremium: BigDecimal):
|
||||
case Bronze extends FormulaType(10_000, 600)
|
||||
case Silver extends FormulaType(25_000, 900)
|
||||
case Gold extends FormulaType(250_000, 1500)
|
||||
|
||||
object FormulaType:
|
||||
enum Json:
|
||||
case bronze, silver, gold
|
||||
|
||||
given Schema[FormulaType] = DeriveSchema
|
||||
.gen[Json].transform(
|
||||
{
|
||||
case Json.bronze => FormulaType.Bronze
|
||||
case Json.silver => FormulaType.Silver
|
||||
case Json.gold => FormulaType.Gold
|
||||
},
|
||||
{
|
||||
case FormulaType.Bronze => Json.bronze
|
||||
case FormulaType.Silver => Json.silver
|
||||
case FormulaType.Gold => Json.gold
|
||||
}
|
||||
)
|
||||
8
model/src/lu/foyer/contracts/ProductType.scala
Normal file
8
model/src/lu/foyer/contracts/ProductType.scala
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package lu.foyer
|
||||
package contracts
|
||||
|
||||
import zio.schema.*
|
||||
import zio.schema.annotation.caseName
|
||||
|
||||
enum ProductType derives Schema:
|
||||
@caseName("car") case Car
|
||||
7
model/src/lu/foyer/contracts/TerminationReasonType.scala
Normal file
7
model/src/lu/foyer/contracts/TerminationReasonType.scala
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package lu.foyer
|
||||
package contracts
|
||||
|
||||
import zio.schema.*
|
||||
|
||||
enum TerminationReasonType derives Schema:
|
||||
case Rejected, HolderDeceased, TerminatedByClient
|
||||
16
model/src/lu/foyer/contracts/Vehicle.scala
Normal file
16
model/src/lu/foyer/contracts/Vehicle.scala
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package lu.foyer
|
||||
package contracts
|
||||
|
||||
import zio.schema.*
|
||||
import java.util.Currency
|
||||
|
||||
opaque type VehiclePlate <: String = String
|
||||
object VehiclePlate extends NonBlankString[VehiclePlate]
|
||||
|
||||
opaque type VehicleBrand <: String = String
|
||||
object VehicleBrand extends NonBlankString[VehicleBrand]
|
||||
|
||||
final case class Amount(value: BigDecimal, currency: Currency) derives Schema
|
||||
|
||||
final case class Vehicle(plate: VehiclePlate, brand: VehicleBrand, insuredValue: Amount)
|
||||
derives Schema
|
||||
Loading…
Add table
Add a link
Reference in a new issue