Added settings to backend and frontend.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
-- Add migration script here
|
||||
|
||||
-- Create Label
|
||||
CREATE TABLE settings
|
||||
(
|
||||
id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 ),
|
||||
mhd text NOT NULL,
|
||||
bio text NOT NULL
|
||||
);
|
||||
|
||||
-- Insert default values
|
||||
INSERT INTO settings (mhd, bio) VALUES ('Mindestens haltbar bis:', 'DE-ÖKO 006');
|
||||
@@ -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(),
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user