diff options
| author | Santo Cariotti <santo@dcariotti.me> | 2022-09-22 15:08:54 +0000 |
|---|---|---|
| committer | Santo Cariotti <santo@dcariotti.me> | 2022-09-22 15:08:54 +0000 |
| commit | b4764fc85c36f5cac6a2a43413da8ad374519fd8 (patch) | |
| tree | 10e6dad556277e8c7c4cf0eab31143ea3fc5d4b6 /src/models/model.rs | |
| parent | a30bcf0f0f32d6b1c822c631cf22fa9b13a5616a (diff) | |
Delete model uploads
Diffstat (limited to 'src/models/model.rs')
| -rw-r--r-- | src/models/model.rs | 36 |
1 files changed, 34 insertions, 2 deletions
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<ModelUpload, AppError> { + 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(()) + } } |
