diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-03-17 14:14:46 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-03-17 14:14:46 +0100 |
commit | 904c7e40a2d092eea87ca6d9ea80edce8a2aad2a (patch) | |
tree | 9749fbf7ff0b9c887df5439aef793bc31c7f202e /src/commit/models.rs | |
parent | c3522a8d3b0236b3c9358db4160182cc211f8069 (diff) |
feat: add delete commit endpoint
Diffstat (limited to 'src/commit/models.rs')
-rw-r--r-- | src/commit/models.rs | 32 |
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()), + }), + } + } } |