Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: sorting active namespaces by pfb count, time or size #41

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 24 additions & 49 deletions cmd/api/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 24 additions & 49 deletions cmd/api/docs/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 18 additions & 38 deletions cmd/api/docs/swagger.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions cmd/api/handler/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,25 +308,35 @@ func (handler *NamespaceHandler) GetMessages(c echo.Context) error {
return returnArray(c, response)
}

type getActiveRequest struct {
Sort string `query:"sort" validate:"omitempty,oneof=time pfb_count size"`
}

// GetActive godoc
//
// @Summary Get last used namespace
// @Description Get last used namespace
// @Tags namespace
// @ID get-namespace-active
// @Param sort query string false "Sort field" Enums(time,pfb_count,size)
// @Produce json
// @Success 200 {array} responses.ActiveNamespace
// @Success 200 {array} responses.Namespace
// @Failure 500 {object} Error
// @Router /v1/namespace/active [get]
func (handler *NamespaceHandler) GetActive(c echo.Context) error {
active, err := handler.namespace.Active(c.Request().Context(), 5)
req, err := bindAndValidate[getActiveRequest](c)
if err != nil {
return badRequestError(c, err)
}

active, err := handler.namespace.Active(c.Request().Context(), req.Sort, 5)
if err != nil {
return handleError(c, err, handler.namespace)
}

response := make([]responses.ActiveNamespace, len(active))
response := make([]responses.Namespace, len(active))
for i := range response {
response[i] = responses.NewActiveNamespace(active[i])
response[i] = responses.NewNamespace(active[i])
}
return returnArray(c, response)
}
Expand Down
Loading
Loading