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