From 752ee52dcd487253bc1662b1ba157732f73d27cf Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 12 Feb 2024 13:57:52 +0000 Subject: wip: mating EPs with Operations --- internal/models/engagement.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 internal/models/engagement.go (limited to 'internal/models/engagement.go') 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 +} -- cgit v1.2.3