Skip to content

Commit 87a33e6

Browse files
authoredSep 8, 2024··
[#675] fix: dashboard page fetch http 422 with DAG list API (#680)
1 parent 3c4f636 commit 87a33e6

File tree

15 files changed

+56
-529
lines changed

15 files changed

+56
-529
lines changed
 

‎Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ open-coverage:
127127
# lint runs the linter.
128128
lint: golangci-lint
129129

130-
# swagger generates the swagger server code.
131-
swagger: clean-swagger gen-swagger
130+
# api generates the swagger server code.
131+
api: clean-swagger gen-swagger
132132

133133
# certs generates the certificates to use in the development environment.
134134
certs: ${CERTS_DIR} ${SERVER_CERT_FILE} ${CLIENT_CERT_FILE} certs-check
@@ -228,8 +228,8 @@ clean-swagger:
228228
gen-swagger:
229229
@echo "${COLOR_GREEN}Generating the swagger server code...${COLOR_RESET}"
230230
@GOBIN=${LOCAL_BIN_DIR} go install $(PKG_swagger)
231-
@${LOCAL_BIN_DIR}/swagger validate ./swagger.yaml
232-
@${LOCAL_BIN_DIR}/swagger generate server -t ${FE_GEN_DIR} --server-package=restapi --exclude-main -f ./swagger.yaml
231+
@${LOCAL_BIN_DIR}/swagger validate ./api.v1.yaml
232+
@${LOCAL_BIN_DIR}/swagger generate server -t ${FE_GEN_DIR} --server-package=restapi --exclude-main -f ./api.v1.yaml
233233
@go mod tidy
234234

235235
##############################################################################

‎swagger.yaml ‎api.v1.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ paths:
3030
parameters:
3131
- name: page
3232
in: query
33-
required: true
33+
required: false
3434
type: integer
3535
- name: limit
3636
in: query
37-
required: true
37+
required: false
3838
type: integer
3939
- name: searchName
4040
in: query
@@ -784,4 +784,4 @@ definitions:
784784
type: string
785785
required:
786786
- Tags
787-
- Errors
787+
- Errors

‎docs/source/locale/ja/LC_MESSAGES/rest.po

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ msgstr ""
3030
#: ../../source/rest.rst:8 f025ce93dadd4f23b4837d5c83f4f5f5
3131
msgid ""
3232
"See the `OpenAPI Schema for Dagu <https://github.com/dagu-"
33-
"dev/dagu/blob/main/swagger.yaml>`_ for more details."
33+
"dev/dagu/blob/main/api.v1.yaml>`_ for more details."
3434
msgstr ""
3535

3636
#: ../../source/rest.rst:10 c6a6f4609e584ebb92c6f0b934f458c7

‎docs/source/locale/zh/LC_MESSAGES/rest.po

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ msgstr ""
3030
#: ../../source/rest.rst:8 4408484915c24e908d1c23719ac9b356
3131
msgid ""
3232
"See the `OpenAPI Schema for Dagu <https://github.com/dagu-"
33-
"dev/dagu/blob/main/swagger.yaml>`_ for more details."
33+
"dev/dagu/blob/main/api.v1.yaml>`_ for more details."
3434
msgstr ""
3535

3636
#: ../../source/rest.rst:10 233a08827cda408aaa69278af4faf86d

‎docs/source/rest.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ REST API Docs
55

66
Dagu server provides simple APIs to query and control DAGs.
77

8-
See the `OpenAPI Schema for Dagu <https://github.com/dagu-org/dagu/blob/main/swagger.yaml>`_ for more details.
8+
See the `OpenAPI Schema for Dagu <https://github.com/dagu-org/dagu/blob/main/api.v1.yaml>`_ for more details.
99

1010
**Endpoint** : `localhost:8080` (default)
1111

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/go-openapi/swag v0.23.0
1616
github.com/go-openapi/validate v0.24.0
1717
github.com/go-resty/resty/v2 v2.7.0
18-
github.com/go-swagger/go-swagger v0.31.0
18+
github.com/go-swagger/go-swagger v0.30.5
1919
github.com/golangci/golangci-lint v1.59.1
2020
github.com/google/addlicense v1.1.1
2121
github.com/google/uuid v1.6.0

‎go.sum

+4-2
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,10 @@ github.com/go-openapi/validate v0.24.0/go.mod h1:iyeX1sEufmv3nPbBdX3ieNviWnOZaJ1
229229
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
230230
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
231231
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
232-
github.com/go-swagger/go-swagger v0.31.0 h1:H8eOYQnY2u7vNKWDNykv2xJP3pBhRG/R+SOCAmKrLlc=
233-
github.com/go-swagger/go-swagger v0.31.0/go.mod h1:WSigRRWEig8zV6t6Sm8Y+EmUjlzA/HoaZJ5edupq7po=
232+
github.com/go-swagger/go-swagger v0.30.5 h1:SQ2+xSonWjjoEMOV5tcOnZJVlfyUfCBhGQGArS1b9+U=
233+
github.com/go-swagger/go-swagger v0.30.5/go.mod h1:cWUhSyCNqV7J1wkkxfr5QmbcnCewetCdvEXqgPvbc/Q=
234+
github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013 h1:l9rI6sNaZgNC0LnF3MiE+qTmyBA/tZAg1rtyrGbUMK0=
235+
github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013/go.mod h1:b65mBPzqzZWxOZGxSWrqs4GInLIn+u99Q9q7p+GKni0=
234236
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
235237
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
236238
github.com/go-toolsmith/astcast v1.1.0 h1:+JN9xZV1A+Re+95pgnMgDboWNVnIMMQXwfBwLRPgSC8=

‎internal/client/client.go

+14-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package client
1818
import (
1919
"errors"
2020
"fmt"
21-
"math"
2221
"os"
2322
"os/exec"
2423
"path/filepath"
@@ -292,13 +291,8 @@ func (e *client) GetAllStatus() (
292291
return ret, errs, err
293292
}
294293

295-
func (e *client) getPageCount(total int64, limit int64) int {
296-
pageCount := int(math.Ceil(float64(total) / float64(limit)))
297-
if pageCount == 0 {
298-
pageCount = 1
299-
}
300-
301-
return pageCount
294+
func (e *client) getPageCount(total int, limit int) int {
295+
return (total-1)/(limit) + 1
302296
}
303297

304298
func (e *client) GetAllStatusPagination(params dags.ListDagsParams) ([]*DAGStatus, *DagListPaginationSummaryResult, error) {
@@ -310,9 +304,18 @@ func (e *client) GetAllStatusPagination(params dags.ListDagsParams) ([]*DAGStatu
310304
currentStatus *DAGStatus
311305
)
312306

307+
page := 1
308+
if params.Page != nil {
309+
page = int(*params.Page)
310+
}
311+
limit := 100
312+
if params.Limit != nil {
313+
limit = int(*params.Limit)
314+
}
315+
313316
if dagListPaginationResult, err = dagStore.ListPagination(persistence.DAGListPaginationArgs{
314-
Page: int(params.Page),
315-
Limit: int(params.Limit),
317+
Page: page,
318+
Limit: limit,
316319
Name: params.SearchName,
317320
Tag: params.SearchTag,
318321
}); err != nil {
@@ -327,7 +330,7 @@ func (e *client) GetAllStatusPagination(params dags.ListDagsParams) ([]*DAGStatu
327330
}
328331

329332
return dagStatusList, &DagListPaginationSummaryResult{
330-
PageCount: e.getPageCount(int64(dagListPaginationResult.Count), params.Limit),
333+
PageCount: e.getPageCount(dagListPaginationResult.Count, limit),
331334
ErrorList: dagListPaginationResult.ErrorList,
332335
}, nil
333336
}

‎internal/client/client_test.go

-471
Large diffs are not rendered by default.

‎internal/frontend/gen/restapi/configure_dagu.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"github.com/dagu-org/dagu/internal/frontend/gen/restapi/operations/dags"
3232
)
3333

34-
//go:generate swagger generate server --target ../../frontend --name Dagu --spec ../../../swagger.yaml --principal any --exclude-main
34+
//go:generate swagger generate server --target ../../frontend --name Dagu --spec ../../../api.v1.yaml --principal any --exclude-main
3535

3636
func configureFlags(api *operations.DaguAPI) {
3737
// handlers.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... }

‎internal/frontend/gen/restapi/embedded_spec.go

+4-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎internal/frontend/gen/restapi/operations/dags/list_dags_parameters.go

+10-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎internal/frontend/gen/restapi/operations/dags/list_dags_urlbuilder.go

+10-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎internal/frontend/gen/restapi/operations/dags/post_dag_action.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎internal/frontend/gen/restapi/server.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.