check / check (push) Waiting to run
Replaces #559, which conflicted. Model: opus-5-5
36 lines
808 B
Go
36 lines
808 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"sneak.berlin/go/webhooker/internal/database"
|
|
)
|
|
|
|
// HandleTargetToggle handles toggling a target's active state.
|
|
func (h *Handlers) HandleTargetToggle() http.HandlerFunc {
|
|
return h.toggleChildResource(
|
|
"targetID",
|
|
func(webhookID, childID string) (bool, error) {
|
|
var tgt database.Target
|
|
|
|
err := h.db.DB().Where(
|
|
"id = ? AND webhook_id = ?",
|
|
childID, webhookID,
|
|
).First(&tgt).Error
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
// Only the active column: saving the whole row would
|
|
// write back the name and settings read above over an
|
|
// edit saved since.
|
|
active := !tgt.Active
|
|
|
|
return active, h.db.DB().Model(&tgt).
|
|
Update("active", active).Error
|
|
},
|
|
"failed to toggle target",
|
|
targetActivated, targetDeactivated,
|
|
)
|
|
}
|