gitea源码

stop_watch.go 1007B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package user
  4. import (
  5. "net/http"
  6. "code.gitea.io/gitea/models/db"
  7. issues_model "code.gitea.io/gitea/models/issues"
  8. "code.gitea.io/gitea/services/context"
  9. "code.gitea.io/gitea/services/convert"
  10. )
  11. // GetStopwatches get all stopwatches
  12. func GetStopwatches(ctx *context.Context) {
  13. sws, err := issues_model.GetUserStopwatches(ctx, ctx.Doer.ID, db.ListOptions{
  14. Page: ctx.FormInt("page"),
  15. PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
  16. })
  17. if err != nil {
  18. ctx.HTTPError(http.StatusInternalServerError, err.Error())
  19. return
  20. }
  21. count, err := issues_model.CountUserStopwatches(ctx, ctx.Doer.ID)
  22. if err != nil {
  23. ctx.HTTPError(http.StatusInternalServerError, err.Error())
  24. return
  25. }
  26. apiSWs, err := convert.ToStopWatches(ctx, sws)
  27. if err != nil {
  28. ctx.HTTPError(http.StatusInternalServerError, err.Error())
  29. return
  30. }
  31. ctx.SetTotalCountHeader(count)
  32. ctx.JSON(http.StatusOK, apiSWs)
  33. }