summaryrefslogtreecommitdiffstats
path: root/internal/models
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-02-12 13:57:52 +0000
committerMatthew Lemon <y@yulqen.org>2024-02-12 13:57:52 +0000
commit752ee52dcd487253bc1662b1ba157732f73d27cf (patch)
treea2c3c3d36177fc9ba90fcc1d85798ba943268579 /internal/models
parentc1c0ddbf61860b863f1e3ac11caea7407eef2412 (diff)
wip: mating EPs with Operations
Diffstat (limited to 'internal/models')
-rw-r--r--internal/models/engagement.go36
-rw-r--r--internal/models/organisations.go2
2 files changed, 36 insertions, 2 deletions
diff --git a/internal/models/engagement.go b/internal/models/engagement.go
new file mode 100644
index 0000000..db1c2f5
--- /dev/null
+++ b/internal/models/engagement.go
@@ -0,0 +1,36 @@
+package models
+
+import (
+ "database/sql"
+ "errors"
+ "time"
+)
+
+type EngagementStrategy struct {
+ ID int
+ ValidFrom time.Time
+ ValidTo time.Time
+ Operation Operation
+}
+
+type EngagementStrategyModel struct {
+ DB *sql.DB
+}
+
+func (m *EngagementStrategyModel) GetForOperation(id int) (EngagementStrategy, error) {
+ stmt := `SELECT id, valid_from, valid_to FROM engagement_strategies
+WHERE operation_id = ?`
+ row := m.DB.QueryRow(stmt, id)
+
+ var es EngagementStrategy
+
+ err := row.Scan(&es.ID, &es.ValidFrom, &es.ValidTo)
+ if err != nil {
+ if errors.Is(err, sql.ErrNoRows) {
+ return EngagementStrategy{}, ErrNoRecord
+ } else {
+ return EngagementStrategy{}, err
+ }
+ }
+ return es, nil
+}
diff --git a/internal/models/organisations.go b/internal/models/organisations.go
index b765f91..88f7bc9 100644
--- a/internal/models/organisations.go
+++ b/internal/models/organisations.go
@@ -82,6 +82,4 @@ func (m *OrganisationModel) Latest() ([]Organisation, error) {
}
return organisations, err
-
- return nil, nil
}