diff --git a/internal/accessor/news/get_all.go b/internal/accessor/news/get_all.go index 246bfd1..34098e6 100644 --- a/internal/accessor/news/get_all.go +++ b/internal/accessor/news/get_all.go @@ -34,6 +34,10 @@ func (a *accessor) GetAll(filter newsdomain.NewsFilter) ([]newsdomain.News, erro 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 clicked"). Group("news.id"). diff --git a/internal/api/http/news/get_all.go b/internal/api/http/news/get_all.go index d37e6c8..362afb2 100644 --- a/internal/api/http/news/get_all.go +++ b/internal/api/http/news/get_all.go @@ -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 { diff --git a/internal/domain/news/spec.go b/internal/domain/news/spec.go index 4e58d6a..6efca53 100644 --- a/internal/domain/news/spec.go +++ b/internal/domain/news/spec.go @@ -52,11 +52,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 } diff --git a/internal/services/news/get_all.go b/internal/services/news/get_all.go index ae59127..3d15016 100644 --- a/internal/services/news/get_all.go +++ b/internal/services/news/get_all.go @@ -41,6 +41,7 @@ func (i *impl) GetAll(filter newsdomain.Filter) ([]newsdomain.News, error) { Tags: tags, Category: categories, Active: filter.Active, + Search: filter.Search, } return i.newsRepo.GetAll(filterSpec) }