Skip to content

Commit

Permalink
Correct lens ordering
Browse files Browse the repository at this point in the history
Signed-off-by: Charlie Egan <[email protected]>
  • Loading branch information
charlieegan3 committed Mar 11, 2024
1 parent 60f001b commit dae46d9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions internal/pkg/database/lenses.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,18 @@ func AllLenses(db *sql.DB) (results []models.Lens, err error) {

goquDB := goqu.New("postgres", db)
selectLenses := goquDB.From("photos.lenses").
Select("*").
Order(goqu.I("name").Asc()).
FullOuterJoin(goqu.T("medias").Schema("photos"), goqu.On(goqu.Ex{"medias.lens_id": goqu.I("lenses.id")})).
FullOuterJoin(goqu.T("posts").Schema("photos"), goqu.On(goqu.Ex{"posts.media_id": goqu.I("medias.id")})).
Select(
"lenses.*",
).
Where(goqu.L("lenses.id IS NOT NULL")).
Order(
goqu.L("MAX(coalesce(posts.publish_date, timestamp with time zone 'epoch'))").Desc(),
).
GroupBy(goqu.I("lenses.id")).
Executor()

if err := selectLenses.ScanStructs(&dbLenses); err != nil {
return results, errors.Wrap(err, "failed to select lenses")
}
Expand Down

0 comments on commit dae46d9

Please sign in to comment.