Merge pull request 'Add string search for display_name' (#336) from staging into master
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #336
This commit was merged in pull request #336.
This commit is contained in:
@@ -23,6 +23,14 @@ func (q OptionalMap) AddNotNil(column string, value interface{}) OptionalMap {
|
||||
return q
|
||||
}
|
||||
|
||||
func (q OptionalMap) Pop(column string) (interface{}, bool) {
|
||||
value, ok := q.filter[column]
|
||||
if ok {
|
||||
delete(q.filter, column)
|
||||
}
|
||||
return value, ok
|
||||
}
|
||||
|
||||
func (q OptionalMap) Map() map[string]interface{} {
|
||||
return q.filter
|
||||
}
|
||||
|
||||
@@ -84,7 +84,11 @@ func (env *Maps) GetAll(ctx context.Context) ([]model.Map, error) {
|
||||
|
||||
func (env *Maps) List(ctx context.Context, filters datastore.OptionalMap, page model.Page) ([]model.Map, error) {
|
||||
var events []model.Map
|
||||
if err := env.db.Where(filters.Map()).Offset(int((page.Number - 1) * page.Size)).Limit(int(page.Size)).Find(&events).Error; err != nil {
|
||||
tx := env.db.Model(&model.Map{})
|
||||
if displayName, ok := filters.Pop("display_name"); ok {
|
||||
tx = tx.Where("display_name ILIKE ?", "%"+displayName.(string)+"%")
|
||||
}
|
||||
if err := tx.Where(filters.Map()).Offset(int((page.Number - 1) * page.Size)).Limit(int(page.Size)).Find(&events).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user