Begining of a RON API to edit profile

This commit is contained in:
Greg Burri 2024-11-14 01:59:40 +01:00
parent 37f6de7a89
commit 405aa68526
11 changed files with 229 additions and 68 deletions

View file

@ -45,3 +45,51 @@
// #[put("/ron-api/recipe/add-step")]
// #[put("/ron-api/recipe/rm-step")]
// #[put("/ron-api/recipe/set-steps-order")]
use askama_axum::IntoResponse;
use axum::{
debug_handler,
extract::{Extension, State},
http::StatusCode,
response::ErrorResponse,
response::Result,
};
use tracing::{event, Level};
use crate::{
data::db,
model,
ron_extractor::{ron_error, ron_response, ExtractRon},
};
#[debug_handler]
pub async fn set_user_name(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
ExtractRon(ron): ExtractRon<common::ron_api::SetProfileName>,
) -> Result<StatusCode> {
if let Some(user) = user {
connection.set_user_name(user.id, &ron.name).await?;
} else {
return Err(ErrorResponse::from(ron_error(
StatusCode::UNAUTHORIZED,
"Action not authorized",
)));
}
Ok(StatusCode::OK)
}
/* Example with RON return value.
#[debug_handler]
pub async fn set_user_name(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
ExtractRon(ron): ExtractRon<common::ron_api::SetProfileName>,
) -> Result<impl IntoResponse> {
Ok(ron_response(common::ron_api::SetProfileName {
name: "abc".to_string(),
}))
}
*/