This commit is contained in:
parent
6d108149d7
commit
2c607f64bc
2 changed files with 14 additions and 7 deletions
|
@ -1,25 +1,27 @@
|
|||
import gleam/dict.{type Dict}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
import utils/api.{type ApiResponse}
|
||||
import utils/auth.{type AgentToken, AgentAuth}
|
||||
import utils/auth.{NoAuth}
|
||||
|
||||
pub type GetSupplyChainResponse {
|
||||
GetSupplyChainResponse(export_to_import_map: Dict(String, String))
|
||||
GetSupplyChainResponse(
|
||||
export_to_import_map: Dict(TradeSymbol, List(TradeSymbol)),
|
||||
)
|
||||
}
|
||||
|
||||
fn get_supply_chain_response_decoder() -> Decoder(GetSupplyChainResponse) {
|
||||
use export_to_import_map <- decode.field(
|
||||
"exportToImportMap",
|
||||
decode.dict(decode.string, decode.string),
|
||||
decode.dict(trade_symbol.decoder(), decode.list(trade_symbol.decoder())),
|
||||
)
|
||||
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")
|
||||
pub fn get_supply_chain() -> ApiResponse(GetSupplyChainResponse) {
|
||||
let request = api.get(NoAuth, "/market/supply-chain")
|
||||
use response <- api.try_send(request)
|
||||
echo response.body
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_data_response(response, get_supply_chain_response_decoder())
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import endpoints/accounts
|
||||
import endpoints/data
|
||||
import endpoints/global
|
||||
import env
|
||||
import gleeunit
|
||||
|
@ -18,3 +19,7 @@ pub fn error_codes_test() {
|
|||
pub fn account_test() {
|
||||
let assert Ok(_) = accounts.get_account(env.load_dotenv_unsafe().agent_token)
|
||||
}
|
||||
|
||||
pub fn supply_chain_test() {
|
||||
let assert Ok(_) = data.get_supply_chain()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue