traits for responses

This commit is contained in:
2023-09-16 00:45:51 +02:00
parent 7e62acf91a
commit 2221ee0412
6 changed files with 160 additions and 95 deletions

View File

@@ -75,7 +75,6 @@ pub mod crud {
T: sqlx::Acquire<'c, Database = sqlx::Sqlite> + Send + std::fmt::Debug;
async fn delete_all<'c>(
// &self,
ctx: &Context,
pool: &'c sqlite::Pool,
filter: Self::Filter,
@@ -109,3 +108,37 @@ pub mod view {
fn build(&self, input: Self::Input) -> Markup;
}
}
pub mod route {
use async_trait::async_trait;
use crate::AppState;
use axum::{
body::BoxBody,
extract::{Path, State},
http::HeaderMap,
response::Response,
Extension, Form,
};
pub enum Method {
Get,
Post,
}
#[async_trait]
pub trait Create: super::crud::Create {
type FormX: Send + Sync + 'static;
type UrlParams: Send + Sync + 'static;
const URL: &'static str;
async fn create(
user: Extension<crate::models::user::User>,
state: State<AppState>,
headers: HeaderMap,
path: Path<Self::UrlParams>,
form: Form<Self::FormX>,
) -> Result<Response<BoxBody>, crate::Error>;
}
}