service/vendor/app/mix/controller/accountrelation_api.go

210 lines
5.8 KiB
Go

package controller
import (
"service/api/consts"
"service/api/errcode"
accountrelationproto "service/api/proto/accountrelation/proto"
"service/app/mix/service"
"service/bizcommon/util"
"service/library/logger"
"github.com/gin-gonic/gin"
)
func ApiCreateAccountRelation(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*accountrelationproto.ApiCreateReq)
ec := service.DefaultService.ApiCreateAccountRelation(ctx, req)
if ec != errcode.ErrCodeAccountRelationSrvOk {
logger.Error("ApiCreateAccountRelation fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func ApiUpdateAccountRelation(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*accountrelationproto.ApiUpdateReq)
ec := service.DefaultService.ApiUpdateAccountRelation(ctx, req)
if ec != errcode.ErrCodeAccountRelationSrvOk {
logger.Error("ApiUpdateAccountRelation fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrorMsg(ctx, "server error")
return
}
ReplyOk(ctx, nil)
}
func ApiDeleteAccountRelation(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*accountrelationproto.ApiDeleteReq)
ec := service.DefaultService.ApiDeleteAccountRelation(ctx, req)
if ec != errcode.ErrCodeAccountRelationSrvOk {
logger.Error("ApiDeleteAccountRelation fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
ReplyOk(ctx, nil)
}
func ApiGetFollowAccountRelationList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*accountrelationproto.ApiListReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.ApiGetFollowAccountRelationList(ctx, req)
if ec != errcode.ErrCodeAccountRelationSrvOk {
logger.Error("ApiGetFollowAccountRelationList fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &accountrelationproto.ApiListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}
func ApiGetIsFollowedAccountRelationList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*accountrelationproto.ApiListReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.ApiGetIsFollowedAccountRelationList(ctx, req)
if ec != errcode.ErrCodeAccountRelationSrvOk {
logger.Error("ApiGetIsFollowedAccountRelationList fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &accountrelationproto.ApiListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}
func ApiGetFriendAccountRelationList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*accountrelationproto.ApiListReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.ApiGetFriendAccountRelationList(ctx, req)
if ec != errcode.ErrCodeAccountRelationSrvOk {
logger.Error("ApiGetFriendAccountRelationList fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &accountrelationproto.ApiListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}
func ApiGetIgnoreAccountRelationList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*accountrelationproto.ApiListReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.ApiGetIgnoreAccountRelationList(ctx, req)
if ec != errcode.ErrCodeAccountRelationSrvOk {
logger.Error("ApiGetIgnoreAccountRelationList fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &accountrelationproto.ApiListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}
func ApiGetAbleToAccessWeixinOfAccountRelationList(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*accountrelationproto.ApiListReq)
//设置默认页长
if req.Limit == 0 {
req.Limit = consts.DefaultPageSize
}
list, ec := service.DefaultService.ApiGetAbleToAccessWeixinOfAccountRelationList(ctx, req)
if ec != errcode.ErrCodeAccountRelationSrvOk {
logger.Error("ApiGetAbleToAccessWeixinOfAccountRelationList fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &accountrelationproto.ApiListData{
List: list,
Offset: req.Offset + len(list),
}
if len(list) >= req.Limit {
data.More = 1
}
ReplyOk(ctx, data)
}
func ApiGetAccountRelationCount(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*accountrelationproto.ApiCountReq)
countMap, ec := service.DefaultService.ApiGetAccountRelationCount(ctx, req)
if ec != errcode.ErrCodeAccountRelationSrvOk {
logger.Error("ApiGetAccountRelationCount fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &accountrelationproto.ApiCountData{
FollowCount: countMap[consts.Follow],
IsFollowedCount: countMap[consts.IsFollowed],
FriendCount: countMap[consts.Friend],
}
ReplyOk(ctx, data)
}
func ApiGetAccountRelationBySentence(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*accountrelationproto.ApiListBySentenceReq)
_, ec := service.DefaultService.ApiGetAccountRelationBySentence(ctx, req)
isAccountRelationExisted := true
if ec == errcode.ErrCodeAccountRelationNotExist {
isAccountRelationExisted = false
} else if ec != errcode.ErrCodeAccountRelationSrvOk {
logger.Error("ApiGetAccountRelationBySentence fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &accountrelationproto.ApiListBySentenceData{
IsAccountRelationExisted: isAccountRelationExisted,
}
ReplyOk(ctx, data)
}