From b4764fc85c36f5cac6a2a43413da8ad374519fd8 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 22 Sep 2022 17:08:54 +0200 Subject: Delete model uploads --- src/models/model.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/models/model.rs') diff --git a/src/models/model.rs b/src/models/model.rs index 469356f..9d463b1 100644 --- a/src/models/model.rs +++ b/src/models/model.rs @@ -59,8 +59,8 @@ pub struct ModelUser { #[derive(Deserialize, Serialize, sqlx::FromRow)] pub struct ModelUpload { id: i32, - model_id: i32, - filepath: String, + pub model_id: i32, + pub filepath: String, created: NaiveDateTime, } @@ -270,4 +270,36 @@ impl ModelUpload { Ok(rec) } + + /// Returns the model upload with id = `upload_id` + pub async fn find_by_id(id: i32) -> Result { + let pool = unsafe { get_client() }; + + let rec: ModelUpload = sqlx::query_as( + r#" + SELECT * FROM uploads WHERE id = $1 + "#, + ) + .bind(id) + .fetch_one(pool) + .await?; + + Ok(rec) + } + + /// Delete a model upload + pub async fn delete(upload_id: i32) -> Result<(), AppError> { + let pool = unsafe { get_client() }; + + sqlx::query( + r#" + DELETE FROM uploads WHERE id = $1 + "#, + ) + .bind(upload_id) + .execute(pool) + .await?; + + Ok(()) + } } -- cgit v1.2.3-71-g8e6c