enroll_handler.go 829 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package acquirer
  2. import (
  3. "net/http"
  4. "git.i2edu.net/i2/i2-bill-api/internal/logic/acquirer"
  5. "git.i2edu.net/i2/i2-bill-api/internal/svc"
  6. "git.i2edu.net/i2/i2-bill-api/internal/types"
  7. "git.i2edu.net/i2/i2-bill-api/internal/utils"
  8. "git.i2edu.net/i2/go-zero/rest/httpx"
  9. )
  10. func EnrollHandler(ctx *svc.ServiceContext) http.HandlerFunc {
  11. return func(w http.ResponseWriter, r *http.Request) {
  12. uid, skey, err := ctx.GetClaims(r)
  13. if err != nil {
  14. httpx.OkJson(w, utils.ReturnHTTPFail(err))
  15. return
  16. }
  17. var req types.EnrollRequest
  18. if err := httpx.Parse(r, &req); err != nil {
  19. httpx.Error(w, err)
  20. return
  21. }
  22. l := acquirer.NewEnrollLogic(r.Context(), ctx)
  23. l.UserId = uid
  24. l.SessionKey = skey
  25. resp, err := l.Enroll(req)
  26. if err != nil {
  27. httpx.Error(w, err)
  28. } else {
  29. httpx.OkJson(w, resp)
  30. }
  31. }
  32. }