16 lines
494 B
Gleam
16 lines
494 B
Gleam
import gleam/dynamic/decode.{type Decoder}
|
|
import models/ship_cargo_item.{type ShipCargoItem}
|
|
|
|
pub type ShipCargo {
|
|
ShipCargo(capacity: Int, units: Int, inventory: List(ShipCargoItem))
|
|
}
|
|
|
|
pub fn decoder() -> Decoder(ShipCargo) {
|
|
use capacity <- decode.field("capacity", decode.int)
|
|
use units <- decode.field("units", decode.int)
|
|
use inventory <- decode.field(
|
|
"inventory",
|
|
decode.list(ship_cargo_item.decoder()),
|
|
)
|
|
decode.success(ShipCargo(capacity:, units:, inventory:))
|
|
}
|