The backend for the project formerly known as signet, now known as beignet.
Você não pode selecionar mais de 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.

56 linhas
1.1 KiB

  1. package endpoints
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "github.com/imosed/signet/auth"
  6. "github.com/imosed/signet/utils"
  7. "github.com/rs/zerolog/log"
  8. )
  9. type SubmitFundRequest struct {
  10. FundID uint `json:"fundID"`
  11. Submit bool `json:"submit"`
  12. }
  13. func SubmitFund(w http.ResponseWriter, r *http.Request) {
  14. var req SubmitFundRequest
  15. err := json.NewDecoder(r.Body).Decode(&req)
  16. if err != nil {
  17. log.Error().Err(err).Msg("Could not decode body in SubmitFund call")
  18. }
  19. var claims *auth.Claims
  20. claims, err = auth.GetUserClaims(r)
  21. if err != nil {
  22. log.Error().Err(err).Msg("Could not get user claims in call to SubmitFund")
  23. }
  24. if claims == nil {
  25. w.WriteHeader(401)
  26. return
  27. }
  28. if claims.Privileges > Admin {
  29. w.WriteHeader(403)
  30. return
  31. }
  32. var resp SuccessResponse
  33. resp.Success = false
  34. if req.Submit {
  35. var success bool
  36. success, err = utils.SubmitGroupFund(req.FundID)
  37. if err != nil {
  38. log.Error().Err(err).Msg("Could not submit group fund from SubmitFundRequest")
  39. }
  40. resp.Success = success
  41. }
  42. err = json.NewEncoder(w).Encode(resp)
  43. if err != nil {
  44. log.Error().Err(err).Msg("Could not deliver response in SubmitFund call")
  45. }
  46. }