fix: search news title by query
This commit is contained in:
parent
09d9c4efb8
commit
a68780f09e
@ -34,6 +34,10 @@ func (a *accessor) GetAll(filter newsdomain.NewsFilter) ([]newsdomain.News, erro
|
|||||||
query = query.Where("news.live_at <= ?", timeutils.Now())
|
query = query.Where("news.live_at <= ?", timeutils.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if filter.Search != "" {
|
||||||
|
query = query.Where("news.title ILIKE ?", "%"+filter.Search+"%")
|
||||||
|
}
|
||||||
|
|
||||||
query.
|
query.
|
||||||
Select("news.*, COUNT(content_logs.content_id) as clicked").
|
Select("news.*, COUNT(content_logs.content_id) as clicked").
|
||||||
Group("news.id").
|
Group("news.id").
|
||||||
|
|||||||
@ -24,11 +24,13 @@ func GetAll(
|
|||||||
category := query.Get("categories")
|
category := query.Get("categories")
|
||||||
tags := query.Get("tags")
|
tags := query.Get("tags")
|
||||||
activeOnly := query.Get("active")
|
activeOnly := query.Get("active")
|
||||||
|
search := query.Get("q")
|
||||||
|
|
||||||
news, err = newsSvc.GetAll(newsdomain.Filter{
|
news, err = newsSvc.GetAll(newsdomain.Filter{
|
||||||
Category: category,
|
Category: category,
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
Active: activeOnly,
|
Active: activeOnly,
|
||||||
|
Search: search,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -52,11 +52,12 @@ type NewsUpdate struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Filter struct {
|
type Filter struct {
|
||||||
Category, Tags, Active string
|
Category, Tags, Active, Search string
|
||||||
}
|
}
|
||||||
|
|
||||||
type NewsFilter struct {
|
type NewsFilter struct {
|
||||||
Tags []string
|
Tags []string
|
||||||
Category []string
|
Category []string
|
||||||
Active string
|
Active string
|
||||||
|
Search string
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,6 +41,7 @@ func (i *impl) GetAll(filter newsdomain.Filter) ([]newsdomain.News, error) {
|
|||||||
Tags: tags,
|
Tags: tags,
|
||||||
Category: categories,
|
Category: categories,
|
||||||
Active: filter.Active,
|
Active: filter.Active,
|
||||||
|
Search: filter.Search,
|
||||||
}
|
}
|
||||||
return i.newsRepo.GetAll(filterSpec)
|
return i.newsRepo.GetAll(filterSpec)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user