222 lines
5.8 KiB
Go
222 lines
5.8 KiB
Go
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 OpUpdateAccount(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*accountproto.OpUpdateReq)
|
|
ec := service.DefaultService.OpUpdateAccount(ctx, req)
|
|
if ec != errcode.ErrCodeAccountSrvOk {
|
|
logger.Error("OpUpdateAccount fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
return
|
|
}
|
|
|
|
ReplyOk(ctx, nil)
|
|
}
|
|
|
|
func OpGetAccountListByMid(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*accountproto.OpListByMidReq)
|
|
|
|
account, ec := service.DefaultService.OpGetAccountListByMid(ctx, req)
|
|
if ec != errcode.ErrCodeAccountSrvOk {
|
|
logger.Error("OpGetAccountListByMid fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
return
|
|
}
|
|
|
|
//填充媒体
|
|
mediafiller.FillEntity(ctx, account.Avatar)
|
|
|
|
data := &accountproto.OpListByMidData{
|
|
Account: account,
|
|
}
|
|
|
|
ReplyOk(ctx, data)
|
|
}
|
|
|
|
func OpGetAccountListByMids(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*accountproto.OpListByMidsReq)
|
|
|
|
//设置默认页长
|
|
if req.Limit == 0 {
|
|
req.Limit = consts.DefaultPageSize
|
|
}
|
|
|
|
list, ec := service.DefaultService.OpGetAccountListByMids(ctx, req)
|
|
if ec != errcode.ErrCodeAccountSrvOk {
|
|
logger.Error("OpGetAccountListByMids 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.OpListByMidsData{
|
|
List: list,
|
|
Offset: req.Offset + len(list),
|
|
}
|
|
if len(list) >= req.Limit {
|
|
data.More = 1
|
|
}
|
|
|
|
ReplyOk(ctx, data)
|
|
}
|
|
|
|
func OpGetAccountListByUserId(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*accountproto.OpListByUserIdReq)
|
|
|
|
account, ec := service.DefaultService.OpGetAccountListByUserId(ctx, req)
|
|
if ec != errcode.ErrCodeAccountSrvOk {
|
|
logger.Error("OpGetAccountListByUserId fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
return
|
|
}
|
|
|
|
//填充媒体
|
|
mediafiller.FillEntity(ctx, account.Avatar)
|
|
|
|
data := &accountproto.OpListByUserIdData{
|
|
Account: account,
|
|
}
|
|
|
|
ReplyOk(ctx, data)
|
|
}
|
|
|
|
func OpGetAccountListFuzzilyByUserId(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*accountproto.OpListFuzzilyByUserIdReq)
|
|
|
|
//设置默认页长
|
|
if req.Limit == 0 {
|
|
req.Limit = consts.DefaultPageSize
|
|
}
|
|
|
|
list, ec := service.DefaultService.OpGetAccountListFuzzilyByUserId(ctx, req)
|
|
if ec != errcode.ErrCodeAccountSrvOk {
|
|
logger.Error("OpGetAccountListFuzzilyByUserId 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.OpListFuzzilyByUserIdData{
|
|
List: list,
|
|
Offset: req.Offset + len(list),
|
|
}
|
|
if len(list) >= req.Limit {
|
|
data.More = 1
|
|
}
|
|
|
|
ReplyOk(ctx, data)
|
|
}
|
|
|
|
func OpGetAccountListFuzzilyByName(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*accountproto.OpListFuzzilyByNameReq)
|
|
|
|
//设置默认页长
|
|
if req.Limit == 0 {
|
|
req.Limit = consts.DefaultPageSize
|
|
}
|
|
|
|
list, ec := service.DefaultService.OpGetAccountListFuzzilyByName(ctx, req)
|
|
if ec != errcode.ErrCodeAccountSrvOk {
|
|
logger.Error("OpGetAccountListFuzzilyByName 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.OpListFuzzilyByNameData{
|
|
List: list,
|
|
Offset: req.Offset + len(list),
|
|
}
|
|
if len(list) >= req.Limit {
|
|
data.More = 1
|
|
}
|
|
|
|
ReplyOk(ctx, data)
|
|
}
|
|
|
|
func OpGetAccountListForOthersByMid(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*accountproto.OpListOthersByMidReq)
|
|
|
|
account, ec := service.DefaultService.OpGetAccountListForOthersByMid(ctx, req)
|
|
if ec != errcode.ErrCodeAccountSrvOk {
|
|
logger.Error("OpGetAccountListOthersByMid fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
return
|
|
}
|
|
|
|
//填充媒体
|
|
mediafiller.FillEntity(ctx, account.Avatar)
|
|
|
|
data := &accountproto.OpListOthersByMidData{
|
|
Account: account,
|
|
}
|
|
|
|
ReplyOk(ctx, data)
|
|
}
|
|
|
|
func OpGetAccountListForOthersByMids(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*accountproto.OpListOthersByMidsReq)
|
|
|
|
//设置默认页长
|
|
if req.Limit == 0 {
|
|
req.Limit = consts.DefaultPageSize
|
|
}
|
|
|
|
list, ec := service.DefaultService.OpGetAccountListForOthersByMids(ctx, req)
|
|
if ec != errcode.ErrCodeAccountSrvOk {
|
|
logger.Error("OpGetAccountListForOthersByMids 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.OpListOthersByMidsData{
|
|
List: list,
|
|
Offset: req.Offset + len(list),
|
|
}
|
|
if len(list) >= req.Limit {
|
|
data.More = 1
|
|
}
|
|
|
|
ReplyOk(ctx, data)
|
|
}
|