28 lines
884 B
Gleam
28 lines
884 B
Gleam
import gleam/dict.{type Dict}
|
|
import gleam/dynamic/decode.{type Decoder}
|
|
import utils/api.{type ApiResponse}
|
|
import utils/auth.{type AgentToken, AgentAuth}
|
|
|
|
pub type GetSupplyChainResponse {
|
|
GetSupplyChainResponse(export_to_import_map: Dict(String, String))
|
|
}
|
|
|
|
fn get_supply_chain_response_decoder() -> Decoder(GetSupplyChainResponse) {
|
|
use export_to_import_map <- decode.field(
|
|
"exportToImportMap",
|
|
decode.dict(decode.string, decode.string),
|
|
)
|
|
decode.success(GetSupplyChainResponse(export_to_import_map:))
|
|
}
|
|
|
|
pub fn get_supply_chain(
|
|
token: AgentToken,
|
|
) -> ApiResponse(GetSupplyChainResponse) {
|
|
let request = api.get(AgentAuth(token), "/market/supply-chain")
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 ->
|
|
api.parse_data_response(response, get_supply_chain_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|