The backend for the project formerly known as signet, now known as beignet.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

closerewardfund.go 1.1 KiB

2 vuotta sitten
2 vuotta sitten
2 vuotta sitten
2 vuotta sitten
2 vuotta sitten
2 vuotta sitten
2 vuotta sitten
2 vuotta sitten
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package endpoints
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "github.com/imosed/signet/auth"
  6. . "github.com/imosed/signet/data"
  7. "github.com/rs/zerolog/log"
  8. )
  9. type CloseRewardFundRequest struct {
  10. ID uint `json:"id"`
  11. Close bool `json:"close"`
  12. }
  13. func CloseRewardFund(w http.ResponseWriter, r *http.Request) {
  14. var req CloseRewardFundRequest
  15. err := json.NewDecoder(r.Body).Decode(&req)
  16. if err != nil {
  17. log.Error().Err(err).Msg("Could not decode body in CloseRewardFund call")
  18. return
  19. }
  20. var claims *auth.Claims
  21. claims, err = auth.GetUserClaims(r)
  22. if err != nil {
  23. log.Error().Err(err).Msg("Could not determine if user is authenticated")
  24. return
  25. }
  26. var fund RewardFund
  27. var modified int64
  28. if claims != nil && claims.Privileges <= AdminPlus && req.Close {
  29. Db.Table("reward_funds").Find(&fund, req.ID)
  30. modified = Db.Delete(&fund).RowsAffected
  31. } else {
  32. w.WriteHeader(403)
  33. return
  34. }
  35. var resp SuccessResponse
  36. resp.Success = modified > 0
  37. err = json.NewEncoder(w).Encode(resp)
  38. if err != nil {
  39. log.Error().Err(err).Msg("Could not deliver response in CloseRewardFund call")
  40. }
  41. }