summaryrefslogtreecommitdiffstats
path: root/internal/models
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-02-12 15:47:47 +0000
committerMatthew Lemon <y@yulqen.org>2024-02-12 15:47:47 +0000
commit2648c9dfc3440f4c00a7b234de4687cc8a93a4d0 (patch)
tree3fbeb43c9a8db234198ed1e8793d496d224e10de /internal/models
parent752ee52dcd487253bc1662b1ba157732f73d27cf (diff)
Operations list shows ESs for each entity
This was about two hours of learning, and getting confused - and it needs to be refactored. We need to be able to generate the list of EPs for the Operation also. At the moment this only prints the object representation. More work to be done writing a method that gives us the id and textual representation for the link in the table.
Diffstat (limited to 'internal/models')
-rw-r--r--internal/models/engagement.go32
-rw-r--r--internal/models/operation.go11
2 files changed, 27 insertions, 16 deletions
diff --git a/internal/models/engagement.go b/internal/models/engagement.go
index db1c2f5..26b468a 100644
--- a/internal/models/engagement.go
+++ b/internal/models/engagement.go
@@ -2,7 +2,6 @@ package models
import (
"database/sql"
- "errors"
"time"
)
@@ -17,20 +16,31 @@ type EngagementStrategyModel struct {
DB *sql.DB
}
-func (m *EngagementStrategyModel) GetForOperation(id int) (EngagementStrategy, error) {
+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)
+ rows, err := m.DB.Query(stmt, id)
+ if err != nil {
+ return nil, err
+ }
- var es EngagementStrategy
+ defer rows.Close()
- 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
+ var esses []EngagementStrategy
+
+ for rows.Next() {
+ var es EngagementStrategy
+ err = rows.Scan(&es.ID, &es.ValidFrom, &es.ValidTo)
+ if err != nil {
+ return nil, err
}
+
+ esses = append(esses, es)
+ }
+
+ if err = rows.Err(); err != nil {
+ return nil, err
}
- return es, nil
+
+ return esses, nil
}
diff --git a/internal/models/operation.go b/internal/models/operation.go
index 4c5d67f..ecfd31b 100644
--- a/internal/models/operation.go
+++ b/internal/models/operation.go
@@ -6,11 +6,12 @@ import (
)
type Operation struct {
- ID int
- Name string
- Description string
- Created time.Time
- OrganisationName string
+ ID int
+ Name string
+ Description string
+ Created time.Time
+ OrganisationName string
+ EngagementStrategies []EngagementStrategy
}
type OperationModel struct {