You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stop_watch.go 989B

12345678910111213141516171819202122232425262728293031323334353637383940
  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/modules/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.Error(http.StatusInternalServerError, err.Error())
  19. return
  20. }
  21. count, err := issues_model.CountUserStopwatches(ctx, ctx.Doer.ID)
  22. if err != nil {
  23. ctx.Error(http.StatusInternalServerError, err.Error())
  24. return
  25. }
  26. apiSWs, err := convert.ToStopWatches(sws)
  27. if err != nil {
  28. ctx.Error(http.StatusInternalServerError, err.Error())
  29. return
  30. }
  31. ctx.SetTotalCountHeader(count)
  32. ctx.JSON(http.StatusOK, apiSWs)
  33. }