devict / job-board

the devICT job board!
https://jobs.devict.org
0 stars 13 forks source link

List jobs from newest to oldest #18

Closed kevinfalting closed 2 years ago

kevinfalting commented 2 years ago

Would be nice to see the newest job postings at the top of the index page rather than at the bottom. The query doesn't specify an order, so it just gets results back in index order.

Let's add ORDER BY published_at DESC to the getAllJobs func.

func getAllJobs(db *sqlx.DB) ([]Job, error) {
    var jobs []Job

-   err := db.Select(&jobs, "SELECT * FROM jobs")
+   err := db.Select(&jobs, "SELECT * FROM jobs ORDER BY published_at DESC")
    if err != nil && !errors.Is(err, sql.ErrNoRows) {
        return jobs, err
    }

    return jobs, nil
}