From d46af6fe5bb472d0aa9435520690c3b94a3ec577 Mon Sep 17 00:00:00 2001 From: fdb-hiroshima <35889323+fdb-hiroshima@users.noreply.github.com> Date: Wed, 28 Aug 2019 11:37:03 +0200 Subject: [PATCH] order media so that latest added are top (#660) * order media so that latest added are top partial fix for #621 * also order paginated medias --- plume-models/src/medias.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plume-models/src/medias.rs b/plume-models/src/medias.rs index e3d33cc..c021f28 100644 --- a/plume-models/src/medias.rs +++ b/plume-models/src/medias.rs @@ -62,7 +62,14 @@ impl MediaCategory { impl Media { insert!(medias, NewMedia); get!(medias); - list_by!(medias, for_user, owner_id as i32); + + pub fn for_user(conn: &Connection, owner: i32) -> Result> { + medias::table + .filter(medias::owner_id.eq(owner)) + .order(medias::id.desc()) + .load::(conn) + .map_err(Error::from) + } pub fn list_all_medias(conn: &Connection) -> Result> { medias::table.load::(conn).map_err(Error::from) @@ -75,6 +82,7 @@ impl Media { ) -> Result> { medias::table .filter(medias::owner_id.eq(user.id)) + .order(medias::id.desc()) .offset(i64::from(min)) .limit(i64::from(max - min)) .load::(conn)