Merge branch 'main' of https://github.com/ardeman/project-legalgo-go
* 'main' of https://github.com/ardeman/project-legalgo-go: fix: search news title by query
This commit is contained in:
commit
4fbfa9c2c9
@ -34,6 +34,10 @@ func (a *accessor) GetAll(filter newsdomain.NewsFilter) ([]newsdomain.NewsRespon
|
||||
query = query.Where("news.live_at <= ?", timeutils.Now())
|
||||
}
|
||||
|
||||
if filter.Search != "" {
|
||||
query = query.Where("news.title ILIKE ?", "%"+filter.Search+"%")
|
||||
}
|
||||
|
||||
query.
|
||||
Select("news.*, COUNT(content_logs.content_id) as views").
|
||||
Group("news.id").
|
||||
|
||||
@ -24,11 +24,13 @@ func GetAll(
|
||||
category := query.Get("categories")
|
||||
tags := query.Get("tags")
|
||||
activeOnly := query.Get("active")
|
||||
search := query.Get("q")
|
||||
|
||||
news, err = newsSvc.GetAll(newsdomain.Filter{
|
||||
Category: category,
|
||||
Tags: tags,
|
||||
Active: activeOnly,
|
||||
Search: search,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
@ -56,11 +56,12 @@ type NewsUpdate struct {
|
||||
}
|
||||
|
||||
type Filter struct {
|
||||
Category, Tags, Active string
|
||||
Category, Tags, Active, Search string
|
||||
}
|
||||
|
||||
type NewsFilter struct {
|
||||
Tags []string
|
||||
Category []string
|
||||
Active string
|
||||
Search string
|
||||
}
|
||||
|
||||
@ -41,6 +41,7 @@ func (i *impl) GetAll(filter newsdomain.Filter) ([]newsdomain.NewsResponse, erro
|
||||
Tags: tags,
|
||||
Category: categories,
|
||||
Active: filter.Active,
|
||||
Search: filter.Search,
|
||||
}
|
||||
return i.newsRepo.GetAll(filterSpec)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user