The backend for the project formerly known as signet, now known as beignet.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

47 rader
1.0 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.Privileges <= AdminPlus && req.Close {
  29. Db.Table("reward_funds").Find(&fund, req.ID)
  30. modified = Db.Delete(&fund).RowsAffected
  31. }
  32. var resp SuccessResponse
  33. resp.Success = modified > 0
  34. err = json.NewEncoder(w).Encode(resp)
  35. if err != nil {
  36. log.Error().Err(err).Msg("Could not deliver response in CloseRewardFund call")
  37. }
  38. }