109 lines
3.5 KiB
Go
109 lines
3.5 KiB
Go
// ==========================================================================
|
||
// GFast自动生成controller操作代码。
|
||
// 生成日期:2024-04-23 14:47:24
|
||
// 生成路径: internal/app/system/controller/comments.go
|
||
// 生成人:gfast
|
||
// desc:App通知公告评论
|
||
// company:云南奇讯科技有限公司
|
||
// ==========================================================================
|
||
|
||
package controller
|
||
|
||
import (
|
||
"context"
|
||
|
||
"github.com/gogf/gf/v2/frame/g"
|
||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
|
||
ct "github.com/tiger1103/gfast/v3/internal/app/system/logic/context"
|
||
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
|
||
"github.com/tiger1103/gfast/v3/internal/app/system/service"
|
||
"github.com/tiger1103/gfast/v3/library/liberr"
|
||
)
|
||
|
||
type commentsController struct {
|
||
BaseController
|
||
}
|
||
|
||
var Comments = new(commentsController)
|
||
|
||
// List 列表
|
||
func (c *commentsController) List(ctx context.Context, req *system.CommentsSearchReq) (res *system.CommentsSearchRes, err error) {
|
||
res, err = service.Comments().List(ctx, req)
|
||
return
|
||
}
|
||
|
||
// Get 获取App通知公告评论
|
||
func (c *commentsController) Get(ctx context.Context, req *system.CommentsGetReq) (res *system.CommentsGetRes, err error) {
|
||
res = new(system.CommentsGetRes)
|
||
res.CommentsInfoRes, err = service.Comments().GetById(ctx, req.Id)
|
||
return
|
||
}
|
||
|
||
// Add 添加App通知公告评论
|
||
func (c *commentsController) Add(ctx context.Context, req *system.CommentsAddReq) (res *system.CommentsAddRes, err error) {
|
||
err = service.Comments().Add(ctx, req)
|
||
return
|
||
}
|
||
|
||
// Edit 修改App通知公告评论
|
||
func (c *commentsController) Edit(ctx context.Context, req *system.CommentsEditReq) (res *system.CommentsEditRes, err error) {
|
||
err = service.Comments().Edit(ctx, req)
|
||
return
|
||
}
|
||
|
||
// Delete 删除App通知公告评论
|
||
func (c *commentsController) Delete(ctx context.Context, req *system.CommentsDeleteReq) (res *system.CommentsDeleteRes, err error) {
|
||
err = service.Comments().Delete(ctx, req.Ids)
|
||
return
|
||
}
|
||
|
||
// Publish 通知公告发布一条评论
|
||
func (c *commentsController) Publish(ctx context.Context, req *system.CommentsPublishReq) (*system.CommentsPublishRes, error) {
|
||
// 获取用户的主键ID
|
||
userID := ct.New().GetUserId(ctx)
|
||
|
||
err := g.Try(ctx, func(ctx context.Context) {
|
||
_, err := dao.Comments.Ctx(ctx).Insert(do.Comments{
|
||
NotificationId: req.NotificationId, // 关联的通知ID
|
||
CommentText: req.CommentText, // 评论内容
|
||
CommentId: userID, // 用户ID
|
||
})
|
||
liberr.ErrIsNil(ctx, err, "添加评论失败")
|
||
})
|
||
liberr.ErrIsNil(ctx, err)
|
||
return &system.CommentsPublishRes{}, nil
|
||
}
|
||
|
||
// 获取指定一个通知公告的评论列表
|
||
func (c *commentsController) GetListByNotificationId(ctx context.Context, req *system.CommentsGetListByNotificationIdReq) (res *system.CommentsGetListByNotificationIdRes, err error) {
|
||
res = new(system.CommentsGetListByNotificationIdRes)
|
||
|
||
err = g.Try(ctx, func(ctx context.Context) {
|
||
m := dao.Comments.Ctx(ctx).WithAll()
|
||
|
||
// 获取总页数
|
||
res.Total, err = m.Count()
|
||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||
|
||
res.CurrentPage = req.PageNum
|
||
|
||
if req.PageNum == 0 {
|
||
req.PageNum = 1
|
||
}
|
||
|
||
if req.PageSize == 0 {
|
||
req.PageSize = 30
|
||
}
|
||
|
||
m = m.As("cs").LeftJoin("sys_user as su", "su.id = cs.comment_id").
|
||
Where("cs.notification_id", req.NotificationId)
|
||
|
||
err = m.Page(req.PageNum, req.PageSize).Order("id asc").
|
||
Fields(`cs.id,notification_id,comment_text,comment_id,cs.created_at,su.user_nickname`).Scan(&res.List)
|
||
liberr.ErrIsNil(ctx, err, "获取数据失败")
|
||
})
|
||
|
||
return
|
||
}
|