初始
This commit is contained in:
38
api/app/visual_remark/req.go
Normal file
38
api/app/visual_remark/req.go
Normal file
@ -0,0 +1,38 @@
|
||||
package visual_remark
|
||||
|
||||
import "github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
// 新增形象进度评论
|
||||
type CreateRemarkReq struct {
|
||||
g.Meta `path:"/remark/create" method:"post" tags:"APP(形象进度评论相关)" summary:"新增形象进度评论"`
|
||||
VisualProgressID int `json:"visualProgressId" v:"required" dc:"形象进度ID"`
|
||||
Comment string `json:"comment" v:"required" dc:"评论的内容"`
|
||||
UserID int `json:"userId" v:"required" dc:"评论的用户ID"`
|
||||
}
|
||||
|
||||
// 查看某个形象进度的评论列表
|
||||
type ListRemarksReq struct {
|
||||
g.Meta `path:"/remark/list" method:"get" tags:"APP(形象进度评论相关)" summary:"查看某个形象进度的评论列表"`
|
||||
VisualID int64 `json:"visualID" v:"required" dc:"形象进度ID"`
|
||||
}
|
||||
|
||||
// 获取形象进度评论详细信息
|
||||
type GetRemarkDetailReq struct {
|
||||
g.Meta `path:"/remark/detail" method:"get" tags:"APP(形象进度评论相关)" summary:"获取形象进度评论详细信息"`
|
||||
ID int64 `json:"id" v:"required" dc:"备注ID"`
|
||||
}
|
||||
|
||||
// 更新形象进度评论
|
||||
type UpdateRemarkReq struct {
|
||||
g.Meta `path:"/remark/update" method:"post" tags:"APP(形象进度评论相关)" summary:"更新形象进度评论"`
|
||||
ID int `json:"id" v:"required" dc:"主键ID"`
|
||||
VisualProgressID int `json:"visualProgressId" dc:"形象进度ID"`
|
||||
Comment string `json:"comment" dc:"评论的内容"`
|
||||
UserID int `json:"userId" dc:"评论的用户ID"`
|
||||
}
|
||||
|
||||
// 删除形象进度评论
|
||||
type DeleteRemarkReq struct {
|
||||
g.Meta `path:"/remark/delete" method:"delete" tags:"APP(形象进度评论相关)" summary:"删除形象进度评论"`
|
||||
ID int `json:"id" v:"required" dc:"主键ID"`
|
||||
}
|
31
api/app/visual_remark/res.go
Normal file
31
api/app/visual_remark/res.go
Normal file
@ -0,0 +1,31 @@
|
||||
package visual_remark
|
||||
|
||||
// 查看某个形象进度的评论列表
|
||||
type ListRemarksRes struct {
|
||||
VisualProgressRemarks []VisualProgressRemark `json:"visualProgressRemarks"`
|
||||
}
|
||||
|
||||
type VisualProgressRemark struct {
|
||||
ID int `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Avatar string `json:"avatar"`
|
||||
VisualProgressID int `json:"visualProgressId"`
|
||||
VisualProgressTitle string `json:"visualProgressTitle"`
|
||||
Comment string `json:"comment"`
|
||||
UserID int `json:"userId"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
}
|
||||
|
||||
// 查看形象进度评论详细信息
|
||||
type GetRemarkDetailRes struct {
|
||||
VisualProgressRemark
|
||||
}
|
||||
|
||||
// 新增形象进度评论
|
||||
type CreateRemarkRes struct{}
|
||||
|
||||
// 更新形象进度评论
|
||||
type UpdateRemarkRes struct{}
|
||||
|
||||
// 删除形象进度评论
|
||||
type DeleteRemarkRes struct{}
|
115
api/app/visual_remark/service.go
Normal file
115
api/app/visual_remark/service.go
Normal file
@ -0,0 +1,115 @@
|
||||
package visual_remark
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
ct "github.com/tiger1103/gfast/v3/internal/app/system/logic/context"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/service"
|
||||
)
|
||||
|
||||
// 列表请求
|
||||
func (v VisualRemark) ListRemarks(ctx context.Context, req *ListRemarksReq) (res *ListRemarksRes, err error) {
|
||||
|
||||
res = &ListRemarksRes{}
|
||||
err = g.Model("visual_progress_remark AS remark").Ctx(ctx).
|
||||
Fields("remark.*,visual.title AS visualProgressTitle, user.user_nickname AS Username, cuser.head_icon AS Avatar").
|
||||
// 连表查询形象进度表得到形象进度标题
|
||||
LeftJoin("visual_progress AS visual", "visual.id = remark.visual_progress_id").
|
||||
// 连表查询评论人的名字(暂未确定是哪张用户表,需要联查)
|
||||
LeftJoin("sys_user AS user on user.id = remark.user_id").
|
||||
// 头像需要从另外一张表查询出来
|
||||
LeftJoin("bus_construction_user AS cuser on cuser.phone = user.mobile").
|
||||
Where("visual.id = ? AND cuser.deleted_at is null", req.VisualID).
|
||||
Scan(&res.VisualProgressRemarks)
|
||||
|
||||
g.Dump(res.VisualProgressRemarks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 获取详情
|
||||
func (v VisualRemark) GetRemarkDetail(ctx context.Context, req *GetRemarkDetailReq) (res *GetRemarkDetailRes, err error) {
|
||||
res = &GetRemarkDetailRes{}
|
||||
err = g.Model("visual_progress_remark AS remark").Ctx(ctx).
|
||||
Fields("remark.*,visual.title AS visualProgressTitle, user.user_nickname AS Username, user.avatar AS Avatar").
|
||||
// 连表查询形象进度表得到形象进度标题
|
||||
LeftJoin("visual_progress AS visual on visual.id = remark.visual_progress_id").
|
||||
// 连表查询评论人的名字
|
||||
LeftJoin("sys_user AS user on user.id = remark.user_id").
|
||||
Where("remark.id = ? AND cuser.deleted_at is null", req.ID).
|
||||
Scan(&res.VisualProgressRemark)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 新增形象进度
|
||||
func (v VisualRemark) CreateRemark(ctx context.Context, req *CreateRemarkReq) (res *CreateRemarkRes, err error) {
|
||||
res = &CreateRemarkRes{}
|
||||
_, err = g.Model("visual_progress_remark").Ctx(ctx).Data(g.Map{
|
||||
"visual_progress_id": req.VisualProgressID,
|
||||
"comment": req.Comment,
|
||||
"user_id": req.UserID,
|
||||
}).Insert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var VisualProgressVo struct {
|
||||
ProjectId int `json:"projectId"`
|
||||
ReporterId int `json:"reporterId"`
|
||||
}
|
||||
// 根据形象进度ID查询项目ID、发布者ID
|
||||
g.Model("visual_progress").Fields("project_id AS ProjectId", "reporter_id AS ReporterId").
|
||||
Where("id", req.VisualProgressID).Scan(&VisualProgressVo)
|
||||
|
||||
// 新增之后通知对应的发起人
|
||||
param := &system.CommentListAddReq{
|
||||
ProjectId: VisualProgressVo.ProjectId,
|
||||
Receiver: VisualProgressVo.ReporterId,
|
||||
Content: req.Comment,
|
||||
Sender: req.UserID,
|
||||
}
|
||||
service.CommentList().Add(ctx, param)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 更新形象备注
|
||||
func (v VisualRemark) UpdateRemark(ctx context.Context, req *UpdateRemarkReq) (res *UpdateRemarkRes, err error) {
|
||||
res = &UpdateRemarkRes{}
|
||||
_, err = g.Model("visual_progress_remark").Ctx(ctx).Data(g.Map{
|
||||
"visual_progress_id": req.VisualProgressID,
|
||||
"comment": req.Comment,
|
||||
"user_id": req.UserID,
|
||||
}).Where("id", req.ID).Update()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// 删除形象备注
|
||||
func (v VisualRemark) DeleteRemark(ctx context.Context, req *DeleteRemarkReq) (res *DeleteRemarkRes, err error) {
|
||||
userID := ct.New().GetUserId(ctx)
|
||||
var VisualProgressRemarkVo struct {
|
||||
ID int `json:"id"`
|
||||
UserID uint64 `json:"userId"`
|
||||
}
|
||||
g.Model("visual_progress_remark").Ctx(ctx).Where("id", req.ID).Scan(&VisualProgressRemarkVo)
|
||||
// 当前用户等于评论的发起人才可以删除自己的评论
|
||||
if userID == VisualProgressRemarkVo.UserID {
|
||||
res = &DeleteRemarkRes{}
|
||||
_, err = g.Model("visual_progress_remark").Ctx(ctx).Where("id", req.ID).Delete()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
return nil, errors.New("只能删除自己的评论信息")
|
||||
}
|
||||
return
|
||||
}
|
4
api/app/visual_remark/visual_remark.go
Normal file
4
api/app/visual_remark/visual_remark.go
Normal file
@ -0,0 +1,4 @@
|
||||
package visual_remark
|
||||
|
||||
type VisualRemark struct {
|
||||
}
|
Reference in New Issue
Block a user