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.

closerewardfund.go 892 B

2 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package endpoints
  2. import (
  3. "encoding/json"
  4. "github.com/imosed/signet/auth"
  5. . "github.com/imosed/signet/data"
  6. "net/http"
  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. }