feat: account strike CRUD API

This commit is contained in:
Paul Makles
2023-05-31 13:39:13 +01:00
parent edfa8e5256
commit a9a5af8cc8
10 changed files with 129 additions and 2 deletions

View File

@@ -17,6 +17,7 @@ auto_derived_partial!(
"PartialAccountStrike"
);
#[allow(clippy::disallowed_methods)]
impl AccountStrike {
/// Update this strike
pub async fn update(&mut self, db: &Database, partial: PartialAccountStrike) -> Result<()> {

View File

@@ -10,6 +10,9 @@ pub trait AbstractAccountStrikes: Sync + Send {
/// Insert new strike into the database
async fn insert_account_strike(&self, strike: &AccountStrike) -> Result<()>;
/// Fetch strike by id
async fn fetch_account_strike(&self, id: &str) -> Result<AccountStrike>;
/// Fetch strikes by user id
async fn fetch_account_strikes_by_user(&self, user_id: &str) -> Result<Vec<AccountStrike>>;

View File

@@ -15,6 +15,11 @@ impl AbstractAccountStrikes for MongoDb {
query!(self, insert_one, COL, &strike).map(|_| ())
}
/// Fetch strike by id
async fn fetch_account_strike(&self, id: &str) -> Result<AccountStrike> {
query!(self, find_one_by_id, COL, id)?.ok_or_else(|| create_error!(NotFound))
}
/// Fetch strikes by user id
async fn fetch_account_strikes_by_user(&self, user_id: &str) -> Result<Vec<AccountStrike>> {
Ok(self

View File

@@ -18,6 +18,15 @@ impl AbstractAccountStrikes for ReferenceDb {
}
}
/// Fetch strike by id
async fn fetch_account_strike(&self, id: &str) -> Result<AccountStrike> {
let strikes = self.account_strikes.lock().await;
strikes
.get(id)
.cloned()
.ok_or_else(|| create_error!(NotFound))
}
/// Fetch strikes by user id
async fn fetch_account_strikes_by_user(&self, user_id: &str) -> Result<Vec<AccountStrike>> {
let strikes = self.account_strikes.lock().await;