fix: categories filter is multiple now
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user