|
|
|
@@ -81,9 +81,7 @@ func AlertDeleteController(db *gorm.DB, ctx context.Context) http.HandlerFunc { |
|
|
|
func AlertUpdateStatusController(db *gorm.DB, ctx context.Context) http.HandlerFunc { |
|
|
|
return func(w http.ResponseWriter, r *http.Request) { |
|
|
|
id := mux.Vars(r)["id"] |
|
|
|
var body struct { |
|
|
|
Status string `json:"status"` |
|
|
|
} |
|
|
|
var body service.AlertPatchBody |
|
|
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil { |
|
|
|
response.BadRequest(w, "invalid request body") |
|
|
|
return |
|
|
|
@@ -92,7 +90,13 @@ func AlertUpdateStatusController(db *gorm.DB, ctx context.Context) http.HandlerF |
|
|
|
response.BadRequest(w, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
if err := service.UpdateAlertStatus(id, body.Status, db, ctx); err != nil { |
|
|
|
|
|
|
|
if err := validation.Var(body.Operator, "required"); err != nil { |
|
|
|
response.BadRequest(w, err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if err := service.UpdateAlertStatus(id, body, db, ctx); err != nil { |
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) { |
|
|
|
response.NotFound(w, "alert not found") |
|
|
|
return |
|
|
|
|