fix: get news by query category and tags filters
This commit is contained in:
@@ -1,7 +1,46 @@
|
||||
package newssvc
|
||||
|
||||
import newsdomain "legalgo-BE-go/internal/domain/news"
|
||||
import (
|
||||
newsdomain "legalgo-BE-go/internal/domain/news"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (i *impl) GetAll() ([]newsdomain.News, error) {
|
||||
return i.newsRepo.GetAll()
|
||||
func (i *impl) GetAll(categoryCode, tagCodes string) ([]newsdomain.News, error) {
|
||||
var (
|
||||
category string
|
||||
err error
|
||||
)
|
||||
|
||||
tags := []string{}
|
||||
news := []newsdomain.News{}
|
||||
|
||||
tagCodeArr := strings.Split(tagCodes, " ")
|
||||
|
||||
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 categoryCode != "" {
|
||||
category, err = i.categoryRepo.GetIDByCode(categoryCode)
|
||||
if err != nil {
|
||||
return news, err
|
||||
}
|
||||
|
||||
if category == "" {
|
||||
return news, nil
|
||||
}
|
||||
}
|
||||
|
||||
filter := newsdomain.NewsFilter{
|
||||
Tags: tags,
|
||||
Category: category,
|
||||
}
|
||||
return i.newsRepo.GetAll(filter)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ type impl struct {
|
||||
}
|
||||
|
||||
type News interface {
|
||||
GetAll() ([]newsdomain.News, error)
|
||||
GetAll(string, string) ([]newsdomain.News, error)
|
||||
GetBySlug(string) (*newsdomain.News, error)
|
||||
Create(newsdomain.NewsReq, string) error
|
||||
Update(string, newsdomain.NewsUpdate) error
|
||||
|
||||
Reference in New Issue
Block a user