feat(fifa17): add purchase_items to host CoreEconomy client
Complete the transport contract: purchase_items (atomic debit + mint N) on the CoreEconomy trait + HttpCoreClient (POST /economy/purchase-items) + FakeEconomy. This is the open-on-buy primitive the Store BUY handler will use (createPackResponse returns the minted itemList). Fail-closed like the rest of the client.
This commit is contained in:
@@ -399,6 +399,8 @@ pub trait CoreEconomy: Send + Sync {
|
|||||||
fn sell_item(&self, item_id: &str, price: i64) -> Result<i64, CoreError>;
|
fn sell_item(&self, item_id: &str, price: i64) -> Result<i64, CoreError>;
|
||||||
fn grant_reward(&self, amount: i64) -> Result<i64, CoreError>;
|
fn grant_reward(&self, amount: i64) -> Result<i64, CoreError>;
|
||||||
fn purchase_item(&self, cost: i64, item_id: &str, card_id: &str) -> Result<i64, CoreError>;
|
fn purchase_item(&self, cost: i64, item_id: &str, card_id: &str) -> Result<i64, CoreError>;
|
||||||
|
/// Debit `cost` and mint several items atomically (open-on-buy Store packs).
|
||||||
|
fn purchase_items(&self, cost: i64, items: &[EconomyGrantItem]) -> Result<i64, CoreError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HttpCoreClient {
|
impl HttpCoreClient {
|
||||||
@@ -517,6 +519,18 @@ impl CoreEconomy for HttpCoreClient {
|
|||||||
)?;
|
)?;
|
||||||
json_i64(&v, "balance")
|
json_i64(&v, "balance")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn purchase_items(&self, cost: i64, items: &[EconomyGrantItem]) -> Result<i64, CoreError> {
|
||||||
|
let items_json: Vec<Value> = items
|
||||||
|
.iter()
|
||||||
|
.map(|i| json!({ "item_id": i.item_id, "card_id": i.card_id }))
|
||||||
|
.collect();
|
||||||
|
let v = self.economy_post(
|
||||||
|
"purchase-items",
|
||||||
|
&json!({ "cost": cost, "items": items_json }),
|
||||||
|
)?;
|
||||||
|
json_i64(&v, "balance")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serialize a [`CoreReplaceRequest`] into the `PUT /squad/replace` JSON body.
|
/// Serialize a [`CoreReplaceRequest`] into the `PUT /squad/replace` JSON body.
|
||||||
@@ -2215,6 +2229,16 @@ mod tests {
|
|||||||
}
|
}
|
||||||
Ok(self.balance)
|
Ok(self.balance)
|
||||||
}
|
}
|
||||||
|
fn purchase_items(
|
||||||
|
&self,
|
||||||
|
_cost: i64,
|
||||||
|
_items: &[EconomyGrantItem],
|
||||||
|
) -> Result<i64, CoreError> {
|
||||||
|
if self.fail {
|
||||||
|
return Err(CoreError::Status(500));
|
||||||
|
}
|
||||||
|
Ok(self.balance)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user