use actix_web::{web, HttpResponse, Responder}; use sqlx::PgPool; use crate::{ endpoints::{clothing::EditClothingPartialTemplate, IdPath}, models::{Clothing, Role, User}, utils::{ApplicationError, TemplateResponse}, }; #[actix_web::get("/clothing/edit/{id}")] pub async fn get( user: web::ReqData, pool: web::Data, path: web::Path, ) -> Result { if user.role != Role::Admin { return Err(ApplicationError::Unauthorized); } let Some(clothing) = Clothing::read(pool.get_ref(), path.id).await? else { return Ok(HttpResponse::NotFound().finish()); }; let template = EditClothingPartialTemplate { id: Some(clothing.id), name: Some(clothing.name), }; Ok(template.to_response()?) }