This commit is contained in:
@@ -14,6 +14,8 @@ type eventHandlerRecord struct {
|
||||
Priority int `db:"priority"`
|
||||
TargetKind string `db:"target_kind"`
|
||||
TargetValue string `db:"target_value"`
|
||||
From *string `db:"from_tod"`
|
||||
To *string `db:"to_tod"`
|
||||
ConditionsJSON json.RawMessage `db:"conditions"`
|
||||
ActionsJSON json.RawMessage `db:"actions"`
|
||||
}
|
||||
@@ -61,12 +63,14 @@ func (r *EventHandlerRepo) Save(ctx context.Context, handler *models.EventHandle
|
||||
TargetValue: handler.TargetValue,
|
||||
ConditionsJSON: conditionsJson,
|
||||
ActionsJSON: actionsJson,
|
||||
From: handler.From.StringPtr(),
|
||||
To: handler.To.StringPtr(),
|
||||
}
|
||||
|
||||
if record.ID == 0 {
|
||||
res, err := r.DBX.NamedExecContext(ctx, `
|
||||
INSERT INTO event_handler (event_name, one_shot, priority, target_kind, target_value, conditions, actions)
|
||||
VALUES (:event_name, :one_shot, :priority, :target_kind, :target_value, :conditions, :actions);
|
||||
INSERT INTO event_handler (event_name, one_shot, priority, target_kind, target_value, conditions, from_tod, to_tod, actions)
|
||||
VALUES (:event_name, :one_shot, :priority, :target_kind, :target_value, :conditions, :from_tod, :to_tod, :actions);
|
||||
`, record)
|
||||
if err != nil {
|
||||
return dbErr(err)
|
||||
@@ -87,6 +91,8 @@ func (r *EventHandlerRepo) Save(ctx context.Context, handler *models.EventHandle
|
||||
target_kind = :target_kind,
|
||||
target_value = :target_value,
|
||||
conditions = :conditions,
|
||||
from_tod = :from_tod,
|
||||
to_tod = :to_tod,
|
||||
actions = :actions
|
||||
WHERE id = :id
|
||||
`, record)
|
||||
@@ -139,6 +145,15 @@ func (r *EventHandlerRepo) populate(records []eventHandlerRecord) ([]models.Even
|
||||
return nil, dbErr(err)
|
||||
}
|
||||
|
||||
handler.From, err = models.ParseTimeOfDayPtr(record.From)
|
||||
if err != nil {
|
||||
return nil, dbErr(err)
|
||||
}
|
||||
handler.To, err = models.ParseTimeOfDayPtr(record.To)
|
||||
if err != nil {
|
||||
return nil, dbErr(err)
|
||||
}
|
||||
|
||||
res = append(res, handler)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user