summaryrefslogtreecommitdiffstats
path: root/internal/models/organisations.go
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-02-10 19:22:56 +0000
committerMatthew Lemon <y@yulqen.org>2024-02-10 19:22:56 +0000
commit58967839c646c717b5345f3a3d2924be5c6d5a4b (patch)
tree3c537852823fb90c374eae385e660b18e05a2ced /internal/models/organisations.go
parent030806353ca9b329bfb0102ebc10518b641511ee (diff)
Adds the Get handler for organisation model and fixes
Also fixes the NotAuthorised response I was mistakenly getting when it should have been a 404.
Diffstat (limited to 'internal/models/organisations.go')
-rw-r--r--internal/models/organisations.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/internal/models/organisations.go b/internal/models/organisations.go
index 291562b..edaa992 100644
--- a/internal/models/organisations.go
+++ b/internal/models/organisations.go
@@ -2,6 +2,7 @@ package models
import (
"database/sql"
+ "errors"
"time"
)
@@ -32,7 +33,22 @@ func (m *OrganisationModel) Insert(name string) (int, error) {
}
func (m *OrganisationModel) Get(id int) (Organisation, error) {
- return Organisation{}, nil
+ stmt := `SELECT id, name, created FROM organisations
+ WHERE id = ?`
+
+ row := m.DB.QueryRow(stmt, id)
+
+ var o Organisation
+
+ err := row.Scan(&o.ID, &o.Name, &o.Created)
+ if err != nil {
+ if errors.Is(err, sql.ErrNoRows) {
+ return Organisation{}, ErrNoRecord
+ } else {
+ return Organisation{}, err
+ }
+ }
+ return o, nil
}
// Ten most recent...