The backend for the project formerly known as signet, now known as beignet.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

50 wiersze
1.1 KiB

  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. }