🎨 用户端新增文章更新和删除接口
This commit is contained in:
@@ -190,3 +190,19 @@ func (ArticleApi) GetBuyList(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
r.OkWithDetailed(gin.H{"list": list, "total": total}, "查询成功", ctx)
|
r.OkWithDetailed(gin.H{"list": list, "total": total}, "查询成功", ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AppDelete 删除文章
|
||||||
|
func (ArticleApi) AppDelete(ctx *gin.Context) {
|
||||||
|
id := ctx.Param("id")
|
||||||
|
if id == "" {
|
||||||
|
r.FailWithMessage("参数错误", ctx)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := articleService.AppDelete(id)
|
||||||
|
if err != nil {
|
||||||
|
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||||
|
r.FailWithMessage("删除失败:"+err.Error(), ctx)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
r.OkWithMessage("删除成功", ctx)
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type Article struct {
|
|||||||
IsFree int `json:"isFree" gorm:"comment:是否免费;default:0"` // 是否免费 0-否 1-是
|
IsFree int `json:"isFree" gorm:"comment:是否免费;default:0"` // 是否免费 0-否 1-是
|
||||||
// 分类ID
|
// 分类ID
|
||||||
CategoryId int `json:"categoryId" gorm:"comment:分类ID"`
|
CategoryId int `json:"categoryId" gorm:"comment:分类ID"`
|
||||||
Status int `json:"status" gorm:"comment:状态;default:1"` // 状态 0-草稿 1-已发布 2-待审核 3-审核不通过
|
Status int `json:"status" gorm:"comment:状态 1-已发布 2-待审核 3-审核不通过;default:2"` // 状态 0-草稿 1-已发布 2-待审核 3-审核不通过
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName 文章表
|
// TableName 文章表
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package vo
|
package vo
|
||||||
|
|
||||||
|
import "git.echol.cn/loser/lckt/model/app/vo"
|
||||||
|
|
||||||
type ArticleListVo struct {
|
type ArticleListVo struct {
|
||||||
ID int `json:"id" gorm:"comment:文章ID"`
|
ID int `json:"id" gorm:"comment:文章ID"`
|
||||||
Title string `json:"title" gorm:"comment:文章标题"`
|
Title string `json:"title" gorm:"comment:文章标题"`
|
||||||
@@ -26,3 +28,8 @@ type ArticleVo struct {
|
|||||||
IsFree int `json:"isFree" gorm:"comment:是否免费;default:0"` // 是否免费 0-否 1-是
|
IsFree int `json:"isFree" gorm:"comment:是否免费;default:0"` // 是否免费 0-否 1-是
|
||||||
IsBuy int `json:"isBuy" gorm:"comment:是否购买;default:0"` // 是否购买 0-否 1-是
|
IsBuy int `json:"isBuy" gorm:"comment:是否购买;default:0"` // 是否购买 0-否 1-是
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ArticleTeacherVo struct {
|
||||||
|
TeacherInfo vo.TeacherInfo
|
||||||
|
ArticleList []ArticleListVo `json:"articleList" gorm:"comment:文章列表"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,8 +30,10 @@ func (s *ArticleRouter) InitBotRouter(Router *gin.RouterGroup, PublicRouter *gin
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
// App端文章相关接口
|
// App端文章相关接口
|
||||||
appRouter.POST("publish", artApi.AppPush) // 获取文章列表
|
appRouter.POST("publish", artApi.AppPush) // 获取文章列表
|
||||||
appRouter.GET("my", artApi.GetMyArticleList) // 获取我的文章列表
|
appRouter.PUT("publish", artApi.AppPush)
|
||||||
appRouter.GET("buyList", artApi.GetBuyList) // 获取购买的文章列表
|
appRouter.DELETE("delete/:id", artApi.AppDelete) // 批量删除文章
|
||||||
|
appRouter.GET("my", artApi.GetMyArticleList) // 获取我的文章列表
|
||||||
|
appRouter.GET("buyList", artApi.GetBuyList) // 获取购买的文章列表
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func (s ArticleService) APPGetArticleList(pageInfo request.GetList) (list []vo.A
|
|||||||
limit := pageInfo.PageSize
|
limit := pageInfo.PageSize
|
||||||
offset := pageInfo.PageSize * (pageInfo.Page - 1)
|
offset := pageInfo.PageSize * (pageInfo.Page - 1)
|
||||||
|
|
||||||
db := global.GVA_DB.Model(&article.Article{})
|
db := global.GVA_DB.Model(&article.Article{}).Where("status = 1") // 只查询已发布的文章
|
||||||
err = db.Count(&total).Error
|
err = db.Count(&total).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -108,7 +108,12 @@ func (s ArticleService) APPGetArticle(id string, userId int) (article *vo.Articl
|
|||||||
|
|
||||||
// AppPush app端推送文章
|
// AppPush app端推送文章
|
||||||
func (s ArticleService) AppPush(req article.Article) (err error) {
|
func (s ArticleService) AppPush(req article.Article) (err error) {
|
||||||
err = global.GVA_DB.Create(&req).Error
|
req.Status = 2 // 默认状态为待审核
|
||||||
|
if req.ID != 0 {
|
||||||
|
err = global.GVA_DB.Model(&article.Article{}).Where("id = ?", req.ID).Updates(&req).Error
|
||||||
|
} else {
|
||||||
|
err = global.GVA_DB.Create(&req).Error
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
global.GVA_LOG.Error("推送文章失败", zap.Error(err))
|
global.GVA_LOG.Error("推送文章失败", zap.Error(err))
|
||||||
return err
|
return err
|
||||||
@@ -174,3 +179,12 @@ func (s ArticleService) GetBuyList(p request.GetList) (articles []article.Articl
|
|||||||
}
|
}
|
||||||
return articles, total, nil
|
return articles, total, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s ArticleService) AppDelete(id string) error {
|
||||||
|
err := global.GVA_DB.Delete(&article.Article{}, "id = ?", id).Error
|
||||||
|
if err != nil {
|
||||||
|
global.GVA_LOG.Error("删除文章失败", zap.Error(err))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user