Added preferences endpoint

This commit is contained in:
Antoine Gersant 2018-10-28 15:52:09 -07:00
parent ea299312d0
commit 2ee33e7615

View file

@ -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<rocket::Route> {
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<DB>, auth: Auth) -> Result<Json<Preferences>, errors::Error> {
let preferences = config::read_preferences::<DB>(&db, &auth.username)?;
Ok(Json(preferences))
}
#[put("/preferences", data = "<preferences>")]
fn put_preferences(
db: State<DB>,
auth: Auth,
preferences: Json<Preferences>,
) -> Result<(), errors::Error> {
config::write_preferences::<DB>(&db, &auth.username, &preferences)?;
Ok(())
}
#[post("/trigger_index")]
fn trigger_index(
command_sender: State<Arc<index::CommandSender>>,