working buy system

This commit is contained in:
2025-06-22 15:58:49 -05:00
parent 782ffb0520
commit 28b3699b3b
2 changed files with 6 additions and 2 deletions
+4 -2
View File
@@ -14,10 +14,12 @@ pub fn buy_cloak(session: &Session, cloak: String) -> Result {
.players
.update_one(
filter,
doc! { "$inc": { "points": -100 }, "$push": { "cloaks": cloak } },
doc! { "$inc": { "coins": -100 }, "$push": { "cloaks": cloak.clone() } },
)
.run()?;
Ok(crate::response::Response::Success)
Ok(crate::response::Response::SuccessfulTransaction(format!(
"cloak={cloak}"
)))
} else {
Err(crate::response::Error::TransactionError(
"Not enough coins".to_string(),
+2
View File
@@ -35,6 +35,7 @@ impl std::fmt::Display for PlayerResponse {
pub enum Response {
Pong,
Success,
SuccessfulTransaction(String),
Player(PlayerResponse),
Players(Vec<PlayerResponse>),
}
@@ -56,6 +57,7 @@ impl std::fmt::Display for Response {
.join("\n")
)
}
Response::SuccessfulTransaction(s) => write!(f, "successful_transaction@{s}"),
}
}
}