fix: categories filter is multiple now
This commit is contained in:
@@ -4,16 +4,16 @@ import (
|
||||
categorydomain "legalgo-BE-go/internal/domain/category"
|
||||
)
|
||||
|
||||
func (a *accessor) GetIDByCode(code string) (string, error) {
|
||||
var category string
|
||||
func (a *accessor) GetIDByCode(codes []string) ([]string, error) {
|
||||
var categories []string
|
||||
|
||||
if err := a.db.
|
||||
Model(&categorydomain.Category{}).
|
||||
Select("id").Where("code = ?", code).
|
||||
Pluck("id", &category).
|
||||
Select("id").Where("code IN ?", codes).
|
||||
Pluck("id", &categories).
|
||||
Error; err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return category, nil
|
||||
return categories, nil
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ type accessor struct {
|
||||
type Category interface {
|
||||
GetAllModel() ([]categorydomain.Category, error)
|
||||
GetByIDs([]string) ([]categorydomain.Category, error)
|
||||
GetIDByCode(string) (string, error)
|
||||
GetIDByCode([]string) ([]string, error)
|
||||
CreateModel(categorydomain.CategoryReq) error
|
||||
Update(categorydomain.Category) error
|
||||
Delete(string) error
|
||||
|
||||
@@ -9,9 +9,9 @@ func (a *accessor) GetAll(filter newsdomain.NewsFilter) ([]newsdomain.News, erro
|
||||
Preload("Categories").
|
||||
Preload("Author")
|
||||
|
||||
if filter.Category != "" {
|
||||
if len(filter.Category) > 0 {
|
||||
query = query.Joins("JOIN news_categories nc ON nc.news_id = news.id").
|
||||
Where("nc.category_id = ?", filter.Category)
|
||||
Where("nc.category_id IN (?)", filter.Category)
|
||||
}
|
||||
|
||||
if len(filter.Tags) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user