From 2ee33e76151a286e37d3dae51af739e9db2933fa Mon Sep 17 00:00:00 2001 From: Antoine Gersant Date: Sun, 28 Oct 2018 15:52:09 -0700 Subject: [PATCH] Added preferences endpoint --- src/rocket_api.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/rocket_api.rs b/src/rocket_api.rs index 0bef85b..f39d506 100644 --- a/src/rocket_api.rs +++ b/src/rocket_api.rs @@ -7,7 +7,7 @@ use std::path::PathBuf; use std::ops::Deref; use std::sync::Arc; -use config::{self, Config}; +use config::{self, Config, Preferences}; use db::DB; use errors; use index; @@ -27,6 +27,8 @@ pub fn get_routes() -> Vec { initial_setup, get_settings, put_settings, + get_preferences, + put_preferences, trigger_index, auth, browse_root, @@ -148,6 +150,22 @@ fn put_settings( Ok(()) } +#[get("/preferences")] +fn get_preferences(db: State, auth: Auth) -> Result, errors::Error> { + let preferences = config::read_preferences::(&db, &auth.username)?; + Ok(Json(preferences)) +} + +#[put("/preferences", data = "")] +fn put_preferences( + db: State, + auth: Auth, + preferences: Json, +) -> Result<(), errors::Error> { + config::write_preferences::(&db, &auth.username, &preferences)?; + Ok(()) +} + #[post("/trigger_index")] fn trigger_index( command_sender: State>,