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.

pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. if claims == nil {
  27. w.WriteHeader(401)
  28. return
  29. }
  30. if claims.Privileges > AdminPlus {
  31. w.WriteHeader(403)
  32. return
  33. }
  34. var fund RewardFund
  35. var modified int64
  36. if req.Close {
  37. Db.Table("reward_funds").Find(&fund, req.ID)
  38. modified = Db.Delete(&fund).RowsAffected
  39. }
  40. var resp SuccessResponse
  41. resp.Success = modified > 0
  42. err = json.NewEncoder(w).Encode(resp)
  43. if err != nil {
  44. log.Error().Err(err).Msg("Could not deliver response in CloseRewardFund call")
  45. }
  46. }