working buy system
This commit is contained in:
+4
-2
@@ -14,10 +14,12 @@ pub fn buy_cloak(session: &Session, cloak: String) -> Result {
|
|||||||
.players
|
.players
|
||||||
.update_one(
|
.update_one(
|
||||||
filter,
|
filter,
|
||||||
doc! { "$inc": { "points": -100 }, "$push": { "cloaks": cloak } },
|
doc! { "$inc": { "coins": -100 }, "$push": { "cloaks": cloak.clone() } },
|
||||||
)
|
)
|
||||||
.run()?;
|
.run()?;
|
||||||
Ok(crate::response::Response::Success)
|
Ok(crate::response::Response::SuccessfulTransaction(format!(
|
||||||
|
"cloak={cloak}"
|
||||||
|
)))
|
||||||
} else {
|
} else {
|
||||||
Err(crate::response::Error::TransactionError(
|
Err(crate::response::Error::TransactionError(
|
||||||
"Not enough coins".to_string(),
|
"Not enough coins".to_string(),
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ impl std::fmt::Display for PlayerResponse {
|
|||||||
pub enum Response {
|
pub enum Response {
|
||||||
Pong,
|
Pong,
|
||||||
Success,
|
Success,
|
||||||
|
SuccessfulTransaction(String),
|
||||||
Player(PlayerResponse),
|
Player(PlayerResponse),
|
||||||
Players(Vec<PlayerResponse>),
|
Players(Vec<PlayerResponse>),
|
||||||
}
|
}
|
||||||
@@ -56,6 +57,7 @@ impl std::fmt::Display for Response {
|
|||||||
.join("\n")
|
.join("\n")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Response::SuccessfulTransaction(s) => write!(f, "successful_transaction@{s}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user