🎨 分类新增文章分类字段,优化查询接口
This commit is contained in:
@@ -196,3 +196,14 @@ func (catApi *CategoryApi) GetCategoryListPublic(context *gin.Context) {
|
|||||||
}
|
}
|
||||||
response.OkWithData(list, context)
|
response.OkWithData(list, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetArticleCategoryList 获取文章类别列表
|
||||||
|
func (catApi *CategoryApi) GetArticleCategoryList(context *gin.Context) {
|
||||||
|
list, err := catService.GetArticleCategoryList()
|
||||||
|
if err != nil {
|
||||||
|
global.GVA_LOG.Error("获取文章类别列表失败!", zap.Error(err))
|
||||||
|
response.FailWithMessage("获取文章类别列表失败:"+err.Error(), context)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.OkWithData(list, context)
|
||||||
|
}
|
||||||
|
@@ -15,6 +15,8 @@ type Category struct {
|
|||||||
Icon *string `json:"icon" form:"icon" gorm:"column:icon;comment:类别图标;"` //图标
|
Icon *string `json:"icon" form:"icon" gorm:"column:icon;comment:类别图标;"` //图标
|
||||||
IndexTrue *bool `json:"index" form:"index" gorm:"column:index;comment:是否首页显示;"` //是否首页显示
|
IndexTrue *bool `json:"index" form:"index" gorm:"column:index;comment:是否首页显示;"` //是否首页显示
|
||||||
Url *string `json:"url" form:"url" gorm:"column:url;comment:类别链接;"` //链接
|
Url *string `json:"url" form:"url" gorm:"column:url;comment:类别链接;"` //链接
|
||||||
|
// 是否文章分类
|
||||||
|
IsArticle *int `json:"isArticle" form:"isArticle" gorm:"column:is_article;default:0;comment:是否文章分类;"` //是否文章分类
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName 类别 Category自定义表名 categories
|
// TableName 类别 Category自定义表名 categories
|
||||||
|
@@ -23,7 +23,8 @@ func (s *CategoryRouter) InitCategoryRouter(Router *gin.RouterGroup, PublicRoute
|
|||||||
catRouterWithoutRecord.GET("getCategoryList", catApi.GetCategoryList) // 获取类别列表
|
catRouterWithoutRecord.GET("getCategoryList", catApi.GetCategoryList) // 获取类别列表
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
catRouterWithoutAuth.GET("getCategoryPublic", catApi.GetCategoryPublic) // 类别开放接口
|
catRouterWithoutAuth.GET("getCategoryPublic", catApi.GetCategoryPublic) // 类别开放接口
|
||||||
catRouterWithoutAuth.GET("/index", catApi.GetCategoryListPublic) // 获取类别列表公开接口
|
catRouterWithoutAuth.GET("/index", catApi.GetCategoryListPublic) // 获取类别列表公开接口
|
||||||
|
catRouterWithoutAuth.GET("/article/list", catApi.GetArticleCategoryList) // 获取类别列表公开接口
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -86,10 +86,20 @@ func (catService *CategoryService) GetCategoryPublic(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (catService *CategoryService) GetIndexCategoryList() (list []category.Category, err error) {
|
func (catService *CategoryService) GetIndexCategoryList() (list []category.Category, err error) {
|
||||||
err = global.GVA_DB.Model(&category.Category{}).Where("categories.index = 1").Find(&list).Error
|
err = global.GVA_DB.Model(&category.Category{}).Where("categories.index = 1 and categories.is_article=0").Find(&list).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
global.GVA_LOG.Error("获取首页分类失败", zap.Error(err))
|
global.GVA_LOG.Error("获取首页分类失败", zap.Error(err))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetArticleCategoryList 获取文章分类
|
||||||
|
func (catService *CategoryService) GetArticleCategoryList() (list []category.Category, err error) {
|
||||||
|
err = global.GVA_DB.Model(&category.Category{}).Where("categories.is_article = 1").Find(&list).Error
|
||||||
|
if err != nil {
|
||||||
|
global.GVA_LOG.Error("获取文章分类失败", zap.Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user