diff options
| author | Santo Cariotti <santo@dcariotti.me> | 2022-09-06 17:58:35 +0000 |
|---|---|---|
| committer | Santo Cariotti <santo@dcariotti.me> | 2022-09-06 17:58:35 +0000 |
| commit | acc32ccc1650b99e03c390a87e71b0a85b073162 (patch) | |
| tree | 0de545ee0eb8eba5961c57c0a73ff7031e97613d /src/routes | |
| parent | e6dbcbb42e7a4a973887acde633cc3ee233aad3e (diff) | |
Create a 3d model object
Diffstat (limited to 'src/routes')
| -rw-r--r-- | src/routes/mod.rs | 1 | ||||
| -rw-r--r-- | src/routes/model.rs | 39 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/routes/mod.rs b/src/routes/mod.rs index f9bae3d..7e61662 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -1,2 +1,3 @@ pub mod auth; +pub mod model; pub mod user; diff --git a/src/routes/model.rs b/src/routes/model.rs new file mode 100644 index 0000000..b1d4cc2 --- /dev/null +++ b/src/routes/model.rs @@ -0,0 +1,39 @@ +use crate::errors::AppError; +use crate::models::{ + auth::Claims, + model::{Model, ModelCreate}, +}; +use axum::{routing::get, Json, Router}; + +/// Create routes for `/v1/models/` namespace +pub fn create_route() -> Router { + Router::new().route("/", get(list_models).post(create_model)) +} + +/// List models. +async fn list_models() -> Result<Json<Vec<Model>>, AppError> { + let models = Model::list().await?; + + Ok(Json(models)) +} + +/// Create a model. Checks Authorization token +async fn create_model( + Json(payload): Json<ModelCreate>, + claims: Claims, +) -> Result<Json<Model>, AppError> { + let model = Model::new( + payload.name, + payload.description, + payload.duration, + payload.height, + payload.weight, + payload.printer, + payload.material, + claims.user_id, + ); + + let model_new = Model::create(model).await?; + + Ok(Json(model_new)) +} |
