Skip to content

Commit

Permalink
新增过滤+list
Browse files Browse the repository at this point in the history
  • Loading branch information
hulutech-web committed Oct 19, 2024
1 parent 0b22ee1 commit 390dc1d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,21 @@ func (r *MaterialController) Index(ctx http.Context) http.Response {
}
}
```

五、列表查询+加上过滤条件:其中conditionMap:map[string]interface{}{}过滤条件,[]string{"excepts"}...为排除的key值
```go

func (r *MaterialController) Index(ctx http.Context) http.Response {
var user models.User
facades.Auth(ctx).User(&user)
partner_id := cast.ToUint(ctx.Value("partner"))
materials := []models.Material{}

queries := ctx.Request().Queries()
conditionMap := map[string]interface{}{
"partner_id": partner_id,
}
result, _ := httpfacades.NewResult(ctx).SearchByParams(queries, conditionMap,[]string{"excepts"}...).List(&materials)
return result
}
```
8 changes: 8 additions & 0 deletions paginator.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,11 @@ func (r *HttpResult) ResultPagination(dest any, withes ...string) (http.Response
// 返回构建好的分页结果
return r.Context.Response().Success().Json(pageResult), nil
}

func (r *HttpResult) List(dest any) (http.Response, error) {
err := r.Query.Find(dest)
if err != nil {
return nil, err
}
return r.Context.Response().Success().Json(dest), nil
}

0 comments on commit 390dc1d

Please sign in to comment.