Fetch OSM places when setting image position.

Also remove specific route that was only partially implemented.
This commit is contained in:
Rasmus Kaj 2018-09-06 23:43:18 +02:00
parent 39126f2bc0
commit ce77a26eec
2 changed files with 6 additions and 25 deletions

View File

@ -1,6 +1,7 @@
//! Admin-only views, generally called by javascript.
use super::SizeTag;
use diesel::prelude::*;
use fetch_places::update_image_places;
use memcachemiddleware::MemcacheRequestExtensions;
use models::{Coord, Photo};
use nickel::extensions::Redirect;
@ -215,6 +216,10 @@ pub fn set_location<'mw>(
.execute(db)
.expect("Insert image position");
match update_image_places(db, image) {
Ok(()) => (),
Err(err) => warn!("Failed to fetch places: {}", err),
}
return res.redirect(format!("/img/{}", image));
}
info!("Missing image and/or position to set, or image not found.");
@ -237,24 +242,3 @@ fn location_params(
},
))
}
pub fn fetch_places<'mw>(
req: &mut Request,
res: Response<'mw>,
) -> MiddlewareResult<'mw> {
if !req.authorized_user().is_some() {
return res.error(StatusCode::Unauthorized, "permission denied");
}
let image = 60458;
let c: &PgConnection = &req.db_conn();
use fetch_places::update_image_places;
match update_image_places(c, image) {
Ok(ok) => res.ok(|o| writeln!(o, "Ok, got places {:?}", ok)),
Err(err) => {
warn!("Failed to fetch places: {}", err);
// TODO This might be a not found or an internal server error
res.not_found("Failed to get image position")
}
}
}

View File

@ -133,12 +133,9 @@ pub fn run(args: &ArgMatches) -> Result<(), Error> {
wrap3!(server.post "/login", do_login);
wrap3!(server.get "/logout", logout);
wrap3!(server.get "/", all_years);
use self::admin::{
fetch_places, rotate, set_grade, set_location, set_person, set_tag,
};
use self::admin::{rotate, set_grade, set_location, set_person, set_tag};
wrap3!(server.get "/ac/tag", auto_complete_tag);
wrap3!(server.get "/ac/person", auto_complete_person);
wrap3!(server.get "/adm/fetch_places", fetch_places);
wrap3!(server.post "/adm/grade", set_grade);
wrap3!(server.post "/adm/person", set_person);
wrap3!(server.post "/adm/rotate", rotate);