Add positions to on-this-day.
This commit is contained in:
parent
e74cbb0c3d
commit
5557dd4de9
@ -6,7 +6,7 @@ use diesel::dsl::sql;
|
||||
use diesel::pg::PgConnection;
|
||||
use diesel::prelude::*;
|
||||
use diesel::sql_types::{BigInt, Integer, Nullable};
|
||||
use models::Photo;
|
||||
use models::{Coord, Photo};
|
||||
use nickel::extensions::response::Redirect;
|
||||
use nickel::{MiddlewareResult, QueryString, Request, Response};
|
||||
use nickel_diesel::DieselRequestExtensions;
|
||||
@ -225,13 +225,34 @@ pub fn on_this_day<'mw>(
|
||||
req: &mut Request,
|
||||
res: Response<'mw>,
|
||||
) -> MiddlewareResult<'mw> {
|
||||
use schema::photos::dsl::{date, grade};
|
||||
use schema::photos::dsl::{date, grade, id};
|
||||
use schema::positions::dsl::{latitude, longitude, photo_id, positions};
|
||||
let c: &PgConnection = &req.db_conn();
|
||||
|
||||
let (month, day) = {
|
||||
let now = time::now();
|
||||
(now.tm_mon as u32 + 1, now.tm_mday as u32)
|
||||
};
|
||||
let pos = Photo::query(req.authorized_user().is_some())
|
||||
.inner_join(positions.on(photo_id.eq(id)))
|
||||
.filter(
|
||||
sql("extract(month from date)=").bind::<Integer, _>(month as i32),
|
||||
).filter(sql("extract(day from date)=").bind::<Integer, _>(day as i32))
|
||||
.select((photo_id, latitude, longitude))
|
||||
.load(c)
|
||||
.map_err(|e| warn!("Failed to load positions: {}", e))
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(|(p_id, lat, long): (i32, i32, i32)| {
|
||||
(
|
||||
Coord {
|
||||
x: f64::from(lat) / 1e6,
|
||||
y: f64::from(long) / 1e6,
|
||||
},
|
||||
p_id,
|
||||
)
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
res.ok(|o| {
|
||||
templates::index(
|
||||
o,
|
||||
@ -272,7 +293,7 @@ pub fn on_this_day<'mw>(
|
||||
size: photo.get_size(SizeTag::Small.px()),
|
||||
}
|
||||
}).collect::<Vec<_>>(),
|
||||
&[],
|
||||
&pos,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user