The backend for the project formerly known as signet, now known as beignet.
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

44 linhas
893 B

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