Skip to content

Commit

Permalink
feat: allows query project by list of types (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
namnhce authored Mar 29, 2024
1 parent e3d4f55 commit 3e96c5b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/handler/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (h *handler) List(c *gin.Context) {
projects, total, err := h.store.Project.All(h.repo.DB(), project.GetListProjectInput{
Statuses: query.Status,
Name: query.Name,
Type: query.Type,
Types: query.Type,
}, pagination)
if err != nil {
l.Error(err, "error query project from db")
Expand Down
10 changes: 7 additions & 3 deletions pkg/handler/project/request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type GetListProjectInput struct {

Name string `form:"name" json:"name"`
Status []string `form:"status" json:"status"`
Type string `form:"type" json:"type"`
Type []string `form:"type" json:"type"`
} // @name GetListProjectInput

type UpdateProjectGeneralInfoRequest struct {
Expand Down Expand Up @@ -104,8 +104,12 @@ func (i *GetListProjectInput) StandardizeInput() {
}

func (i *GetListProjectInput) Validate() error {
if i.Type != "" && !model.ProjectType(i.Type).IsValid() {
return errs.ErrInvalidProjectType
if len(i.Type) > 0 {
for _, projectType := range i.Type {
if utils.RemoveAllSpace(projectType) != "" && !model.ProjectType(projectType).IsValid() {
return errs.ErrInvalidProjectType
}
}
}
if len(i.Status) > 0 {
for _, status := range i.Status {
Expand Down
4 changes: 2 additions & 2 deletions pkg/store/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func (s *store) All(db *gorm.DB, input GetListProjectInput, pagination model.Pag
query = query.Where("projects.status IN ?", input.Statuses)
}

if input.Type != "" {
query = query.Where("projects.type = ?", input.Type)
if len(input.Types) > 0 {
query = query.Where("projects.type IN ?", input.Types)
}

if input.AllowsSendingSurvey {
Expand Down
2 changes: 1 addition & 1 deletion pkg/store/project/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package project
type GetListProjectInput struct {
Statuses []string `json:"statuses"`
Name string `json:"name"`
Type string `json:"type"`
Types []string `json:"type"`
AllowsSendingSurvey bool `json:"allowsSendingSurvey"`
}

0 comments on commit 3e96c5b

Please sign in to comment.