service/app/mix/controller/callhistory_op.go

118 lines
3.3 KiB
Go
Raw Permalink Normal View History

2023-12-21 22:17:40 +08:00
package controller
import (
"service/api/consts"
"service/api/errcode"
callhistoryproto "service/api/proto/callhistory/proto"
"service/app/mix/service"
"service/bizcommon/util"
"service/library/logger"
"service/library/mediafiller"
"github.com/gin-gonic/gin"
)
func OpCreateCallHistory(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*callhistoryproto.OpCreateReq)
ec := service.DefaultService.OpCreateCallHistory(ctx, req)
if ec != errcode.ErrCodeCallHistorySrvOk {
logger.Error("OpCreateCallHistory fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrorMsg(ctx, "server error")
return
}
ReplyOk(ctx, nil)
}
func OpUpdateCallHistory(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*callhistoryproto.OpUpdateReq)
ec := service.DefaultService.OpUpdateCallHistory(ctx, req)
if ec != errcode.ErrCodeCallHistorySrvOk {
logger.Error("OpUpdateCallHistory fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func OpDeleteCallHistory(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*callhistoryproto.OpDeleteReq)
ec := service.DefaultService.OpDeleteCallHistory(ctx, req.Id)
if ec != errcode.ErrCodeCallHistorySrvOk {
logger.Error("OpDeleteCallHistory fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func OpGetCallHistoryList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*callhistoryproto.OpListReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.OpGetCallHistoryList(ctx, req)
if ec != errcode.ErrCodeCallHistorySrvOk {
logger.Error("OpGetCallHistoryList fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &callhistoryproto.OpListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}
func OpGetCallHistoryCount(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*callhistoryproto.OpCountReq)
countMap, ec := service.DefaultService.OpGetCallHistoryCount(ctx, req)
if ec != errcode.ErrCodeCallHistorySrvOk {
logger.Error("OpGetCallHistoryCount fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &callhistoryproto.OpCountData{
LikeCount: countMap[consts.Like],
TakeNoInterestCount: countMap[consts.TakeNoInterest],
}
ReplyOk(ctx, data)
}
func OpGetCallEvaluationList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*callhistoryproto.OpCallEvaluationListReq)
list, ec := service.DefaultService.OpGetCallEvaluationList(ctx, req)
if ec != errcode.ErrCodeCallHistorySrvOk {
logger.Error("OpGetCallEvaluationList 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, callevaluation := range list {
mediaFillableList[objectMediaNum*i+0] = callevaluation.Avatar
}
mediafiller.FillList(ctx, mediaFillableList)
data := &callhistoryproto.OpCallEvaluationListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}