Skip to content

chore: support fuzzy match project name #1376

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

Merged
merged 1 commit into from
Jan 13, 2025
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
14 changes: 10 additions & 4 deletions api/openapispec/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,12 @@ const docTemplate = `{
"name": "name",
"in": "query"
},
{
"type": "string",
"description": "Fuzzy match project name to filter project list by.",
"name": "fuzzyName",
"in": "query"
},
{
"type": "integer",
"description": "The current page to fetch. Default to 1",
Expand Down Expand Up @@ -3753,18 +3759,18 @@ const docTemplate = `{
"constant.SourceProviderType": {
"type": "string",
"enum": [
"git",
"git",
"github",
"oci",
"local"
"local",
"git"
],
"x-enum-varnames": [
"DefaultSourceType",
"SourceProviderTypeGit",
"SourceProviderTypeGithub",
"SourceProviderTypeOCI",
"SourceProviderTypeLocal"
"SourceProviderTypeLocal",
"DefaultSourceType"
]
},
"constant.StackState": {
Expand Down
14 changes: 10 additions & 4 deletions api/openapispec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,12 @@
"name": "name",
"in": "query"
},
{
"type": "string",
"description": "Fuzzy match project name to filter project list by.",
"name": "fuzzyName",
"in": "query"
},
{
"type": "integer",
"description": "The current page to fetch. Default to 1",
Expand Down Expand Up @@ -3742,18 +3748,18 @@
"constant.SourceProviderType": {
"type": "string",
"enum": [
"git",
"git",
"github",
"oci",
"local"
"local",
"git"
],
"x-enum-varnames": [
"DefaultSourceType",
"SourceProviderTypeGit",
"SourceProviderTypeGithub",
"SourceProviderTypeOCI",
"SourceProviderTypeLocal"
"SourceProviderTypeLocal",
"DefaultSourceType"
]
},
"constant.StackState": {
Expand Down
8 changes: 6 additions & 2 deletions api/openapispec/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ definitions:
constant.SourceProviderType:
enum:
- git
- git
- github
- oci
- local
- git
type: string
x-enum-varnames:
- DefaultSourceType
- SourceProviderTypeGit
- SourceProviderTypeGithub
- SourceProviderTypeOCI
- SourceProviderTypeLocal
- DefaultSourceType
constant.StackState:
enum:
- UnSynced
Expand Down Expand Up @@ -2074,6 +2074,10 @@ paths:
in: query
name: name
type: string
- description: Fuzzy match project name to filter project list by.
in: query
name: fuzzyName
type: string
- description: The current page to fetch. Default to 1
in: query
name: page
Expand Down
1 change: 1 addition & 0 deletions pkg/domain/constant/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ var (
ErrInvalidAppConfigName = errors.New("appConfig name can only have alphanumeric characters and underscores with [a-zA-Z0-9_]")
ErrInvalidProjectID = errors.New("the project ID should be a uuid")
ErrInvalidStackID = errors.New("the stack ID should be a uuid")
ErrProjectNameAndFuzzyName = errors.New("project name and fuzzy name cannot be set at the same time")
)
1 change: 1 addition & 0 deletions pkg/domain/entity/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Project struct {
type ProjectFilter struct {
OrgID uint
Name string
FuzzyName string
Pagination *Pagination
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/infra/persistence/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func GetProjectQuery(filter *entity.ProjectFilter) (string, []interface{}) {
pattern = append(pattern, "name = ?")
args = append(args, filter.Name)
}
if filter.FuzzyName != "" {
pattern = append(pattern, "name LIKE ?")
args = append(args, fmt.Sprintf("%%%s%%", filter.FuzzyName))
}
return CombineQueryParts(pattern), args
}

Expand Down
1 change: 1 addition & 0 deletions pkg/server/handler/project/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func (h *Handler) GetProject() http.HandlerFunc {
// @Produce json
// @Param orgID query uint false "OrganizationID to filter project list by. Default to all projects."
// @Param name query string false "Project name to filter project list by. This should only return one result if set."
// @Param fuzzyName query string false "Fuzzy match project name to filter project list by."
// @Param page query uint false "The current page to fetch. Default to 1"
// @Param pageSize query uint false "The size of the page. Default to 10"
// @Success 200 {object} handler.Response{data=[]response.PaginatedProjectResponse} "Success"
Expand Down
9 changes: 9 additions & 0 deletions pkg/server/manager/project/project_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ func (m *ProjectManager) BuildProjectFilter(ctx context.Context, query *url.Valu
filter.Name = name
}

fuzzyName := query.Get("fuzzyName")
if fuzzyName != "" {
filter.FuzzyName = fuzzyName
}

if name != "" && fuzzyName != "" {
return nil, constant.ErrProjectNameAndFuzzyName
}

// Set pagination parameters.
page, _ := strconv.Atoi(query.Get("page"))
if page <= 0 {
Expand Down
Loading