2022-04-07 12:59:56 -06:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 11:20:29 -07:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-04-07 12:59:56 -06:00
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-06-13 03:37:59 -06:00
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2022-04-07 12:59:56 -06:00
|
|
|
"code.gitea.io/gitea/modules/context"
|
2022-12-28 19:57:15 -07:00
|
|
|
"code.gitea.io/gitea/services/convert"
|
2022-04-07 12:59:56 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetStopwatches get all stopwatches
|
|
|
|
func GetStopwatches(ctx *context.Context) {
|
2022-06-13 03:37:59 -06:00
|
|
|
sws, err := issues_model.GetUserStopwatches(ctx.Doer.ID, db.ListOptions{
|
2022-04-07 12:59:56 -06:00
|
|
|
Page: ctx.FormInt("page"),
|
|
|
|
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-06-13 03:37:59 -06:00
|
|
|
count, err := issues_model.CountUserStopwatches(ctx.Doer.ID)
|
2022-04-07 12:59:56 -06:00
|
|
|
if err != nil {
|
|
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
apiSWs, err := convert.ToStopWatches(sws)
|
|
|
|
if err != nil {
|
|
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.SetTotalCountHeader(count)
|
|
|
|
ctx.JSON(http.StatusOK, apiSWs)
|
|
|
|
}
|