47 lines
924 B
Go
47 lines
924 B
Go
package newssvc
|
|
|
|
import (
|
|
newsdomain "legalgo-BE-go/internal/domain/news"
|
|
"strings"
|
|
)
|
|
|
|
func (i *impl) GetAll(filter newsdomain.Filter) ([]newsdomain.News, error) {
|
|
var err error
|
|
|
|
categories := []string{}
|
|
tags := []string{}
|
|
news := []newsdomain.News{}
|
|
|
|
tagCodeArr := strings.Split(filter.Tags, " ")
|
|
categoryCodeArr := strings.Split(filter.Category, " ")
|
|
|
|
if len(tagCodeArr) > 0 && tagCodeArr[0] != "" {
|
|
tags, err = i.tagRepo.GetIDsByCodes(tagCodeArr)
|
|
if err != nil {
|
|
return news, err
|
|
}
|
|
|
|
if len(tags) < 1 {
|
|
return news, nil
|
|
}
|
|
}
|
|
|
|
if len(categoryCodeArr) > 0 && categoryCodeArr[0] != "" {
|
|
categories, err = i.categoryRepo.GetIDByCode(categoryCodeArr)
|
|
if err != nil {
|
|
return news, err
|
|
}
|
|
|
|
if len(categories) < 1 {
|
|
return news, nil
|
|
}
|
|
}
|
|
|
|
filterSpec := newsdomain.NewsFilter{
|
|
Tags: tags,
|
|
Category: categories,
|
|
Active: filter.Active,
|
|
}
|
|
return i.newsRepo.GetAll(filterSpec)
|
|
}
|