The backend for the project formerly known as signet, now known as beignet.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

closerewardfund.go 1.0 KiB

pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. }