Added settings to backend and frontend.

This commit is contained in:
2026-02-02 03:41:56 +01:00
parent 2fb74839e4
commit c34b2391eb
10 changed files with 429 additions and 0 deletions
+49
View File
@@ -17,6 +17,7 @@ use tracing::info;
use http::header::{AUTHORIZATION, ACCEPT, ACCESS_CONTROL_ALLOW_ORIGIN, CONTENT_TYPE, ACCESS_CONTROL_ALLOW_CREDENTIALS};
use common::models::article;
use common::models::label::{delete_label, insert_label, load_labels, update_label, Label};
use common::models::settings::{load_settings, update_settings, Settings};
use common::models::unit::Unit;
use common::models::variant::{delete_variant, insert_variant, update_variant, Variant};
@@ -60,6 +61,9 @@ async fn main() {
.route("/label", post(add_label_route))
.route("/label/{id}", post(update_label_route))
.route("/label/{id}", delete(delete_label_route))
.route("/settings", get(get_settings_route))
.route("/settings", post(update_settings_route))
.with_state(pool)
.layer(cors);
@@ -352,3 +356,48 @@ async fn delete_label_route(
}
}
}
#[tracing::instrument(ret)]
async fn get_settings_route(
State(pool): State<PgPool>,
) -> (StatusCode, Json<Settings>) {
info!("Get settings");
match load_settings(&pool).await {
Some(settings) => {
(StatusCode::OK, Json(settings))
}
None => {
(StatusCode::INTERNAL_SERVER_ERROR, Json(
Settings {
id: 0,
mhd: "".to_string(),
bio: "".to_string(),
}
))
}
}
}
#[tracing::instrument(ret)]
async fn update_settings_route(
State(pool): State<PgPool>,
Json(payload): Json<Settings>,
) -> (StatusCode, Json<Settings>) {
info!("Update settings");
match update_settings(&payload, pool).await {
Some(settings) => {
(StatusCode::OK, Json(settings))
}
None => {
(StatusCode::INTERNAL_SERVER_ERROR, Json(
Settings {
id: 0,
mhd: "".to_string(),
bio: "".to_string(),
}
))
}
}
}