package endpoints import ( "encoding/json" "net/http" "github.com/imosed/signet/auth" . "github.com/imosed/signet/data" "github.com/rs/zerolog/log" ) type CloseRewardFundRequest struct { ID uint `json:"id"` Close bool `json:"close"` } func CloseRewardFund(w http.ResponseWriter, r *http.Request) { var req CloseRewardFundRequest err := json.NewDecoder(r.Body).Decode(&req) if err != nil { log.Error().Err(err).Msg("Could not decode body in CloseRewardFund call") return } var claims *auth.Claims claims, err = auth.GetUserClaims(r) if err != nil { log.Error().Err(err).Msg("Could not determine if user is authenticated") return } if claims == nil { w.WriteHeader(401) return } if claims.Privileges > AdminPlus { w.WriteHeader(403) return } var fund RewardFund var modified int64 if req.Close { Db.Table("reward_funds").Find(&fund, req.ID) modified = Db.Delete(&fund).RowsAffected } var resp SuccessResponse resp.Success = modified > 0 err = json.NewEncoder(w).Encode(resp) if err != nil { log.Error().Err(err).Msg("Could not deliver response in CloseRewardFund call") } }