The backend for the project formerly known as signet, now known as beignet.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
892 B

  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. }