fix: categories filter is multiple now

This commit is contained in:
ericprd
2025-03-07 14:30:31 +08:00
parent 51b50a3132
commit c410e651ce
6 changed files with 19 additions and 20 deletions
+8 -9
View File
@@ -5,16 +5,15 @@ import (
"strings"
)
func (i *impl) GetAll(categoryCode, tagCodes string) ([]newsdomain.News, error) {
var (
category string
err error
)
func (i *impl) GetAll(categoriesCode, tagCodes string) ([]newsdomain.News, error) {
var err error
categories := []string{}
tags := []string{}
news := []newsdomain.News{}
tagCodeArr := strings.Split(tagCodes, " ")
categoryCodeArr := strings.Split(categoriesCode, " ")
if len(tagCodeArr) > 0 && tagCodeArr[0] != "" {
tags, err = i.tagRepo.GetIDsByCodes(tagCodeArr)
@@ -27,20 +26,20 @@ func (i *impl) GetAll(categoryCode, tagCodes string) ([]newsdomain.News, error)
}
}
if categoryCode != "" {
category, err = i.categoryRepo.GetIDByCode(categoryCode)
if len(categoryCodeArr) > 0 && categoryCodeArr[0] != "" {
categories, err = i.categoryRepo.GetIDByCode(categoryCodeArr)
if err != nil {
return news, err
}
if category == "" {
if len(categories) < 1 {
return news, nil
}
}
filter := newsdomain.NewsFilter{
Tags: tags,
Category: category,
Category: categories,
}
return i.newsRepo.GetAll(filter)
}