summaryrefslogtreecommitdiffstats
path: root/internal/models/engagement.go
blob: db1c2f547e44d684f132df1be6a7dad96e142d85 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
}