2025-03-02 04:36:17 +08:00
|
|
|
package newssvc
|
|
|
|
|
|
2025-03-07 00:55:50 +08:00
|
|
|
import (
|
|
|
|
|
newsdomain "legalgo-BE-go/internal/domain/news"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
2025-03-02 04:36:17 +08:00
|
|
|
|
2025-03-24 15:24:52 +08:00
|
|
|
func (i *impl) GetAll(filter newsdomain.Filter) ([]newsdomain.NewsResponse, error) {
|
2025-03-07 14:30:31 +08:00
|
|
|
var err error
|
2025-03-07 00:55:50 +08:00
|
|
|
|
2025-03-07 14:30:31 +08:00
|
|
|
categories := []string{}
|
2025-03-07 00:55:50 +08:00
|
|
|
tags := []string{}
|
2025-03-24 15:24:52 +08:00
|
|
|
news := []newsdomain.NewsResponse{}
|
2025-03-07 00:55:50 +08:00
|
|
|
|
2025-03-20 13:13:28 +08:00
|
|
|
tagCodeArr := strings.Split(filter.Tags, " ")
|
|
|
|
|
categoryCodeArr := strings.Split(filter.Category, " ")
|
2025-03-07 00:55:50 +08:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-07 14:30:31 +08:00
|
|
|
if len(categoryCodeArr) > 0 && categoryCodeArr[0] != "" {
|
|
|
|
|
categories, err = i.categoryRepo.GetIDByCode(categoryCodeArr)
|
2025-03-07 00:55:50 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return news, err
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-07 14:30:31 +08:00
|
|
|
if len(categories) < 1 {
|
2025-03-07 00:55:50 +08:00
|
|
|
return news, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-20 13:13:28 +08:00
|
|
|
filterSpec := newsdomain.NewsFilter{
|
2025-03-07 00:55:50 +08:00
|
|
|
Tags: tags,
|
2025-03-07 14:30:31 +08:00
|
|
|
Category: categories,
|
2025-03-20 13:13:28 +08:00
|
|
|
Active: filter.Active,
|
2025-03-24 18:11:08 +08:00
|
|
|
Search: filter.Search,
|
2025-03-07 00:55:50 +08:00
|
|
|
}
|
2025-03-20 13:13:28 +08:00
|
|
|
return i.newsRepo.GetAll(filterSpec)
|
2025-03-02 04:36:17 +08:00
|
|
|
}
|