package controller import ( "service/api/consts" "service/api/errcode" accountproto "service/api/proto/account/proto" "service/app/mix/service" "service/bizcommon/util" "service/library/logger" "service/library/mediafiller" "github.com/gin-gonic/gin" ) func ApiUpdateAccount(ctx *gin.Context) { req := ctx.MustGet("client_req").(*accountproto.ApiUpdateReq) ec := service.DefaultService.ApiUpdateAccount(ctx, req) if ec != errcode.ErrCodeAccountSrvOk { logger.Error("ApiUpdateAccount fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } ReplyOk(ctx, nil) } func ApiGetAccountListByMid(ctx *gin.Context) { req := ctx.MustGet("client_req").(*accountproto.ApiListByMidReq) account, ec := service.DefaultService.ApiGetAccountListByMid(ctx, req) if ec != errcode.ErrCodeAccountSrvOk { logger.Error("ApiGetAccountListByMid fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } //填充媒体 mediafiller.FillEntity(ctx, account.Avatar) data := &accountproto.ApiListByMidData{ Account: account, } ReplyOk(ctx, data) } func ApiGetAccountListByMids(ctx *gin.Context) { req := ctx.MustGet("client_req").(*accountproto.ApiListByMidsReq) //设置默认页长 if req.Limit == 0 { req.Limit = consts.DefaultPageSize } list, ec := service.DefaultService.ApiGetAccountListByMids(ctx, req) if ec != errcode.ErrCodeAccountSrvOk { logger.Error("ApiGetAccountListByMids 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, account := range list { mediaFillableList[objectMediaNum*i+0] = account.Avatar } mediafiller.FillList(ctx, mediaFillableList) data := &accountproto.ApiListByMidsData{ List: list, Offset: req.Offset + len(list), } if len(list) >= req.Limit { data.More = 1 } ReplyOk(ctx, data) } func ApiGetAccountListByUserId(ctx *gin.Context) { req := ctx.MustGet("client_req").(*accountproto.ApiListByUserIdReq) account, ec := service.DefaultService.ApiGetAccountListByUserId(ctx, req) if ec != errcode.ErrCodeAccountSrvOk { logger.Error("ApiGetAccountListByUserId fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } //填充媒体 mediafiller.FillEntity(ctx, account.Avatar) data := &accountproto.ApiListByUserIdData{ Account: account, } ReplyOk(ctx, data) } func ApiGetAccountListFuzzilyByUserId(ctx *gin.Context) { req := ctx.MustGet("client_req").(*accountproto.ApiListFuzzilyByUserIdReq) //设置默认页长 if req.Limit == 0 { req.Limit = consts.DefaultPageSize } list, ec := service.DefaultService.ApiGetAccountListFuzzilyByUserId(ctx, req) if ec != errcode.ErrCodeAccountSrvOk { logger.Error("ApiGetAccountListFuzzilyByUserId fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } //填充媒体切片 objectMediaNum := 1 // 单个用户服务总共1个媒体类 mediaFillableListFuzzily := make([]mediafiller.MediaFillable, len(list)*objectMediaNum) for i, account := range list { mediaFillableListFuzzily[objectMediaNum*i+0] = account.Avatar } mediafiller.FillList(ctx, mediaFillableListFuzzily) data := &accountproto.ApiListFuzzilyByUserIdData{ List: list, Offset: req.Offset + len(list), } if len(list) >= req.Limit { data.More = 1 } ReplyOk(ctx, data) } func ApiGetAccountListFuzzilyByName(ctx *gin.Context) { req := ctx.MustGet("client_req").(*accountproto.ApiListFuzzilyByNameReq) //设置默认页长 if req.Limit == 0 { req.Limit = consts.DefaultPageSize } list, ec := service.DefaultService.ApiGetAccountListFuzzilyByName(ctx, req) if ec != errcode.ErrCodeAccountSrvOk { logger.Error("ApiGetAccountListFuzzilyByName fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } //填充媒体切片 objectMediaNum := 1 // 单个用户服务总共1个媒体类 mediaFillableListFuzzily := make([]mediafiller.MediaFillable, len(list)*objectMediaNum) for i, account := range list { mediaFillableListFuzzily[objectMediaNum*i+0] = account.Avatar } mediafiller.FillList(ctx, mediaFillableListFuzzily) data := &accountproto.ApiListFuzzilyByNameData{ List: list, Offset: req.Offset + len(list), } if len(list) >= req.Limit { data.More = 1 } ReplyOk(ctx, data) } func ApiGetAccountListForOthersByMid(ctx *gin.Context) { req := ctx.MustGet("client_req").(*accountproto.ApiListOthersByMidReq) account, ec := service.DefaultService.ApiGetAccountListForOthersByMid(ctx, req) if ec != errcode.ErrCodeAccountSrvOk { logger.Error("ApiGetAccountListOthersByMid fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } //填充媒体 mediafiller.FillEntity(ctx, account.Avatar) data := &accountproto.ApiListOthersByMidData{ Account: account, } ReplyOk(ctx, data) } func ApiGetAccountListForOthersByMids(ctx *gin.Context) { req := ctx.MustGet("client_req").(*accountproto.ApiListOthersByMidsReq) //设置默认页长 if req.Limit == 0 { req.Limit = consts.DefaultPageSize } list, ec := service.DefaultService.ApiGetAccountListForOthersByMids(ctx, req) if ec != errcode.ErrCodeAccountSrvOk { logger.Error("ApiGetAccountListForOthersByMids 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, account := range list { mediaFillableList[objectMediaNum*i+0] = account.Avatar } mediafiller.FillList(ctx, mediaFillableList) data := &accountproto.ApiListOthersByMidsData{ List: list, Offset: req.Offset + len(list), } if len(list) >= req.Limit { data.More = 1 } ReplyOk(ctx, data) } func ApiAccountExpInc(ctx *gin.Context) { req := ctx.MustGet("client_req").(*accountproto.ApiExpIncReq) result, ec := service.DefaultService.ApiAccountExpInc(ctx, req) if ec != errcode.ErrCodeAccountSrvOk { logger.Error("ApiAccountExpInc fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } ReplyOk(ctx, result) } func ApiCancelAccount(ctx *gin.Context) { req := ctx.MustGet("client_req").(*accountproto.ApiCancelReq) ec := service.DefaultService.ApiCancelAccount(ctx, req) if ec != errcode.ErrCodeAccountSrvOk { logger.Error("ApiCancelAccount fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } ReplyOk(ctx, nil) } func ApiAbortAccountCancellation(ctx *gin.Context) { req := ctx.MustGet("client_req").(*accountproto.ApiAbortCancellationReq) ec := service.DefaultService.ApiAbortAccountCancellation(ctx, req) if ec != errcode.ErrCodeAccountSrvOk { logger.Error("ApiAbortAccountCancellation fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) return } ReplyOk(ctx, nil) }