summaryrefslogblamecommitdiffstats
path: root/internal/models/engagement.go
blob: 26b468a7bf13bd1f55b9ea5d38b3fc5c92a82d1c (plain) (tree)
1
2
3
4



                      













                                     
                                                                                         

                                                                           



                                         
 
                          
 






                                                                   
                 





                                         
         

                         
 
package models

import (
	"database/sql"
	"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 = ?`
	rows, err := m.DB.Query(stmt, id)
	if err != nil {
		return nil, err
	}

	defer rows.Close()

	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 esses, nil
}