Fix supply chain endpoint
Some checks are pending
test / test (push) Waiting to run

This commit is contained in:
LilyRose2798 2025-06-18 13:04:55 +10:00
parent 6d108149d7
commit 2c607f64bc
2 changed files with 14 additions and 7 deletions

View file

@ -1,25 +1,27 @@
import gleam/dict.{type Dict} import gleam/dict.{type Dict}
import gleam/dynamic/decode.{type Decoder} import gleam/dynamic/decode.{type Decoder}
import models/trade_symbol.{type TradeSymbol}
import utils/api.{type ApiResponse} import utils/api.{type ApiResponse}
import utils/auth.{type AgentToken, AgentAuth} import utils/auth.{NoAuth}
pub type GetSupplyChainResponse { 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) { fn get_supply_chain_response_decoder() -> Decoder(GetSupplyChainResponse) {
use export_to_import_map <- decode.field( use export_to_import_map <- decode.field(
"exportToImportMap", "exportToImportMap",
decode.dict(decode.string, decode.string), decode.dict(trade_symbol.decoder(), decode.list(trade_symbol.decoder())),
) )
decode.success(GetSupplyChainResponse(export_to_import_map:)) decode.success(GetSupplyChainResponse(export_to_import_map:))
} }
pub fn get_supply_chain( pub fn get_supply_chain() -> ApiResponse(GetSupplyChainResponse) {
token: AgentToken, let request = api.get(NoAuth, "/market/supply-chain")
) -> ApiResponse(GetSupplyChainResponse) {
let request = api.get(AgentAuth(token), "/market/supply-chain")
use response <- api.try_send(request) use response <- api.try_send(request)
echo response.body
case response.status { case response.status {
200 -> 200 ->
api.parse_data_response(response, get_supply_chain_response_decoder()) api.parse_data_response(response, get_supply_chain_response_decoder())

View file

@ -1,4 +1,5 @@
import endpoints/accounts import endpoints/accounts
import endpoints/data
import endpoints/global import endpoints/global
import env import env
import gleeunit import gleeunit
@ -18,3 +19,7 @@ pub fn error_codes_test() {
pub fn account_test() { pub fn account_test() {
let assert Ok(_) = accounts.get_account(env.load_dotenv_unsafe().agent_token) let assert Ok(_) = accounts.get_account(env.load_dotenv_unsafe().agent_token)
} }
pub fn supply_chain_test() {
let assert Ok(_) = data.get_supply_chain()
}