新增了操作图文视频状态

This commit is contained in:
wucongxing8150 2024-09-09 15:45:40 +08:00
parent 61d27b2f02
commit 567e926ba3
5 changed files with 141 additions and 76 deletions

View File

@ -357,75 +357,63 @@ func (r *Article) AddArticle(c *gin.Context) {
}
// PutArticleStatus 操作图文状态
func (b *Article) PutArticleStatus(c *gin.Context) {
//orderSingleRequest := requests.OrderSingleRequest{}
//req := orderSingleRequest.PutOrderSingleDeleteStatus
//if err := c.ShouldBind(&req); err != nil {
// responses.FailWithMessage(err.Error(), c)
// return
//}
//
//// 参数验证
//if err := global.Validate.Struct(req); err != nil {
// responses.FailWithMessage(utils.Translate(err), c)
// return
//}
//
//if req.IsDelete != 0 && req.IsDelete != 1 {
// responses.FailWithMessage("参数错误", c)
// return
//}
//
//id := c.Param("order_id")
//if id == "" {
// responses.FailWithMessage("缺少参数", c)
// return
//}
//
//// 将 id 转换为 int64 类型
//orderId, err := strconv.ParseInt(id, 10, 64)
//if err != nil {
// responses.Fail(c)
// return
//}
//
//// 获取订单数据
//orderSingleDao := dao.OrderSingleDao{}
//orderSingle, err := orderSingleDao.GetOrderSingleById(orderId)
//if err != nil {
// responses.FailWithMessage("订单异常", c)
// return
//}
//
//// 检测订单状态
//if orderSingle.OrderStatus == 2 {
// responses.FailWithMessage("订单不允许删除", c)
// return
//}
//
//// 检测订单删除状态
//if orderSingle.IsDelete == req.IsDelete {
// responses.Ok(c)
// return
//}
//
//// 开始事务
//tx := global.Db.Begin()
//defer func() {
// if r := recover(); r != nil {
// tx.Rollback()
// }
//}()
//
//orderSingleData := make(map[string]interface{})
//orderSingleData["is_delete"] = 1
//err = orderSingleDao.EditOrderSingleById(tx, orderId, orderSingleData)
//if err != nil {
// tx.Rollback()
// responses.FailWithMessage("删除失败", c)
// return
//}
//
//tx.Commit()
func (r *Article) PutArticleStatus(c *gin.Context) {
articleRequest := requests.ArticleRequest{}
req := articleRequest.PutArticleStatus
if err := c.ShouldBind(&req); err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 参数验证
if err := global.Validate.Struct(req); err != nil {
responses.FailWithMessage(utils.Translate(err), c)
return
}
id := c.Param("article_id")
if id == "" {
responses.FailWithMessage("缺少参数", c)
return
}
// 将 id 转换为 int64 类型
articleId, err := strconv.ParseInt(id, 10, 64)
if err != nil {
responses.Fail(c)
return
}
// 获取订单数据
articleDao := dao.ArticleDao{}
article, err := articleDao.GetArticleById(articleId)
if err != nil {
responses.FailWithMessage("图文异常", c)
return
}
// 开始事务
tx := global.Db.Begin()
defer func() {
if r := recover(); r != nil {
tx.Rollback()
}
}()
articleData := make(map[string]interface{})
if req.ArticleStatus != article.ArticleStatus {
articleData["article_status"] = req.ArticleStatus
}
if len(articleData) > 0 {
err = articleDao.EditArticleById(tx, articleId, articleData)
if err != nil {
tx.Rollback()
responses.FailWithMessage("修改失败", c)
return
}
}
tx.Commit()
responses.Ok(c)
}

View File

@ -360,3 +360,65 @@ func (r *Video) AddVideo(c *gin.Context) {
tx.Commit()
responses.Ok(c)
}
// PutVideoStatus 操作视频状态
func (r *Video) PutVideoStatus(c *gin.Context) {
videoRequest := requests.VideoRequest{}
req := videoRequest.PutVideoStatus
if err := c.ShouldBind(&req); err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 参数验证
if err := global.Validate.Struct(req); err != nil {
responses.FailWithMessage(utils.Translate(err), c)
return
}
id := c.Param("video_id")
if id == "" {
responses.FailWithMessage("缺少参数", c)
return
}
// 将 id 转换为 int64 类型
videoId, err := strconv.ParseInt(id, 10, 64)
if err != nil {
responses.Fail(c)
return
}
// 获取订单数据
videoDao := dao.VideoDao{}
video, err := videoDao.GetVideoById(videoId)
if err != nil {
responses.FailWithMessage("视频异常", c)
return
}
// 开始事务
tx := global.Db.Begin()
defer func() {
if r := recover(); r != nil {
tx.Rollback()
}
}()
videoData := make(map[string]interface{})
if req.VideoStatus != video.VideoStatus {
videoData["video_status"] = req.VideoStatus
}
if len(videoData) > 0 {
err = videoDao.EditVideoById(tx, videoId, videoData)
if err != nil {
tx.Rollback()
responses.FailWithMessage("修改失败", c)
return
}
}
tx.Commit()
responses.Ok(c)
}

View File

@ -4,6 +4,7 @@ type ArticleRequest struct {
GetArticlePage // 获取图文列表-分页
PutArticle // 修改图文详情
AddArticle // 新增图文详情
PutArticleStatus // 操作图文状态
}
// GetArticlePage 获取图文列表-分页
@ -49,3 +50,8 @@ type AddArticleAuthor struct {
AuthorName string `json:"author_name" form:"author_name" label:"作者姓名" validate:"required"`
HospitalId string `json:"hospital_id" form:"hospital_id" label:"作者所属医院id" validate:"required"`
}
// PutArticleStatus 操作图文状态
type PutArticleStatus struct {
ArticleStatus int `json:"article_status" form:"article_status" label:"文章状态" validate:"required,oneof=1 2"` // 1:正常 2:禁用)
}

View File

@ -4,6 +4,7 @@ type VideoRequest struct {
GetVideoPage // 获取视频列表-分页
PutVideo // 修改视频详情
AddVideo // 新增视频详情
PutVideoStatus // 操作视频状态
}
// GetVideoPage 获取视频列表-分页
@ -52,3 +53,8 @@ type AddVideoAuthor struct {
AuthorName string `json:"author_name" form:"author_name" label:"作者姓名" validate:"required"`
HospitalId string `json:"hospital_id" form:"hospital_id" label:"作者所属医院id" validate:"required"`
}
// PutVideoStatus 操作视频状态
type PutVideoStatus struct {
VideoStatus int `json:"video_status" form:"video_status" label:"状态" validate:"required,oneof=1 2"` // 1:正常 2:禁用)
}

View File

@ -142,6 +142,9 @@ func privateRouter(r *gin.Engine, api controller.Api) {
// 新增视频详情
videoGroup.POST("", api.Video.AddVideo)
// 操作视频状态
articleGroup.PUT("/status/:video_id", api.Video.PutVideoStatus)
// 投票记录列表-视频-分页
videoGroup.GET("/vote/page", api.UserVoteDay.GetVideoVotePage)
}