fix: filter active in news

This commit is contained in:
ericprd
2025-03-20 13:13:28 +08:00
parent 8d7500610e
commit 24f0fe6efa
5 changed files with 33 additions and 8 deletions
+6 -5
View File
@@ -5,15 +5,15 @@ import (
"strings"
)
func (i *impl) GetAll(categoriesCode, tagCodes string) ([]newsdomain.News, error) {
func (i *impl) GetAll(filter newsdomain.Filter) ([]newsdomain.News, error) {
var err error
categories := []string{}
tags := []string{}
news := []newsdomain.News{}
tagCodeArr := strings.Split(tagCodes, " ")
categoryCodeArr := strings.Split(categoriesCode, " ")
tagCodeArr := strings.Split(filter.Tags, " ")
categoryCodeArr := strings.Split(filter.Category, " ")
if len(tagCodeArr) > 0 && tagCodeArr[0] != "" {
tags, err = i.tagRepo.GetIDsByCodes(tagCodeArr)
@@ -37,9 +37,10 @@ func (i *impl) GetAll(categoriesCode, tagCodes string) ([]newsdomain.News, error
}
}
filter := newsdomain.NewsFilter{
filterSpec := newsdomain.NewsFilter{
Tags: tags,
Category: categories,
Active: filter.Active,
}
return i.newsRepo.GetAll(filter)
return i.newsRepo.GetAll(filterSpec)
}
+1 -1
View File
@@ -16,7 +16,7 @@ type impl struct {
}
type News interface {
GetAll(string, string) ([]newsdomain.News, error)
GetAll(filter newsdomain.Filter) ([]newsdomain.News, error)
GetBySlug(string) (*newsdomain.News, error)
Create(newsdomain.NewsReq, string) error
Update(string, newsdomain.NewsUpdate) error