The backend for the project formerly known as signet, now known as beignet.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

submitfund.go 1.1 KiB

pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. }