package controller import ( "service/api/consts" "service/api/errcode" notificationproto "service/api/proto/notification/proto" "service/app/mix/service" "service/bizcommon/util" "service/library/logger" "service/library/mediafiller" "github.com/gin-gonic/gin" ) func OpCreateNotification(ctx *gin.Context) { req := ctx.MustGet("client_req").(*notificationproto.OpCreateReq) ec := service.DefaultService.OpCreateNotification(ctx, req) if ec != errcode.ErrCodeNotificationSrvOk { logger.Error("OpCreateNotification fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrorMsg(ctx, "server error") return } ReplyOk(ctx, nil) } func OpUpdateNotification(ctx *gin.Context) { req := ctx.MustGet("client_req").(*notificationproto.OpUpdateReq) ec := service.DefaultService.OpUpdateNotification(ctx, req) if ec != errcode.ErrCodeNotificationSrvOk { logger.Error("OpUpdateNotification fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } ReplyOk(ctx, nil) } func OpDeleteNotification(ctx *gin.Context) { req := ctx.MustGet("client_req").(*notificationproto.OpDeleteReq) ec := service.DefaultService.OpDeleteNotification(ctx, req.Id) if ec != errcode.ErrCodeNotificationSrvOk { logger.Error("OpDeleteNotification fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } ReplyOk(ctx, nil) } func OpGetNotificationList(ctx *gin.Context) { req := ctx.MustGet("client_req").(*notificationproto.OpListReq) //设置默认页长 if req.Limit == 0 { req.Limit = consts.DefaultPageSize } list, ec := service.DefaultService.OpGetNotificationList(ctx, req) if ec != errcode.ErrCodeNotificationSrvOk { logger.Error("OpGetNotificationList fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } //填充媒体切片 mediaFillableList := make([]mediafiller.MediaFillable, len(list)) for i, media := range list { mediaFillableList[i] = media.Thumbnail } mediafiller.FillList(ctx, mediaFillableList) data := ¬ificationproto.OpListData{ List: list, Offset: req.Offset + len(list), } if len(list) >= req.Limit { data.More = 1 } ReplyOk(ctx, data) } func OpCancelNotification(ctx *gin.Context) { req := ctx.MustGet("client_req").(*notificationproto.OpCancelReq) ec := service.DefaultService.OpCancelNotification(ctx, req) if ec != errcode.ErrCodeNotificationSrvOk { logger.Error("OpCancelNotification fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } ReplyOk(ctx, nil) }