|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package endpoints
-
- import (
- "encoding/json"
- "net/http"
-
- "github.com/imosed/signet/auth"
- "github.com/imosed/signet/utils"
- "github.com/rs/zerolog/log"
- )
-
- type SubmitFundRequest struct {
- FundID uint `json:"fundID"`
- Submit bool `json:"submit"`
- }
-
- func SubmitFund(w http.ResponseWriter, r *http.Request) {
- var req SubmitFundRequest
- err := json.NewDecoder(r.Body).Decode(&req)
- if err != nil {
- log.Error().Err(err).Msg("Could not decode body in SubmitFund call")
- }
-
- var claims *auth.Claims
- claims, err = auth.GetUserClaims(r)
- if err != nil {
- log.Error().Err(err).Msg("Could not get user claims in call to SubmitFund")
- }
- if claims == nil {
- w.WriteHeader(401)
- return
- }
- if claims.Privileges > Admin {
- w.WriteHeader(403)
- return
- }
-
- var resp SuccessResponse
- resp.Success = false
-
- if req.Submit {
- var success bool
- success, err = utils.SubmitGroupFund(req.FundID)
- if err != nil {
- log.Error().Err(err).Msg("Could not submit group fund from SubmitFundRequest")
- }
-
- resp.Success = success
- }
-
- err = json.NewEncoder(w).Encode(resp)
- if err != nil {
- log.Error().Err(err).Msg("Could not deliver response in SubmitFund call")
- }
- }
|