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" "service/library/mediafiller" "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 } //填充媒体切片 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) data := &feedbackproto.OpListData{ List: list, Offset: req.Offset + len(list), } if len(list) >= req.Limit { data.More = 1 } ReplyOk(ctx, data) }