From 167a4620fe55edbbcd281b6fabde7f6e5d151ab2 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Fri, 27 Sep 2024 09:27:29 +0200 Subject: [PATCH] api --- lib/api.dart | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/api.dart b/lib/api.dart index 69db310..e42b99d 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -198,7 +198,13 @@ class API { } // /item///stat - Future getStat(String item, String variant) async { + Future getStat(String item, String variant, + {bool full = false}) async { + if (full) { + return FullItemVariantStat(jsonDecode( + await getRequest("$instance/item/$item/$variant/stat?full=true"))); + } + return ItemVariantStat( jsonDecode(await getRequest("$instance/item/$item/$variant/stat"))); } @@ -570,3 +576,28 @@ class GlobalItemStat { var split = iv.split("::"); return (split[0], split[1]); } + +class FullItemVariantStat { + late int amount; + late double totalPrice; + late double expiryRate; + late Map origins; + + FullItemVariantStat(Map json) { + amount = json["amount"]; + totalPrice = json["total_price"]; + expiryRate = json["expiry_rate"]; + origins = (json["origins"] as Map) + .map((key, value) => MapEntry(key, OriginStat(value))); + } +} + +class OriginStat { + late double average_price; + late int inventory; + + OriginStat(Map json) { + average_price = json["average_price"]; + inventory = json["inventory"]; + } +}