diff options
author | Matthew Lemon <y@yulqen.org> | 2024-02-10 19:39:51 +0000 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-02-10 19:39:51 +0000 |
commit | ceae84f1ae0ce2f23a70aa23b899e135384332f6 (patch) | |
tree | 0ce91d2dd2a30ef67ff051f5659c5fdc42a11a61 /internal/models | |
parent | 58967839c646c717b5345f3a3d2924be5c6d5a4b (diff) |
Implements Latest() organisation model method
And puts the list in plain text on the home page.
Diffstat (limited to 'internal/models')
-rw-r--r-- | internal/models/organisations.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/models/organisations.go b/internal/models/organisations.go index edaa992..b765f91 100644 --- a/internal/models/organisations.go +++ b/internal/models/organisations.go @@ -53,5 +53,35 @@ func (m *OrganisationModel) Get(id int) (Organisation, error) { // Ten most recent... func (m *OrganisationModel) Latest() ([]Organisation, error) { + // Pick out the last 10 + stmt := `SELECT id, name, created FROM organisations + ORDER BY id DESC LIMIT 10` + + rows, err := m.DB.Query(stmt) + if err != nil { + return nil, err + } + + defer rows.Close() + + var organisations []Organisation + + for rows.Next() { + var o Organisation + + err = rows.Scan(&o.ID, &o.Name, &o.Created) + if err != nil { + return nil, err + } + + organisations = append(organisations, o) + } + + if err = rows.Err(); err != nil { + return nil, err + } + + return organisations, err + return nil, nil } |