mirror of
https://github.com/mentos1386/zdravko.git
synced 2024-11-22 15:53:45 +00:00
25 lines
739 B
Go
25 lines
739 B
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
|
|
"code.tjo.space/mentos1386/zdravko/database/models"
|
|
"github.com/jmoiron/sqlx"
|
|
)
|
|
|
|
func GetMonitorHistoryForMonitor(ctx context.Context, db *sqlx.DB, monitorSlug string) ([]*models.MonitorHistory, error) {
|
|
var monitorHistory []*models.MonitorHistory
|
|
err := db.SelectContext(ctx, &monitorHistory,
|
|
"SELECT * FROM monitor_histories WHERE monitor_slug = $1 ORDER BY created_at DESC",
|
|
monitorSlug,
|
|
)
|
|
return monitorHistory, err
|
|
}
|
|
|
|
func AddHistoryForMonitor(ctx context.Context, db *sqlx.DB, history *models.MonitorHistory) error {
|
|
_, err := db.NamedExecContext(ctx,
|
|
"INSERT INTO monitor_histories (monitor_slug, status, note) VALUES (:monitor_slug, :status, :note)",
|
|
history,
|
|
)
|
|
return err
|
|
}
|