Skip to content

Commit

Permalink
[#675] fix: dashboard page fetch http 422 with DAG list API (#680)
Browse files Browse the repository at this point in the history
  • Loading branch information
yohamta committed Sep 8, 2024
1 parent 3c4f636 commit 87a33e6
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 529 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ open-coverage:
# lint runs the linter.
lint: golangci-lint

# swagger generates the swagger server code.
swagger: clean-swagger gen-swagger
# api generates the swagger server code.
api: clean-swagger gen-swagger

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

##############################################################################
Expand Down
6 changes: 3 additions & 3 deletions swagger.yaml → api.v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ paths:
parameters:
- name: page
in: query
required: true
required: false
type: integer
- name: limit
in: query
required: true
required: false
type: integer
- name: searchName
in: query
Expand Down Expand Up @@ -784,4 +784,4 @@ definitions:
type: string
required:
- Tags
- Errors
- Errors
2 changes: 1 addition & 1 deletion docs/source/locale/ja/LC_MESSAGES/rest.po
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ msgstr ""
#: ../../source/rest.rst:8 f025ce93dadd4f23b4837d5c83f4f5f5
msgid ""
"See the `OpenAPI Schema for Dagu <https://github.com/dagu-"
"dev/dagu/blob/main/swagger.yaml>`_ for more details."
"dev/dagu/blob/main/api.v1.yaml>`_ for more details."
msgstr ""

#: ../../source/rest.rst:10 c6a6f4609e584ebb92c6f0b934f458c7
Expand Down
2 changes: 1 addition & 1 deletion docs/source/locale/zh/LC_MESSAGES/rest.po
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ msgstr ""
#: ../../source/rest.rst:8 4408484915c24e908d1c23719ac9b356
msgid ""
"See the `OpenAPI Schema for Dagu <https://github.com/dagu-"
"dev/dagu/blob/main/swagger.yaml>`_ for more details."
"dev/dagu/blob/main/api.v1.yaml>`_ for more details."
msgstr ""

#: ../../source/rest.rst:10 233a08827cda408aaa69278af4faf86d
Expand Down
2 changes: 1 addition & 1 deletion docs/source/rest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ REST API Docs

Dagu server provides simple APIs to query and control DAGs.

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

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

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/go-openapi/swag v0.23.0
github.com/go-openapi/validate v0.24.0
github.com/go-resty/resty/v2 v2.7.0
github.com/go-swagger/go-swagger v0.31.0
github.com/go-swagger/go-swagger v0.30.5
github.com/golangci/golangci-lint v1.59.1
github.com/google/addlicense v1.1.1
github.com/google/uuid v1.6.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,10 @@ github.com/go-openapi/validate v0.24.0/go.mod h1:iyeX1sEufmv3nPbBdX3ieNviWnOZaJ1
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-swagger/go-swagger v0.31.0 h1:H8eOYQnY2u7vNKWDNykv2xJP3pBhRG/R+SOCAmKrLlc=
github.com/go-swagger/go-swagger v0.31.0/go.mod h1:WSigRRWEig8zV6t6Sm8Y+EmUjlzA/HoaZJ5edupq7po=
github.com/go-swagger/go-swagger v0.30.5 h1:SQ2+xSonWjjoEMOV5tcOnZJVlfyUfCBhGQGArS1b9+U=
github.com/go-swagger/go-swagger v0.30.5/go.mod h1:cWUhSyCNqV7J1wkkxfr5QmbcnCewetCdvEXqgPvbc/Q=
github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013 h1:l9rI6sNaZgNC0LnF3MiE+qTmyBA/tZAg1rtyrGbUMK0=
github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013/go.mod h1:b65mBPzqzZWxOZGxSWrqs4GInLIn+u99Q9q7p+GKni0=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/go-toolsmith/astcast v1.1.0 h1:+JN9xZV1A+Re+95pgnMgDboWNVnIMMQXwfBwLRPgSC8=
Expand Down
25 changes: 14 additions & 11 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package client
import (
"errors"
"fmt"
"math"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -292,13 +291,8 @@ func (e *client) GetAllStatus() (
return ret, errs, err
}

func (e *client) getPageCount(total int64, limit int64) int {
pageCount := int(math.Ceil(float64(total) / float64(limit)))
if pageCount == 0 {
pageCount = 1
}

return pageCount
func (e *client) getPageCount(total int, limit int) int {
return (total-1)/(limit) + 1
}

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

page := 1
if params.Page != nil {
page = int(*params.Page)
}
limit := 100
if params.Limit != nil {
limit = int(*params.Limit)
}

if dagListPaginationResult, err = dagStore.ListPagination(persistence.DAGListPaginationArgs{
Page: int(params.Page),
Limit: int(params.Limit),
Page: page,
Limit: limit,
Name: params.SearchName,
Tag: params.SearchTag,
}); err != nil {
Expand All @@ -327,7 +330,7 @@ func (e *client) GetAllStatusPagination(params dags.ListDagsParams) ([]*DAGStatu
}

return dagStatusList, &DagListPaginationSummaryResult{
PageCount: e.getPageCount(int64(dagListPaginationResult.Count), params.Limit),
PageCount: e.getPageCount(dagListPaginationResult.Count, limit),
ErrorList: dagListPaginationResult.ErrorList,
}, nil
}
Expand Down
Loading

0 comments on commit 87a33e6

Please sign in to comment.