30 lines
853 B
Gleam
30 lines
853 B
Gleam
import birl.{type Time}
|
|
import gleam/dynamic/decode.{type Decoder}
|
|
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
|
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
|
import spacetraders_sdk/internal/time
|
|
|
|
pub type ChartTransaction {
|
|
ChartTransaction(
|
|
waypoint_symbol: WaypointSymbol,
|
|
ship_symbol: ShipSymbol,
|
|
total_price: Int,
|
|
timestamp: Time,
|
|
)
|
|
}
|
|
|
|
pub fn decoder() -> Decoder(ChartTransaction) {
|
|
use waypoint_symbol <- decode.field(
|
|
"waypointSymbol",
|
|
waypoint_symbol.decoder(),
|
|
)
|
|
use ship_symbol <- decode.field("shipSymbol", ship_symbol.decoder())
|
|
use total_price <- decode.field("totalPrice", decode.int)
|
|
use timestamp <- decode.field("timestamp", time.datetime_decoder())
|
|
decode.success(ChartTransaction(
|
|
waypoint_symbol:,
|
|
ship_symbol:,
|
|
total_price:,
|
|
timestamp:,
|
|
))
|
|
}
|