summaryrefslogtreecommitdiff
path: root/src/commit/models.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commit/models.rs')
-rw-r--r--src/commit/models.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/commit/models.rs b/src/commit/models.rs
index c70ecf2..8b81a15 100644
--- a/src/commit/models.rs
+++ b/src/commit/models.rs
@@ -61,4 +61,36 @@ impl Commit {
}),
}
}
+
+ /// Find a commit and delete it, but before check if "Authorization"
+ /// matches with SECRET_KEY
+ pub async fn delete(
+ pool: Pool,
+ hash: &String,
+ ) -> Result<Commit, AppError> {
+ let client = get_client(pool.clone()).await.unwrap();
+ let statement = client
+ .prepare(
+ "
+ DELETE FROM commit
+ WHERE hash=$1
+ RETURNING *
+ ",
+ )
+ .await?;
+
+ let commit = client
+ .query_opt(&statement, &[&hash])
+ .await?
+ .map(|row| Commit::from_row_ref(&row).unwrap());
+
+ match commit {
+ Some(commit) => Ok(commit),
+ None => Err(AppError {
+ error_type: AppErrorType::NotFoundError,
+ cause: None,
+ message: Some("Commit not found".to_string()),
+ }),
+ }
+ }
}