44 lines
1.3 KiB
Gleam
44 lines
1.3 KiB
Gleam
import birl.{type Time}
|
|
import gleam/dynamic/decode.{type Decoder}
|
|
import models/ship_symbol.{type ShipSymbol}
|
|
import models/trade_symbol.{type TradeSymbol}
|
|
import models/transaction_type.{type TransactionType}
|
|
import models/waypoint_symbol.{type WaypointSymbol}
|
|
import utils/api
|
|
|
|
pub type MarketTransaction {
|
|
MarketTransaction(
|
|
waypoint_symbol: WaypointSymbol,
|
|
ship_symbol: ShipSymbol,
|
|
trade_symbol: TradeSymbol,
|
|
type_: TransactionType,
|
|
units: Int,
|
|
price_per_unit: Int,
|
|
total_price: Int,
|
|
timestamp: Time,
|
|
)
|
|
}
|
|
|
|
pub fn decoder() -> Decoder(MarketTransaction) {
|
|
use waypoint_symbol <- decode.field(
|
|
"waypointSymbol",
|
|
waypoint_symbol.decoder(),
|
|
)
|
|
use ship_symbol <- decode.field("shipSymbol", ship_symbol.decoder())
|
|
use trade_symbol <- decode.field("tradeSymbol", trade_symbol.decoder())
|
|
use type_ <- decode.field("type", transaction_type.decoder())
|
|
use units <- decode.field("units", decode.int)
|
|
use price_per_unit <- decode.field("pricePerUnit", decode.int)
|
|
use total_price <- decode.field("totalPrice", decode.int)
|
|
use timestamp <- decode.field("timestamp", api.time_decoder())
|
|
decode.success(MarketTransaction(
|
|
waypoint_symbol:,
|
|
ship_symbol:,
|
|
trade_symbol:,
|
|
type_:,
|
|
units:,
|
|
price_per_unit:,
|
|
total_price:,
|
|
timestamp:,
|
|
))
|
|
}
|