service/app/mix/controller/feedback_op.go

83 lines
2.1 KiB
Go
Raw Normal View History

2023-12-21 22:17:40 +08:00
package controller
import (
"service/api/consts"
"service/api/errcode"
feedbackproto "service/api/proto/feedback/proto"
"service/app/mix/service"
"service/bizcommon/util"
"service/library/logger"
2023-12-29 22:22:25 +08:00
"service/library/mediafiller"
2023-12-21 22:17:40 +08:00
"github.com/gin-gonic/gin"
)
func OpCreateFeedback(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*feedbackproto.OpCreateReq)
ec := service.DefaultService.OpCreateFeedback(ctx, req)
if ec != errcode.ErrCodeFeedbackSrvOk {
logger.Error("OpCreateFeedback fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrorMsg(ctx, "server error")
return
}
ReplyOk(ctx, nil)
}
func OpUpdateFeedback(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*feedbackproto.OpUpdateReq)
ec := service.DefaultService.OpUpdateFeedback(ctx, req)
if ec != errcode.ErrCodeFeedbackSrvOk {
logger.Error("OpUpdateFeedback fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func OpDeleteFeedback(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*feedbackproto.OpDeleteReq)
ec := service.DefaultService.OpDeleteFeedback(ctx, req.Id)
if ec != errcode.ErrCodeFeedbackSrvOk {
logger.Error("OpDeleteFeedback fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func OpGetFeedbackList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*feedbackproto.OpListReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.OpGetFeedbackList(ctx, req)
if ec != errcode.ErrCodeFeedbackSrvOk {
logger.Error("OpGetFeedbackList fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
2023-12-29 22:22:25 +08:00
//填充媒体切片
objectMediaNum := 1 // 单个反馈总共1个媒体类
mediaFillableList := make([]mediafiller.MediaFillable, len(list)*objectMediaNum)
for i, feedback := range list {
mediaFillableList[objectMediaNum*i+0] = feedback.Credentials
}
mediafiller.FillList(ctx, mediaFillableList)
2023-12-21 22:17:40 +08:00
data := &feedbackproto.OpListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}