service/app/mix/controller/account_op.go

188 lines
4.8 KiB
Go
Raw Normal View History

2023-12-21 22:17:40 +08:00
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 OpGetMobilePhoneByUserId(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*accountproto.OpGetMobilePhoneByUserIdReq)
mobilePhone, ec := service.DefaultService.OpGetMobilePhoneByUserId(ctx, req)
if ec != errcode.ErrCodeAccountSrvOk {
logger.Error("OpGetMobilePhoneByUserId fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &accountproto.OpGetMobilePhoneByUserIdData{
MobilePhone: mobilePhone,
}
ReplyOk(ctx, data)
}
2023-12-21 22:17:40 +08:00
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)
}
2024-01-02 19:34:05 +08:00
func OpGetAccountCount(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*accountproto.OpCountReq)
count, ec := service.DefaultService.OpGetAccountCount(ctx, req)
if ec != errcode.ErrCodeAccountSrvOk {
logger.Error("OpGetAccountCount fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &accountproto.OpCountData{
Count: count,
}
ReplyOk(ctx, data)
}