232 lines
6.2 KiB
Go
232 lines
6.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"service/api/consts"
|
|
"service/api/errcode"
|
|
"service/api/message/response"
|
|
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 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 ApiGetAccountListForOthersByUserId(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*accountproto.ApiListOthersByUserIdReq)
|
|
|
|
account, ec := service.DefaultService.ApiGetAccountListForOthersByUserId(ctx, req)
|
|
if ec != errcode.ErrCodeAccountSrvOk {
|
|
logger.Error("ApiGetAccountListOthersByUserId fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
ReplyErrCodeMsg(ctx, ec)
|
|
return
|
|
}
|
|
|
|
//填充媒体
|
|
mediafiller.FillEntity(ctx, account.Avatar)
|
|
|
|
data := &accountproto.ApiListOthersByUserIdData{
|
|
Account: account,
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
func ApiGetMobilePhone(ctx *gin.Context) {
|
|
req := ctx.MustGet("client_req").(*accountproto.ApiGetMobilePhoneReq)
|
|
|
|
// 验证token
|
|
mid, err := service.DefaultService.OpParseToken(ctx, req.Token)
|
|
if err != nil {
|
|
logger.Error("OpParseToken fail, req: %v, err: %v", util.ToJson(req), err)
|
|
response.ReplyErrorMsg(ctx, "Token解析失败")
|
|
return
|
|
}
|
|
|
|
vo, ec := service.DefaultService.ApiGetMobilePhoneByMid(ctx, mid)
|
|
if ec != errcode.ErrCodeAccountSrvOk {
|
|
logger.Error("ApiGetMobilePhoneByMid fail, req: %v, ec: %v", util.ToJson(req), ec)
|
|
response.ReplyErrCodeMsg(ctx, ec)
|
|
return
|
|
}
|
|
|
|
response.ReplyOk(ctx, vo)
|
|
}
|