The backend for the project formerly known as signet, now known as beignet.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

closerewardfund.go 893 B

il y a 2 ans
il y a 2 ans
12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. }