mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-03 09:52:26 +02:00
[API] generalize list header (#16551)
* Add info about list endpoints to CONTRIBUTING.md * Let all list endpoints return X-Total-Count header * Add TODOs for GetCombinedCommitStatusByRef * Fix models/issue_stopwatch.go * Rrefactor models.ListDeployKeys * Introduce helper func and use them for SetLinkHeader related func
This commit is contained in:
parent
ca13e1d56c
commit
2289580bb7
88 changed files with 637 additions and 329 deletions
|
@ -83,7 +83,7 @@ func ListTrackedTimes(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
opts := models.FindTrackedTimesOptions{
|
||||
opts := &models.FindTrackedTimesOptions{
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
RepositoryID: ctx.Repo.Repository.ID,
|
||||
IssueID: issue.ID,
|
||||
|
@ -119,6 +119,12 @@ func ListTrackedTimes(ctx *context.APIContext) {
|
|||
}
|
||||
}
|
||||
|
||||
count, err := models.CountTrackedTimes(opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
trackedTimes, err := models.GetTrackedTimes(opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTrackedTimes", err)
|
||||
|
@ -128,6 +134,8 @@ func ListTrackedTimes(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(count)
|
||||
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(trackedTimes))
|
||||
}
|
||||
|
||||
|
@ -423,7 +431,7 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
opts := models.FindTrackedTimesOptions{
|
||||
opts := &models.FindTrackedTimesOptions{
|
||||
UserID: user.ID,
|
||||
RepositoryID: ctx.Repo.Repository.ID,
|
||||
}
|
||||
|
@ -493,7 +501,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
opts := models.FindTrackedTimesOptions{
|
||||
opts := &models.FindTrackedTimesOptions{
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
RepositoryID: ctx.Repo.Repository.ID,
|
||||
}
|
||||
|
@ -530,6 +538,12 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
|
|||
}
|
||||
}
|
||||
|
||||
count, err := models.CountTrackedTimes(opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
trackedTimes, err := models.GetTrackedTimes(opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTrackedTimes", err)
|
||||
|
@ -539,6 +553,8 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(count)
|
||||
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(trackedTimes))
|
||||
}
|
||||
|
||||
|
@ -573,7 +589,7 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/TrackedTimeList"
|
||||
|
||||
opts := models.FindTrackedTimesOptions{
|
||||
opts := &models.FindTrackedTimesOptions{
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
UserID: ctx.User.ID,
|
||||
}
|
||||
|
@ -584,6 +600,12 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
count, err := models.CountTrackedTimes(opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
trackedTimes, err := models.GetTrackedTimes(opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTrackedTimesByUser", err)
|
||||
|
@ -595,5 +617,6 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(count)
|
||||
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(trackedTimes))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue