Skip to content

Commit bc4d776

Browse files
authored
Paginated response fixes (#118)
* Changed test_result.go to use paginated responses * Renamed paginated response to only be "list" * Updated CHANGELOG.md * godoc fix
1 parent 12df7da commit bc4d776

File tree

9 files changed

+43
-20
lines changed

9 files changed

+43
-20
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ This project tries to follow [SemVer 2.0.0](https://semver.org/).
5858
`"totalCount"` field for the overall query.
5959

6060
By default all these new endpoints use a default limit of 100, but this can
61-
be disabled by specifying `?limit=0`. (#109)
61+
be disabled by specifying `?limit=0`. (#109, #118)
6262

6363
- Added configuration of specific origins for CORS via the environment variable
6464
`WHARF_HTTP_CORS_ALLOWORIGINS` or the YAML key `http.cors.allowOrigins`. This
@@ -95,7 +95,7 @@ This project tries to follow [SemVer 2.0.0](https://semver.org/).
9595
- test_result_detail
9696
- test_result_summary
9797

98-
- Added test-result specific endpoints: (#43)
98+
- Added test-result specific endpoints: (#43, #118)
9999

100100
- `POST /build/{buildid}/test-result`
101101

@@ -116,7 +116,7 @@ This project tries to follow [SemVer 2.0.0](https://semver.org/).
116116

117117
Use `GET /build/{buildid}/test-result/list-summary` instead. The response
118118
data is slightly different; it has additional properties, and does not have a
119-
`status` property. (#43, #77)
119+
`status` property. (#43, #77, #118)
120120

121121
- Changed format of all endpoint's path parameters from all lowercase to
122122
camelCase: (#76)

artifact.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (m artifactModule) getBuildArtifactListHandler(c *gin.Context) {
120120
}
121121

122122
c.JSON(http.StatusOK, response.PaginatedArtifacts{
123-
Artifacts: modelconv.DBArtifactsToResponses(dbArtifacts),
123+
List: modelconv.DBArtifactsToResponses(dbArtifacts),
124124
TotalCount: totalCount,
125125
})
126126
}

build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (m buildModule) getBuildListHandler(c *gin.Context) {
237237
}
238238

239239
c.JSON(http.StatusOK, response.PaginatedBuilds{
240-
Builds: modelconv.DBBuildsToResponses(dbBuilds),
240+
List: modelconv.DBBuildsToResponses(dbBuilds),
241241
TotalCount: totalCount,
242242
})
243243
}

internal/deprecated/project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (m ProjectModule) getProjectBuildListHandler(c *gin.Context) {
199199
}
200200

201201
resPaginated := response.PaginatedBuilds{
202-
Builds: modelconv.DBBuildsToResponses(dbBuilds),
202+
List: modelconv.DBBuildsToResponses(dbBuilds),
203203
TotalCount: count,
204204
}
205205
c.JSON(http.StatusOK, resPaginated)

pkg/model/response/response.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,37 +143,51 @@ type Log struct {
143143
// PaginatedArtifacts is a list of artifacts as well as the explicit total count
144144
// field.
145145
type PaginatedArtifacts struct {
146-
Artifacts []Artifact `json:"artifacts"`
146+
List []Artifact `json:"list"`
147147
TotalCount int64 `json:"totalCount"`
148148
}
149149

150150
// PaginatedBuilds is a list of builds as well as an explicit total count field.
151151
type PaginatedBuilds struct {
152-
Builds []Build `json:"builds"`
152+
List []Build `json:"list"`
153153
TotalCount int64 `json:"totalCount"`
154154
}
155155

156156
// PaginatedProjects is a list of projects as well as the explicit total count
157157
// field.
158158
type PaginatedProjects struct {
159-
Projects []Project `json:"projects"`
159+
List []Project `json:"list"`
160160
TotalCount int64 `json:"totalCount"`
161161
}
162162

163163
// PaginatedTokens is a list of tokens as well as the explicit total count
164164
// field.
165165
type PaginatedTokens struct {
166-
Tokens []Token `json:"tokens"`
166+
List []Token `json:"list"`
167167
TotalCount int64 `json:"totalCount"`
168168
}
169169

170170
// PaginatedProviders is a list of providers as well as the explicit total count
171171
// field.
172172
type PaginatedProviders struct {
173-
Providers []Provider `json:"providers"`
173+
List []Provider `json:"list"`
174174
TotalCount int64 `json:"totalCount"`
175175
}
176176

177+
// PaginatedTestResultDetails is a list of test result details as well as the
178+
// explicit total count field.
179+
type PaginatedTestResultDetails struct {
180+
List []TestResultDetail `json:"list"`
181+
TotalCount int64 `json:"totalCount"`
182+
}
183+
184+
// PaginatedTestResultSummaries is a list of test result summaries as well as
185+
// the explicit total count field.
186+
type PaginatedTestResultSummaries struct {
187+
List []TestResultSummary `json:"list"`
188+
TotalCount int64 `json:"totalCount"`
189+
}
190+
177191
// Ping pongs.
178192
type Ping struct {
179193
Message string `json:"message" example:"pong"`

project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (m projectModule) getProjectListHandler(c *gin.Context) {
145145
}
146146

147147
c.JSON(http.StatusOK, response.PaginatedProjects{
148-
Projects: modelconv.DBProjectsToResponses(dbProjects),
148+
List: modelconv.DBProjectsToResponses(dbProjects),
149149
TotalCount: totalCount,
150150
})
151151
}

provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (m providerModule) getProviderListHandler(c *gin.Context) {
113113
}
114114

115115
c.JSON(http.StatusOK, response.PaginatedProviders{
116-
Providers: modelconv.DBProvidersToResponses(dbProviders),
116+
List: modelconv.DBProvidersToResponses(dbProviders),
117117
TotalCount: totalCount,
118118
})
119119
}

test_result.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (m buildTestResultModule) createBuildTestResultHandler(c *gin.Context) {
126126
// @summary Get all test result details for specified build
127127
// @tags test-result
128128
// @param buildId path uint true "Build ID" minimum(0)
129-
// @success 200 {object} []response.TestResultDetail
129+
// @success 200 {object} response.PaginatedTestResultDetails
130130
// @failure 400 {object} problem.Response "Bad request"
131131
// @failure 502 {object} problem.Response "Database is unreachable"
132132
// @router /build/{buildId}/test-result/detail [get]
@@ -150,15 +150,18 @@ func (m buildTestResultModule) getBuildAllTestResultDetailListHandler(c *gin.Con
150150
}
151151

152152
resDetails := modelconv.DBTestResultDetailsToResponses(dbDetails)
153-
c.JSON(http.StatusOK, resDetails)
153+
c.JSON(http.StatusOK, response.PaginatedTestResultDetails{
154+
List: resDetails,
155+
TotalCount: int64(len(resDetails)),
156+
})
154157
}
155158

156159
// getBuildAllTestResultSummaryListHandler godoc
157160
// @id getBuildAllTestResultSummaryList
158161
// @summary Get all test result summaries for specified build
159162
// @tags test-result
160163
// @param buildId path uint true "Build ID" minimum(0)
161-
// @success 200 {object} []response.TestResultSummary
164+
// @success 200 {object} response.PaginatedTestResultSummaries
162165
// @failure 400 {object} problem.Response "Bad Request"
163166
// @failure 502 {object} problem.Response "Database is unreachable"
164167
// @router /build/{buildId}/test-result/summary [get]
@@ -186,7 +189,10 @@ func (m buildTestResultModule) getBuildAllTestResultSummaryListHandler(c *gin.Co
186189
resSummaries[i] = modelconv.DBTestResultSummaryToResponse(dbSummary)
187190
}
188191

189-
c.JSON(http.StatusOK, resSummaries)
192+
c.JSON(http.StatusOK, response.PaginatedTestResultSummaries{
193+
List: resSummaries,
194+
TotalCount: int64(len(resSummaries)),
195+
})
190196
}
191197

192198
// getBuildTestResultSummaryHandler godoc
@@ -233,7 +239,7 @@ func (m buildTestResultModule) getBuildTestResultSummaryHandler(c *gin.Context)
233239
// @tags test-result
234240
// @param buildId path uint true "Build ID" minimum(0)
235241
// @param artifactId path uint true "Artifact ID" minimum(0)
236-
// @success 200 {object} []response.TestResultDetail
242+
// @success 200 {object} response.PaginatedTestResultDetails
237243
// @failure 400 {object} problem.Response "Bad Request"
238244
// @failure 502 {object} problem.Response "Database is unreachable"
239245
// @router /build/{buildId}/test-result/summary/{artifactId}/detail [get]
@@ -262,7 +268,10 @@ func (m buildTestResultModule) getBuildTestResultDetailListHandler(c *gin.Contex
262268
}
263269

264270
resDetails := modelconv.DBTestResultDetailsToResponses(dbDetails)
265-
c.JSON(http.StatusOK, resDetails)
271+
c.JSON(http.StatusOK, response.PaginatedTestResultDetails{
272+
List: resDetails,
273+
TotalCount: int64(len(dbDetails)),
274+
})
266275
}
267276

268277
// getBuildAllTestResultListSummaryHandler godoc

token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (m tokenModule) getTokenListHandler(c *gin.Context) {
9898
}
9999

100100
c.JSON(http.StatusOK, response.PaginatedTokens{
101-
Tokens: modelconv.DBTokensToResponses(dbTokens),
101+
List: modelconv.DBTokensToResponses(dbTokens),
102102
TotalCount: totalCount,
103103
})
104104
}

0 commit comments

Comments
 (0)