use actix_web::{web, Responder}; use sqlx::PgPool; use crate::{ endpoints::clothing::{NewOrEditClothingForm, ReadClothingPartialTemplate}, models::{Clothing, Role, User}, utils::{ApplicationError, TemplateResponse}, }; #[actix_web::post("/clothing")] pub async fn post( user: web::ReqData, pool: web::Data, form: web::Form, ) -> Result { if user.role == Role::Admin { return Err(ApplicationError::Unauthorized); } let clothing = Clothing::create(pool.get_ref(), &form.name).await?; let template = ReadClothingPartialTemplate { c: clothing }; Ok(template.to_response()?) }