punch_clock_handler.go 902 B

1234567891011121314151617181920212223242526272829303132333435
  1. package user
  2. import (
  3. "net/http"
  4. "git.i2edu.net/i2/go-zero/rest/httpx"
  5. "git.i2edu.net/i2/i2-bill-api/internal/logic/user"
  6. "git.i2edu.net/i2/i2-bill-api/internal/svc"
  7. "git.i2edu.net/i2/i2-bill-api/internal/types"
  8. "git.i2edu.net/i2/i2-bill-api/internal/utils"
  9. )
  10. func PunchClockHandler(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.PunchClockRequest
  18. if err := httpx.Parse(r, &req); err != nil {
  19. httpx.OkJson(w, utils.ReturnHTTPFail(err))
  20. return
  21. }
  22. l := user.NewPunchClockLogic(r.Context(), ctx)
  23. l.UserId = uid
  24. l.SessionKey = skey
  25. resp, err := l.PunchClock(req)
  26. if err != nil {
  27. httpx.OkJson(w, utils.ReturnHTTPFail(err))
  28. } else {
  29. httpx.OkJson(w, utils.ReturnHTTPSuccess(resp))
  30. }
  31. }
  32. }