update: category

This commit is contained in:
Kerwin
2025-07-16 10:54:00 +08:00
parent 22d264d0a4
commit e915f1637b
14 changed files with 268 additions and 37 deletions

View File

@@ -11,7 +11,9 @@ type CategoryRepository interface {
BaseRepository[entity.Category]
FindByName(name string) (*entity.Category, error)
FindWithResources() ([]entity.Category, error)
FindWithTags() ([]entity.Category, error)
GetResourceCount(categoryID uint) (int64, error)
GetTagCount(categoryID uint) (int64, error)
FindWithPagination(page, pageSize int) ([]entity.Category, int64, error)
Search(query string, page, pageSize int) ([]entity.Category, int64, error)
}
@@ -45,6 +47,13 @@ func (r *CategoryRepositoryImpl) FindWithResources() ([]entity.Category, error)
return categories, err
}
// FindWithTags 查找包含标签的分类
func (r *CategoryRepositoryImpl) FindWithTags() ([]entity.Category, error) {
var categories []entity.Category
err := r.db.Preload("Tags").Find(&categories).Error
return categories, err
}
// GetResourceCount 获取分类下的资源数量
func (r *CategoryRepositoryImpl) GetResourceCount(categoryID uint) (int64, error) {
var count int64
@@ -52,6 +61,13 @@ func (r *CategoryRepositoryImpl) GetResourceCount(categoryID uint) (int64, error
return count, err
}
// GetTagCount 获取分类下的标签数量
func (r *CategoryRepositoryImpl) GetTagCount(categoryID uint) (int64, error) {
var count int64
err := r.db.Model(&entity.Tag{}).Where("category_id = ?", categoryID).Count(&count).Error
return count, err
}
// FindWithPagination 分页查询分类
func (r *CategoryRepositoryImpl) FindWithPagination(page, pageSize int) ([]entity.Category, int64, error) {
var categories []entity.Category