2022-04-08 00:29:56 +05:30
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2022-04-08 00:29:56 +05:30
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-06-13 15:07:59 +05:30
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2024-02-27 12:42:22 +05:30
|
|
|
"code.gitea.io/gitea/services/context"
|
2022-12-29 08:27:15 +05:30
|
|
|
"code.gitea.io/gitea/services/convert"
|
2022-04-08 00:29:56 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
// GetStopwatches get all stopwatches
|
|
|
|
func GetStopwatches(ctx *context.Context) {
|
2023-09-16 20:09:12 +05:30
|
|
|
sws, err := issues_model.GetUserStopwatches(ctx, ctx.Doer.ID, db.ListOptions{
|
2022-04-08 00:29:56 +05:30
|
|
|
Page: ctx.FormInt("page"),
|
|
|
|
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-09-16 20:09:12 +05:30
|
|
|
count, err := issues_model.CountUserStopwatches(ctx, ctx.Doer.ID)
|
2022-04-08 00:29:56 +05:30
|
|
|
if err != nil {
|
|
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-14 14:07:24 +05:30
|
|
|
apiSWs, err := convert.ToStopWatches(ctx, sws)
|
2022-04-08 00:29:56 +05:30
|
|
|
if err != nil {
|
|
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.SetTotalCountHeader(count)
|
|
|
|
ctx.JSON(http.StatusOK, apiSWs)
|
|
|
|
}
|