|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- 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
- }
-
- var fund RewardFund
- var modified int64
- if claims != nil && claims.Privileges <= AdminPlus && req.Close {
- Db.Table("reward_funds").Find(&fund, req.ID)
- modified = Db.Delete(&fund).RowsAffected
- } else {
- w.WriteHeader(403)
- return
- }
-
- 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")
- }
- }
|