summaryrefslogtreecommitdiffstats
path: root/internal/models/operation.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/operation.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/operation.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/internal/models/operation.go b/internal/models/operation.go
new file mode 100644
index 0000000..ecfd31b
--- /dev/null
+++ b/internal/models/operation.go
@@ -0,0 +1,52 @@
+package models
+
+import (
+ "database/sql"
+ "time"
+)
+
+type Operation struct {
+ ID int
+ Name string
+ Description string
+ Created time.Time
+ OrganisationName string
+ EngagementStrategies []EngagementStrategy
+}
+
+type OperationModel struct {
+ DB *sql.DB
+}
+
+func (m *OperationModel) ListAll() ([]Operation, error) {
+
+ stmt := `SELECT op.id, op.name, op.description, op.created, org.name
+ FROM operations op
+ INNER JOIN organisations org ON op.organisation_id=org.id`
+
+ // stmt := `SELECT * FROM operations`
+
+ rows, err := m.DB.Query(stmt)
+ if err != nil {
+ return nil, err
+ }
+
+ defer rows.Close()
+
+ var ops []Operation
+
+ for rows.Next() {
+ var o Operation
+ err = rows.Scan(&o.ID, &o.Name, &o.Description, &o.Created, &o.OrganisationName)
+ if err != nil {
+ return nil, err
+ }
+
+ ops = append(ops, o)
+ }
+
+ if err = rows.Err(); err != nil {
+ return nil, err
+ }
+ return ops, err
+}