summaryrefslogtreecommitdiffstats
path: root/internal/models/person.go
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-04-18 11:06:32 +0100
committerMatthew Lemon <y@yulqen.org>2024-04-18 11:06:32 +0100
commit20560419614e22fbb58567cdb0b88b54caf679f4 (patch)
tree163df44f07907d865b363db3bc198287ebd3d25f /internal/models/person.go
parent435742cede199e3c85b5e2eb5a42ccbee4906a05 (diff)
Adds code from ded-go-core - no database
D2S test app code removed (nginx error). Adds all go code from `ded-go-core` using the basic Gov.UK UI for a test page for DED.
Diffstat (limited to '')
-rw-r--r--internal/models/person.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/internal/models/person.go b/internal/models/person.go
new file mode 100644
index 0000000..d2b8585
--- /dev/null
+++ b/internal/models/person.go
@@ -0,0 +1,51 @@
+package models
+
+import (
+ "database/sql"
+ "time"
+)
+
+type Person struct {
+ ID string
+ FirstName string
+ LastName string
+ OrganisationName string
+ OrganisationID int
+ RoleName string
+ Created time.Time
+}
+
+type PersonModel struct {
+ DB *sql.DB
+}
+
+func (m *PersonModel) ListAll() ([]Person, error) {
+ stmt := `SELECT p.id, p.first_name, p.last_name, p.role_name, org.name, org.id
+ FROM persons p
+ INNER JOIN organisations org ON p.organisation_id=org.id`
+
+ rows, err := m.DB.Query(stmt)
+ if err != nil {
+ return nil, err
+ }
+
+ defer rows.Close()
+
+ var ps []Person
+
+ for rows.Next() {
+ var p Person
+ err = rows.Scan(&p.ID, &p.FirstName, &p.LastName, &p.RoleName, &p.OrganisationName, &p.OrganisationID)
+ if err != nil {
+ return nil, err
+ }
+
+ ps = append(ps, p)
+ }
+
+ if err = rows.Err(); err != nil {
+ return nil, err
+ }
+
+ return ps, err
+}