fix: categories filter is multiple now

This commit is contained in:
ericprd
2025-03-07 14:30:31 +08:00
parent 51b50a3132
commit c410e651ce
6 changed files with 19 additions and 20 deletions
+6 -6
View File
@@ -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
}
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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 {