feat: add model
This commit is contained in:
parent
c5f6a24b3a
commit
42a75ba800
6 changed files with 117 additions and 1 deletions
34
src/web/routes_properties.rs
Normal file
34
src/web/routes_properties.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
use crate::model::{ModelController, Property, PropertyForCreate};
|
||||
use crate::Result;
|
||||
use axum::extract::{Path, State};
|
||||
use axum::routing::{delete, post};
|
||||
use axum::{Json, Router};
|
||||
|
||||
pub fn routes(mc: ModelController) -> Router {
|
||||
Router::new()
|
||||
.route("/properties", post(create_property).get(list_properties))
|
||||
.route("/properties/:id", delete(delete_property))
|
||||
.with_state(mc)
|
||||
}
|
||||
|
||||
// region: --- REST Handlers
|
||||
|
||||
async fn create_property(State(mc): State<ModelController>, Json(property_fc): Json<PropertyForCreate>) -> Result<Json<Property>> {
|
||||
println!("->> {:<12} - create_property", "HANDLER");
|
||||
let property = mc.create_property(property_fc).await?;
|
||||
Ok(Json(property))
|
||||
}
|
||||
|
||||
async fn list_properties(State(mc): State<ModelController>) -> Result<Json<Vec<Property>>> {
|
||||
println!("->> {:<12} - list_properties", "HANDLER");
|
||||
let properties = mc.list_properties().await?;
|
||||
Ok(Json(properties))
|
||||
}
|
||||
|
||||
async fn delete_property(State(mc): State<ModelController>, Path(id): Path<u64>) -> Result<Json<Property>> {
|
||||
println!("->> {:<12} - delete_property", "HANDLER");
|
||||
let property = mc.delete_property(id).await?;
|
||||
Ok(Json(property))
|
||||
}
|
||||
|
||||
// endregion: --- REST Handlers
|
||||
Loading…
Add table
Add a link
Reference in a new issue