summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2022-09-12 12:15:30 +0000
committerSanto Cariotti <santo@dcariotti.me>2022-09-12 12:15:30 +0000
commit1e9f99b092346f4153fb5880b274778ce1195e6d (patch)
treef6eb9b87e4321be52b06d8ab59609f279f85d7c0 /src
parent74fa5cd55032b45413c08b19b9b8060a992194e9 (diff)
Add route to get one model per time
Diffstat (limited to 'src')
-rw-r--r--src/routes/model.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/routes/model.rs b/src/routes/model.rs
index f85e9a7..30429f7 100644
--- a/src/routes/model.rs
+++ b/src/routes/model.rs
@@ -17,6 +17,7 @@ use serde::Serialize;
pub fn create_route() -> Router {
Router::new()
.route("/", get(list_models).post(create_model))
+ .route("/:id", get(get_model))
.route("/:id/upload", post(upload_model_file))
}
@@ -56,6 +57,14 @@ async fn create_model(
Ok(Json(model_new))
}
+/// Get a model with id = `model_id`
+async fn get_model(Path(model_id): Path<i32>) -> Result<Json<ModelUser>, AppError> {
+ match Model::find_by_id(model_id).await {
+ Ok(model) => Ok(Json(model)),
+ Err(_) => Err(AppError::NotFound("Model not found".to_string())),
+ }
+}
+
/// Upload a file for a model
async fn upload_model_file(
claims: Claims,