Skip to content

Commit

Permalink
order media so that latest added are top (#660)
Browse files Browse the repository at this point in the history
* order media so that latest added are top

partial fix for #621

* also order paginated medias
  • Loading branch information
trinity-1686a authored and elegaanz committed Aug 28, 2019
1 parent ddbec3f commit d46af6f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion plume-models/src/medias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Media>> {
medias::table
.filter(medias::owner_id.eq(owner))
.order(medias::id.desc())
.load::<Self>(conn)
.map_err(Error::from)
}

pub fn list_all_medias(conn: &Connection) -> Result<Vec<Media>> {
medias::table.load::<Media>(conn).map_err(Error::from)
Expand All @@ -75,6 +82,7 @@ impl Media {
) -> Result<Vec<Media>> {
medias::table
.filter(medias::owner_id.eq(user.id))
.order(medias::id.desc())
.offset(i64::from(min))
.limit(i64::from(max - min))
.load::<Media>(conn)
Expand Down

0 comments on commit d46af6f

Please sign in to comment.