refactor: reorganize modules and add Linux build tooling
This commit is contained in:
62
module/social/relation/internal/config/config.go
Normal file
62
module/social/relation/internal/config/config.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/conf"
|
||||
"git.apinb.com/bsm-sdk/core/crypto/encipher"
|
||||
"git.apinb.com/bsm-sdk/core/env"
|
||||
)
|
||||
|
||||
var (
|
||||
Spec SrvConfig
|
||||
)
|
||||
|
||||
type SrvConfig struct {
|
||||
conf.Base `yaml:",inline"`
|
||||
Databases *conf.DBConf `yaml:"Databases"`
|
||||
MicroService *conf.MicroServiceConf `yaml:"MicroService"`
|
||||
Rpc map[string]conf.RpcConf `yaml:"Rpc"`
|
||||
Gateway *conf.GatewayConf `yaml:"Gateway"`
|
||||
Apm *conf.ApmConf `yaml:"APM"`
|
||||
Etcd *conf.EtcdConf `yaml:"Etcd"`
|
||||
WeChat *WeChatConf `yaml:"WeChatConf"`
|
||||
Token *TokenConf `yaml:"Token"`
|
||||
Kyc *KycConf `yaml:"Kyc"`
|
||||
}
|
||||
|
||||
type KycConf struct {
|
||||
Provider string `yaml:"Provider"`
|
||||
BaseUrl string `yaml:"BaseUrl"`
|
||||
ApiSecret string `yaml:"ApiSecret"`
|
||||
ApiToken string `yaml:"ApiToken"`
|
||||
ApiArgs string `yaml:"ApiArgs"`
|
||||
}
|
||||
|
||||
type TokenConf struct {
|
||||
Prefix string `yaml:"Prefix"`
|
||||
Expire int `yaml:"Expire"`
|
||||
}
|
||||
|
||||
type WeChatConf struct {
|
||||
AppID string `json:"app_id"`
|
||||
AppSecret string `json:"app_secret"`
|
||||
}
|
||||
|
||||
func New(srvKey string) {
|
||||
// 初始化配置 创建一个新的配置实例,用于服务配置
|
||||
conf.New(srvKey, &Spec)
|
||||
|
||||
// 配置校验 服务IP,端口; 端口如果不合规,则随机分配端口
|
||||
Spec.Port = conf.CheckPort(Spec.Port)
|
||||
Spec.BindIP = conf.CheckIP(Spec.BindIP)
|
||||
Spec.Addr = net.JoinHostPort(Spec.BindIP, Spec.Port)
|
||||
|
||||
// 配置校验 服务名称地址及监听地址不能为空
|
||||
conf.NotNil(Spec.Service, Spec.Cache)
|
||||
|
||||
// 初始化加密SecretKey
|
||||
encipher.New(env.Runtime.JwtSecretKey)
|
||||
|
||||
conf.PrintInfo(Spec.Addr)
|
||||
}
|
||||
25
module/social/relation/internal/impl/impl.go
Normal file
25
module/social/relation/internal/impl/impl.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package impl
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/cache/redis"
|
||||
"git.apinb.com/bsm-sdk/core/with"
|
||||
"bsm/full/module/social/relation/internal/config"
|
||||
cache "github.com/patrickmn/go-cache"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var (
|
||||
RedisService *redis.RedisClient
|
||||
EtcdService *clientv3.Client
|
||||
DBService *gorm.DB
|
||||
MemorySerice *cache.Cache
|
||||
)
|
||||
|
||||
func NewImpl() {
|
||||
// with activating
|
||||
MemorySerice = with.Memory(nil)
|
||||
RedisService = with.RedisCache(config.Spec.Cache) // redis cache
|
||||
DBService = with.Databases(config.Spec.Databases, nil) // model
|
||||
EtcdService = with.Etcd(config.Spec.Etcd) // etcd
|
||||
}
|
||||
202
module/social/relation/internal/logic/common/const.go
Normal file
202
module/social/relation/internal/logic/common/const.go
Normal file
@@ -0,0 +1,202 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"hash/crc64"
|
||||
"sort"
|
||||
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
var (
|
||||
Filed string = "relation_identity as identity,nickname,avatar,sex,province,city,area,sign"
|
||||
)
|
||||
|
||||
// 根据identity获取会员信息卡片
|
||||
func GetrelationInfoDetailCard(identity string) (card *pb.RelationItem, err error) {
|
||||
err = impl.DBService.Table("relation_extend").Select(Filed).Where("relation_identity = ?", identity).First(&card).Error
|
||||
return
|
||||
}
|
||||
|
||||
// 根据id数组获取多条会员信息卡片
|
||||
func GetrelationInfoDetailCardById(ids []uint) (cards []*pb.RelationItem, err error) {
|
||||
err = impl.DBService.Table("relation_extend").Select(Filed).Where("relation_id in ?", ids).Find(&cards).Error
|
||||
return
|
||||
}
|
||||
|
||||
// 实现将2个字符串,不论先后顺序输入,输出得到的唯一值都是一样的。
|
||||
func UniqueSessionID(s1, s2 string) string {
|
||||
strs := []string{s1, s2}
|
||||
sort.Strings(strs)
|
||||
table := crc64.MakeTable(crc64.ECMA)
|
||||
return fmt.Sprintf("%x", crc64.Checksum([]byte(strs[0]+strs[1]), table))
|
||||
}
|
||||
|
||||
// 根据用户ID,找到用户的申请好友信息
|
||||
func CollectionFriendApply(id uint) (reply *pb.ApplyFetchReply, err error) {
|
||||
var (
|
||||
version int64
|
||||
ids []uint
|
||||
last_msg_ids []uint
|
||||
maxSize int = 50
|
||||
applys = make([]*models.FriendApply, 0)
|
||||
replyItems = make([]*pb.ApplyItem, 0)
|
||||
mapCards = make(map[string]*pb.RelationItem)
|
||||
|
||||
messages = make([]*models.FriendApplyMessage, 0)
|
||||
mapMessages = make(map[uint]*pb.MessageItem)
|
||||
)
|
||||
reply = &pb.ApplyFetchReply{}
|
||||
|
||||
err = impl.DBService.Where("to_id=? ", id).Order("id desc").Limit(maxSize).Find(&applys).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, item := range applys {
|
||||
ids = append(ids, item.FromID)
|
||||
last_msg_ids = append(last_msg_ids, item.LastMessageID)
|
||||
}
|
||||
|
||||
result, err := GetrelationInfoDetailCardById(ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, item := range result {
|
||||
mapCards[item.Identity] = item
|
||||
}
|
||||
|
||||
err = impl.DBService.Where("id in ?", last_msg_ids).Find(&messages).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, item := range messages {
|
||||
mapMessages[item.ID] = &pb.MessageItem{
|
||||
RelationIdentity: item.PassportIdentity,
|
||||
Body: item.Body,
|
||||
CreatedAt: item.CreatedAt.Local().Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
}
|
||||
|
||||
for _, item := range applys {
|
||||
var applyItem = &pb.ApplyItem{}
|
||||
applyItem.Identity = item.Identity
|
||||
applyItem.CreatedAt = item.CreatedAt.Local().Format("2006-01-02 15:04:05")
|
||||
applyItem.Status = int32(item.Status)
|
||||
|
||||
if _, ok := mapCards[item.FromIdentity]; ok {
|
||||
applyItem.From = mapCards[item.FromIdentity]
|
||||
}
|
||||
|
||||
if _, ok := mapMessages[item.LastMessageID]; ok {
|
||||
applyItem.Message = mapMessages[item.LastMessageID]
|
||||
}
|
||||
|
||||
replyItems = append(replyItems, applyItem)
|
||||
version = int64(item.ID)
|
||||
}
|
||||
|
||||
reply.Applys = replyItems
|
||||
reply.Version = version
|
||||
return
|
||||
}
|
||||
|
||||
// 根据用户ID,找到用户的好友信息和分组信息
|
||||
func CollectionFriendData(id uint) (reply *pb.FriendsReply, err error) {
|
||||
var (
|
||||
version int64
|
||||
ids []uint
|
||||
|
||||
relationFriend = make([]models.RelationFriend, 0)
|
||||
mapRelationFrend = make(map[uint]models.RelationFriend)
|
||||
|
||||
friendInTag = make([]models.FriendInTag, 0)
|
||||
mapFriendInTag = make(map[string][]string)
|
||||
)
|
||||
reply = &pb.FriendsReply{}
|
||||
impl.DBService.Where("relation_id=?", id).Order("id desc").Find(&relationFriend)
|
||||
|
||||
for _, item := range relationFriend {
|
||||
ids = append(ids, item.ID)
|
||||
mapRelationFrend[item.ID] = item
|
||||
version = int64(item.ID)
|
||||
}
|
||||
|
||||
impl.DBService.Where("relation_id=?", id).Find(&friendInTag)
|
||||
|
||||
for _, item := range friendInTag {
|
||||
mapFriendInTag[item.FriendIdentity] = append(mapFriendInTag[item.FriendIdentity], item.TagIdentity)
|
||||
}
|
||||
|
||||
err = impl.DBService.Model(models.FriendTag{}).Where("relation_id=?", id).Order("id asc").Scan(&reply.Tags).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
reply.Friends, err = GetrelationInfoDetailCardById(ids)
|
||||
for idx, item := range reply.Friends {
|
||||
reply.Friends[idx].RemarkName = item.RemarkName
|
||||
reply.Friends[idx].Popular = item.Popular
|
||||
if _, ok := mapFriendInTag[item.Identity]; ok {
|
||||
reply.Friends[idx].Tags = mapFriendInTag[item.Identity]
|
||||
}
|
||||
}
|
||||
|
||||
reply.Version = version
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 根据Match表获取多条会员信息卡片
|
||||
func GetrelationInfoDetailCardByMatch(relation_identity string, offset, limit int) (cards []*pb.RelationItem, err error) {
|
||||
sql := `Select
|
||||
pe.relation_identity as identity,
|
||||
pe.name,
|
||||
pe.avatar,
|
||||
pe.birthday,
|
||||
pe.sex,
|
||||
pe.province,
|
||||
pe.city,
|
||||
pe.area,
|
||||
pe.sign,
|
||||
rm.status as foreign_status
|
||||
From relation_match as rm,relation_extend as pe
|
||||
Left join pe on pe.relation_identity=rm.recommend_identity
|
||||
Where rm.relation_identity=?
|
||||
Offset ?
|
||||
Limit ?
|
||||
Order by rm.id Desc`
|
||||
err = impl.DBService.Raw(sql, relation_identity, offset, limit).Scan(&cards).Error
|
||||
return
|
||||
}
|
||||
|
||||
func SetCache(identity string, collectionName string, in interface{}) error {
|
||||
key := "/RF/" + identity + "/" + collectionName
|
||||
val, err := json.Marshal(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = impl.RedisService.Client.Set(impl.RedisService.Ctx, key, string(val), 0).Err()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetCache(identity, collectionName string) (reply *pb.ApplyFetchReply, err error) {
|
||||
key := "/RF/" + identity + "/" + collectionName
|
||||
collection, err := impl.RedisService.Client.Get(impl.RedisService.Ctx, key).Result()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal([]byte(collection), &reply)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
33
module/social/relation/internal/logic/follow/do.go
Normal file
33
module/social/relation/internal/logic/follow/do.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package follow
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 执行关注
|
||||
func Do(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// valildate request id,identity.
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
45
module/social/relation/internal/logic/follow/doing.go
Normal file
45
module/social/relation/internal/logic/follow/doing.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package follow
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 执行关注
|
||||
func Doing(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
data := &models.RelationFollow{
|
||||
FromIdentity: auth.Identity,
|
||||
ToIdentity: in.Identity,
|
||||
}
|
||||
data.Identity = utils.UUID()
|
||||
|
||||
err = impl.DBService.Create(data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
66
module/social/relation/internal/logic/follow/fetch.go
Normal file
66
module/social/relation/internal/logic/follow/fetch.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package follow
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
common "bsm/full/module/social/relation/internal/logic/common"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 获取关注列表
|
||||
func Fetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.FetchRelationItemReply, err error) {
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var (
|
||||
total int64
|
||||
column string
|
||||
ids []uint
|
||||
model = impl.DBService.Model(&models.RelationFollow{})
|
||||
cards []*pb.RelationItem
|
||||
)
|
||||
|
||||
switch strings.ToUpper(in.Params["direction"]) {
|
||||
case "MY": // 我关注的
|
||||
column = "to_identity"
|
||||
model.Where("from_identity=?", auth.Identity)
|
||||
case "WHO": // 关注我的
|
||||
column = "from_identity"
|
||||
model.Where("to_identity=?", auth.Identity)
|
||||
default:
|
||||
return &pb.FetchRelationItemReply{}, nil
|
||||
}
|
||||
|
||||
//处理分页
|
||||
if in.PageNo <= 1 {
|
||||
in.PageNo = 1
|
||||
}
|
||||
if in.PageSize <= 1 {
|
||||
in.PageSize = 20
|
||||
}
|
||||
|
||||
err = model.Count(&total).Order("id desc").Offset(int(in.PageNo-1)*int(in.PageSize)).Limit(int(in.PageSize)).Pluck(column, &ids).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
//根据ids取得用户信息卡片
|
||||
cards, err = common.GetrelationInfoDetailCardById(ids)
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.FetchRelationItemReply{
|
||||
Total: total,
|
||||
Data: cards,
|
||||
}, nil
|
||||
}
|
||||
47
module/social/relation/internal/logic/follow/state.go
Normal file
47
module/social/relation/internal/logic/follow/state.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package follow
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// 关注状态
|
||||
func State(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
var data models.RelationFollow
|
||||
err = impl.DBService.Where("from_identity=? and to_identity=?", auth.Identity, in.Identity).First(&data).Error
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
} else {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Data: data.Identity,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
36
module/social/relation/internal/logic/follow/undo.go
Normal file
36
module/social/relation/internal/logic/follow/undo.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package follow
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 撤销关注
|
||||
func Undo(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = impl.DBService.Model(&models.RelationFollow{}).Delete("identity=?", in.Identity).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
69
module/social/relation/internal/logic/friend/apply_do.go
Normal file
69
module/social/relation/internal/logic/friend/apply_do.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 好友申请
|
||||
func ApplyDo(ctx context.Context, in *pb.ApplyDoRequest) (reply *pb.StatusReply, err error) {
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.ToIdentity == "" || in.Body == "" || in.ToId == 0 {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
//创建申请
|
||||
apply := models.FriendApply{
|
||||
FromID: uint(auth.ID),
|
||||
FromIdentity: auth.Identity,
|
||||
ToID: uint(in.ToId),
|
||||
ToIdentity: in.ToIdentity,
|
||||
LastMessageID: 0,
|
||||
}
|
||||
apply.Identity = utils.UUID()
|
||||
err = impl.DBService.Create(&apply).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
//创建留言
|
||||
msg := models.FriendApplyMessage{
|
||||
ApplyID: apply.ID,
|
||||
Body: in.Body,
|
||||
}
|
||||
msg.PassportID = auth.ID
|
||||
msg.PassportIdentity = auth.Identity
|
||||
|
||||
err = impl.DBService.Create(&msg).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
//回写最后一次交流的消息ID
|
||||
err = impl.DBService.Model(models.FriendApply{}).Where("id=?", apply.ID).UpdateColumn("last_message_id", msg.ID).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
//EventMQ:向mesh MQ中心发送报文,请求推送消息以及更新Cache.
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 好友申请Do:留言
|
||||
func ApplyDoMessage(ctx context.Context, in *pb.ApplyMessageRequest) (reply *pb.StatusReply, err error) {
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.Body == "" || in.ApplyId == 0 {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
msg := models.FriendApplyMessage{
|
||||
ApplyID: uint(in.ApplyId),
|
||||
Body: in.Body,
|
||||
}
|
||||
msg.PassportID = auth.ID
|
||||
msg.PassportIdentity = auth.Identity
|
||||
|
||||
err = impl.DBService.Create(&msg).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
//回写最后一次交流的消息ID
|
||||
err = impl.DBService.Model(models.FriendApply{}).Where("id=?", msg.ApplyID).UpdateColumn("last_message_id", msg.ID).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
//EventMQ:向mesh MQ中心发送报文,请求推送消息以及更新Cache.
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/logic/common"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 好友申请Do:确认
|
||||
func ApplyDoPass(ctx context.Context, in *pb.ApplyDoPassRequest) (reply *pb.StatusReply, err error) {
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.FriendRelationIdentity == "" || in.ApplyIdentity == "" || in.FriendRelationId == 0 {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
//写入好友表
|
||||
friend := &models.RelationFriend{FriendrelationID: uint(in.FriendRelationId), FriendrelationIdentity: in.FriendRelationIdentity}
|
||||
friend.Identity = utils.UUID()
|
||||
friend.PassportID = auth.ID
|
||||
friend.PassportIdentity = auth.Identity
|
||||
friend.SessionID = common.UniqueSessionID(auth.Identity, in.FriendRelationIdentity)
|
||||
|
||||
err = impl.DBService.Create(&friend).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
//EventMQ:向mesh MQ中心发送报文,请求推送消息以及更新Cache.
|
||||
|
||||
err = impl.DBService.Model(models.FriendApply{}).Where("to_identity=? and identity=?", auth.Identity, in.ApplyIdentity).UpdateColumn("status", 1).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 好友申请Do:拒绝
|
||||
func ApplyDoReject(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = impl.DBService.Model(models.FriendApply{}).Where("to_identity=? and identity=?", auth.Identity, in.Identity).UpdateColumn("status", -1).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
//EventMQ:向mesh MQ中心发送报文,请求推送消息以及更新Cache.
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
52
module/social/relation/internal/logic/friend/apply_fetch.go
Normal file
52
module/social/relation/internal/logic/friend/apply_fetch.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"bsm/full/module/social/relation/internal/logic/common"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 好友申请列表
|
||||
func ApplyFetch(ctx context.Context, in *pb.VersionRequest) (reply *pb.ApplyFetchReply, err error) {
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var cacheErr error
|
||||
if in.Version == 0 {
|
||||
reply, err = common.CollectionFriendApply(auth.ID)
|
||||
if err == nil {
|
||||
cacheErr = common.SetCache(auth.Identity, "apply", reply)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cache, err := common.GetCache(auth.Identity, "apply")
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrRedis
|
||||
}
|
||||
|
||||
if in.Version != cache.Version {
|
||||
reply, err = common.CollectionFriendApply(auth.ID)
|
||||
if err == nil {
|
||||
cacheErr = common.SetCache(auth.Identity, "apply", reply)
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
if cacheErr != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrRedis
|
||||
}
|
||||
return reply, nil
|
||||
}
|
||||
44
module/social/relation/internal/logic/friend/apply_get.go
Normal file
44
module/social/relation/internal/logic/friend/apply_get.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/logic/common"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 好友申请详情
|
||||
func ApplyGet(ctx context.Context, in *pb.IdentRequest) (reply *pb.FriendApplyGetReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
var apply models.FriendApply
|
||||
err = impl.DBService.Where("identity=?", in.Identity).First(&apply).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
reply.Data, err = common.GetrelationInfoDetailCard(apply.FromIdentity)
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
err = impl.DBService.Where("apply_id=?", apply.ID).Order("id asc").Find(&reply.Message).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return
|
||||
}
|
||||
38
module/social/relation/internal/logic/friend/delete.go
Normal file
38
module/social/relation/internal/logic/friend/delete.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 删除好友
|
||||
func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = impl.DBService.Model(models.RelationFriend{}).Delete("relation_id=? and identity=?", auth.ID, in.Identity).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
38
module/social/relation/internal/logic/friend/do_popular.go
Normal file
38
module/social/relation/internal/logic/friend/do_popular.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 受你欢迎的,置顶
|
||||
func DoPopular(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = impl.DBService.Model(models.RelationFriend{}).Where("relation_id=? and identity=?", auth.ID, in.Identity).UpdateColumn("popular", 1).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
52
module/social/relation/internal/logic/friend/fetch.go
Normal file
52
module/social/relation/internal/logic/friend/fetch.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"bsm/full/module/social/relation/internal/logic/common"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 获取好友列表
|
||||
func Fetch(ctx context.Context, in *pb.VersionRequest) (reply *pb.FriendsReply, err error) {
|
||||
// parse authorization meta.
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var cacheErr error
|
||||
if in.Version == 0 {
|
||||
reply, err = common.CollectionFriendData(auth.ID)
|
||||
if err == nil {
|
||||
cacheErr = common.SetCache(auth.Identity, "friends", reply)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cache, err := common.GetCache(auth.Identity, "friends")
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrRedis
|
||||
}
|
||||
|
||||
if in.Version != cache.Version {
|
||||
reply, err = common.CollectionFriendData(auth.ID)
|
||||
if err == nil {
|
||||
cacheErr = common.SetCache(auth.Identity, "friends", reply)
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
if cacheErr != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrRedis
|
||||
}
|
||||
return reply, nil
|
||||
}
|
||||
30
module/social/relation/internal/logic/friend/get.go
Normal file
30
module/social/relation/internal/logic/friend/get.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"bsm/full/module/social/relation/internal/logic/common"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 获取用户信息卡片
|
||||
func Get(ctx context.Context, in *pb.IdentRequest) (reply *pb.RelationItem, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
reply, err = common.GetrelationInfoDetailCard(in.Identity)
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return reply, nil
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 修改好友备注名称,如果要清除备注,直接nickname传空值
|
||||
func ModifyNickname(ctx context.Context, in *pb.ModifyNicknameRequest) (reply *pb.StatusReply, err error) {
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.Nickname == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = impl.DBService.Model(models.RelationFriend{}).Where("relation_id=? and identity=?", auth.ID, in.Identity).UpdateColumn("nickname", in.Nickname).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
22
module/social/relation/internal/logic/friend/search.go
Normal file
22
module/social/relation/internal/logic/friend/search.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 搜索
|
||||
func Search(ctx context.Context, in *pb.SearchRequest) (reply *pb.PartFriendReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.Keyword == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
return &pb.PartFriendReply{}, nil
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 创建标签
|
||||
func TagDoCreate(ctx context.Context, in *pb.TagDoCreateRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.TagName == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
data := &models.FriendTag{Name: in.TagName}
|
||||
data.Identity = utils.UUID()
|
||||
data.PassportID = auth.ID
|
||||
data.PassportIdentity = auth.Identity
|
||||
|
||||
err = impl.DBService.Create(data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
batchs := make([]*models.FriendInTag, 0)
|
||||
for _, identity := range in.FriendIdentity {
|
||||
temp := &models.FriendInTag{
|
||||
FriendIdentity: identity,
|
||||
TagIdentity: data.Identity,
|
||||
}
|
||||
temp.PassportID = auth.ID
|
||||
temp.PassportIdentity = auth.Identity
|
||||
|
||||
batchs = append(batchs, temp)
|
||||
}
|
||||
|
||||
err = impl.DBService.Create(&batchs).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 更新标签成员
|
||||
func TagDoUpdate(ctx context.Context, in *pb.TagDoUpdateRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.TagIdentity == "" || in.FriendIdentity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
switch strings.ToUpper(in.Direction) {
|
||||
case "ADD":
|
||||
data := models.FriendInTag{
|
||||
FriendIdentity: in.FriendIdentity,
|
||||
TagIdentity: in.TagIdentity,
|
||||
}
|
||||
data.PassportID = auth.ID
|
||||
data.PassportIdentity = auth.Identity
|
||||
|
||||
err = impl.DBService.Create(&data).Error
|
||||
case "DEL":
|
||||
err = impl.DBService.Model(models.FriendInTag{}).Delete("friend_identity=? and tag_identity=?", in.FriendIdentity, in.TagIdentity).Error
|
||||
default:
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
28
module/social/relation/internal/logic/friend/tag_fetch.go
Normal file
28
module/social/relation/internal/logic/friend/tag_fetch.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 获取标签列表
|
||||
func TagFetch(ctx context.Context, in *pb.Empty) (reply *pb.FriendTagsReply, err error) {
|
||||
// parse authorization meta.
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = impl.DBService.Model(models.FriendTag{}).Where("relation_id=?", auth.ID).Count(&reply.Total).Order("id asc").Scan(&reply.Data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return reply, nil
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/logic/common"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 获取标签成员
|
||||
func TagMemberFetch(ctx context.Context, in *pb.IdentRequest) (reply *pb.PartFriendReply, err error) {
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
var ids []uint
|
||||
err = impl.DBService.Model(models.RelationFriend{}).Where("relation_id=? and group_identity=?", auth.ID, in.Identity).Pluck("relation_id", ids).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
data, err := common.GetrelationInfoDetailCardById(ids)
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.PartFriendReply{
|
||||
Total: int32(len(data)),
|
||||
Friends: data,
|
||||
}, nil
|
||||
}
|
||||
38
module/social/relation/internal/logic/friend/undo_popular.go
Normal file
38
module/social/relation/internal/logic/friend/undo_popular.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 取消受欢迎的,取消置顶
|
||||
func UndoPopular(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = impl.DBService.Model(models.RelationFriend{}).Where("relation_id=? and identity=?", auth.ID, in.Identity).UpdateColumn("popular", 0).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
37
module/social/relation/internal/logic/match/do_ignore.go
Normal file
37
module/social/relation/internal/logic/match/do_ignore.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package match
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 执行忽略
|
||||
func DoIgnore(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = impl.DBService.Model(new(models.RelationFollow)).Delete("identity=?", in.Identity).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
45
module/social/relation/internal/logic/match/do_join.go
Normal file
45
module/social/relation/internal/logic/match/do_join.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package match
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 执行通过,加为好友
|
||||
func DoJoin(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
data := &models.RelationFollow{
|
||||
FromIdentity: auth.Identity,
|
||||
ToIdentity: in.Identity,
|
||||
}
|
||||
data.Identity = utils.UUID()
|
||||
|
||||
err = impl.DBService.Create(data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
52
module/social/relation/internal/logic/match/fetch.go
Normal file
52
module/social/relation/internal/logic/match/fetch.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package match
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"bsm/full/module/social/relation/internal/impl"
|
||||
"bsm/full/module/social/relation/internal/logic/common"
|
||||
"bsm/full/module/social/relation/internal/models"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 获取匹配列表
|
||||
func Fetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.FetchRelationItemReply, err error) {
|
||||
// parse authorization meta.
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 处理分页
|
||||
if in.PageNo <= 1 {
|
||||
in.PageNo = 1
|
||||
}
|
||||
if in.PageSize <= 1 {
|
||||
in.PageSize = 20
|
||||
}
|
||||
|
||||
var (
|
||||
total int64
|
||||
)
|
||||
|
||||
err = impl.DBService.Model(&models.RelationMatch{}).Where("relation_identity=?", auth.Identity).Count(&total).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
// 取得用户信息卡片
|
||||
data, err := common.GetrelationInfoDetailCardByMatch(auth.Identity, int(in.PageNo-1)*int(in.PageSize), int(in.PageSize))
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
reply = &pb.FetchRelationItemReply{
|
||||
Total: total,
|
||||
Data: data,
|
||||
}
|
||||
return reply, nil
|
||||
}
|
||||
30
module/social/relation/internal/logic/match/get.go
Normal file
30
module/social/relation/internal/logic/match/get.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package match
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"bsm/full/module/social/relation/internal/logic/common"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
// 获取匹配详情
|
||||
func Get(ctx context.Context, in *pb.IdentRequest) (reply *pb.RelationItem, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
reply, err = common.GetrelationInfoDetailCard(in.Identity)
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return reply, nil
|
||||
}
|
||||
1
module/social/relation/internal/models/base.go
Normal file
1
module/social/relation/internal/models/base.go
Normal file
@@ -0,0 +1 @@
|
||||
package models
|
||||
20
module/social/relation/internal/models/friend_apply.go
Normal file
20
module/social/relation/internal/models/friend_apply.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// FriendApply 好友申请
|
||||
type FriendApply struct {
|
||||
types.Std_IICUDS
|
||||
FromID uint `gorm:"column:from_id;not null;" json:"from_id"` //申请人id
|
||||
FromIdentity string `gorm:"column:from_identity;type:varchar(50);not null;" json:"from_identity"` //申请人identity
|
||||
ToID uint `gorm:"column:to_id;not null;" json:"to_id"` //目的人id
|
||||
ToIdentity string `gorm:"column:to_identity;type:varchar(50);not null;" json:"to_identity"` //目的人identity
|
||||
LastMessageID uint `gorm:"column:last_message_id;not null;" json:"last_message_id"` //最后交流ID
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (fg *FriendApply) TableName() string {
|
||||
return "relation_friend_apply"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// FriendApply 好友申请交流表
|
||||
type FriendApplyMessage struct {
|
||||
types.Std_IICUDS
|
||||
types.Std_Passport
|
||||
ApplyID uint `gorm:"column:apply_id;not null;" json:"apply_id"` //申请表ID
|
||||
Body string `gorm:"column:body;type:varchar(500);default:''" json:"body"`
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (fg *FriendApplyMessage) TableName() string {
|
||||
return "relation_friend_apply_message"
|
||||
}
|
||||
18
module/social/relation/internal/models/friend_in_tag.go
Normal file
18
module/social/relation/internal/models/friend_in_tag.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// FriendData 好友存在于那些标签
|
||||
type FriendInTag struct {
|
||||
types.Std_IICUDS
|
||||
types.Std_Passport //标签归属
|
||||
FriendIdentity string `gorm:"column:friend_identity;type:varchar(36);not null;" json:"friend_identity"`
|
||||
TagIdentity string `gorm:"column:tag_identity;type:varchar(36);not null;" json:"tag_identity"` //所属好友标签Identity
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (fd *FriendInTag) TableName() string {
|
||||
return "relation_friend_in_tag"
|
||||
}
|
||||
17
module/social/relation/internal/models/friend_tag.go
Normal file
17
module/social/relation/internal/models/friend_tag.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// FriendTag 好友标签分组信息
|
||||
type FriendTag struct {
|
||||
types.Std_IICUDS
|
||||
types.Std_Passport //标签归属
|
||||
Name string `gorm:"column:name;type:varchar(255);not null;" json:"name"`
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (fg *FriendTag) TableName() string {
|
||||
return "relation_friend_tag"
|
||||
}
|
||||
1
module/social/relation/internal/models/query.go
Normal file
1
module/social/relation/internal/models/query.go
Normal file
@@ -0,0 +1 @@
|
||||
package models
|
||||
17
module/social/relation/internal/models/relation_follow.go
Normal file
17
module/social/relation/internal/models/relation_follow.go
Normal file
@@ -0,0 +1,17 @@
|
||||
// Models generated by mesh dev cli,@Author: David Yan(david.yan@qq.com).
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
type RelationFollow struct {
|
||||
types.Std_IICUDS
|
||||
FromIdentity string `gorm:"column:from_identity;type:varchar(36);not null;" json:"from_identity"` // 关注者
|
||||
ToIdentity string `gorm:"column:to_identity;type:varchar(255);not null;" json:"to_identity"` // 关注对象`
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *RelationFollow) TableName() string {
|
||||
return "relation_follow" //对应数据库表名
|
||||
}
|
||||
21
module/social/relation/internal/models/relation_friend.go
Normal file
21
module/social/relation/internal/models/relation_friend.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// FriendData 好友列表
|
||||
type RelationFriend struct {
|
||||
types.Std_IICUDS
|
||||
types.Std_Passport
|
||||
FriendrelationID uint `gorm:"column:friend_relation_id;not null;" json:"friend_relation_id"` //好友的会员唯一ID
|
||||
FriendrelationIdentity string `gorm:"column:friend_relation_identity;not null;" json:"friend_relation_identity"` //好友的会员唯一标识
|
||||
RemarkName string `gorm:"column:remark_name;type:varchar(255);default:'';" json:"remark_name"` //备注
|
||||
Popular int `gorm:"column:popular;type:int2;default:0;" json:"popular"` //是否置顶,默认:否
|
||||
SessionID string `gorm:"column:session_id;not null;" json:"session_id"` //与好友的会话ID
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (fd *RelationFriend) TableName() string {
|
||||
return "relation_friend"
|
||||
}
|
||||
15
module/social/relation/internal/models/relation_match.go
Normal file
15
module/social/relation/internal/models/relation_match.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/types"
|
||||
|
||||
// RelationMatch records a recommended relationship between two identities.
|
||||
type RelationMatch struct {
|
||||
types.Std_IICUDS
|
||||
RelationIdentity string `gorm:"column:relation_identity;type:varchar(36);not null;" json:"relation_identity"`
|
||||
RecommendIdentity string `gorm:"column:recommend_identity;type:varchar(255);not null;" json:"recommend_identity"`
|
||||
}
|
||||
|
||||
// TableName returns the backing relation table.
|
||||
func (*RelationMatch) TableName() string {
|
||||
return "relation_match"
|
||||
}
|
||||
36
module/social/relation/internal/server/follow_server.go
Normal file
36
module/social/relation/internal/server/follow_server.go
Normal file
@@ -0,0 +1,36 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"bsm/full/module/social/relation/internal/logic/follow"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
type FollowServer struct {
|
||||
pb.UnimplementedFollowServer
|
||||
}
|
||||
|
||||
func NewFollowServer() *FollowServer {
|
||||
return &FollowServer{}
|
||||
}
|
||||
|
||||
// 执行关注
|
||||
func (s *FollowServer) Doing(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return follow.Doing(ctx, in)
|
||||
}
|
||||
|
||||
// 撤销关注
|
||||
func (s *FollowServer) Undo(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return follow.Undo(ctx, in)
|
||||
}
|
||||
|
||||
// 关注状态
|
||||
func (s *FollowServer) State(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return follow.State(ctx, in)
|
||||
}
|
||||
|
||||
// 获取关注列表
|
||||
func (s *FollowServer) Fetch(ctx context.Context, in *pb.FetchRequest) (*pb.FetchRelationItemReply, error) {
|
||||
return follow.Fetch(ctx, in)
|
||||
}
|
||||
101
module/social/relation/internal/server/friend_server.go
Normal file
101
module/social/relation/internal/server/friend_server.go
Normal file
@@ -0,0 +1,101 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"bsm/full/module/social/relation/internal/logic/friend"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
type FriendServer struct {
|
||||
pb.UnimplementedFriendServer
|
||||
}
|
||||
|
||||
func NewFriendServer() *FriendServer {
|
||||
return &FriendServer{}
|
||||
}
|
||||
|
||||
// 搜索
|
||||
func (s *FriendServer) Search(ctx context.Context, in *pb.SearchRequest) (*pb.PartFriendReply, error) {
|
||||
return friend.Search(ctx, in)
|
||||
}
|
||||
|
||||
// 获取好友列表
|
||||
func (s *FriendServer) Fetch(ctx context.Context, in *pb.VersionRequest) (*pb.FriendsReply, error) {
|
||||
return friend.Fetch(ctx, in)
|
||||
}
|
||||
|
||||
// 获取用户信息卡片
|
||||
func (s *FriendServer) Get(ctx context.Context, in *pb.IdentRequest) (*pb.RelationItem, error) {
|
||||
return friend.Get(ctx, in)
|
||||
}
|
||||
|
||||
// 修改好友备注名称,如果要清除备注,直接nickname传空值
|
||||
func (s *FriendServer) ModifyNickname(ctx context.Context, in *pb.ModifyNicknameRequest) (*pb.StatusReply, error) {
|
||||
return friend.ModifyNickname(ctx, in)
|
||||
}
|
||||
|
||||
// 受你欢迎的,置顶
|
||||
func (s *FriendServer) DoPopular(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return friend.DoPopular(ctx, in)
|
||||
}
|
||||
|
||||
// 取消受欢迎的,取消置顶
|
||||
func (s *FriendServer) UndoPopular(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return friend.UndoPopular(ctx, in)
|
||||
}
|
||||
|
||||
// 删除好友
|
||||
func (s *FriendServer) Delete(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return friend.Delete(ctx, in)
|
||||
}
|
||||
|
||||
// 好友申请列表
|
||||
func (s *FriendServer) ApplyFetch(ctx context.Context, in *pb.VersionRequest) (*pb.ApplyFetchReply, error) {
|
||||
return friend.ApplyFetch(ctx, in)
|
||||
}
|
||||
|
||||
// 好友申请详情
|
||||
func (s *FriendServer) ApplyGet(ctx context.Context, in *pb.IdentRequest) (*pb.FriendApplyGetReply, error) {
|
||||
return friend.ApplyGet(ctx, in)
|
||||
}
|
||||
|
||||
// 好友申请
|
||||
func (s *FriendServer) ApplyDo(ctx context.Context, in *pb.ApplyDoRequest) (*pb.StatusReply, error) {
|
||||
return friend.ApplyDo(ctx, in)
|
||||
}
|
||||
|
||||
// 好友申请Do:留言
|
||||
func (s *FriendServer) ApplyDoMessage(ctx context.Context, in *pb.ApplyMessageRequest) (*pb.StatusReply, error) {
|
||||
return friend.ApplyDoMessage(ctx, in)
|
||||
}
|
||||
|
||||
// 好友申请Do:确认
|
||||
func (s *FriendServer) ApplyDoPass(ctx context.Context, in *pb.ApplyDoPassRequest) (*pb.StatusReply, error) {
|
||||
return friend.ApplyDoPass(ctx, in)
|
||||
}
|
||||
|
||||
// 好友申请Do:拒绝
|
||||
func (s *FriendServer) ApplyDoReject(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return friend.ApplyDoReject(ctx, in)
|
||||
}
|
||||
|
||||
// 获取标签列表
|
||||
func (s *FriendServer) TagFetch(ctx context.Context, in *pb.Empty) (*pb.FriendTagsReply, error) {
|
||||
return friend.TagFetch(ctx, in)
|
||||
}
|
||||
|
||||
// 获取标签成员
|
||||
func (s *FriendServer) TagMemberFetch(ctx context.Context, in *pb.IdentRequest) (*pb.PartFriendReply, error) {
|
||||
return friend.TagMemberFetch(ctx, in)
|
||||
}
|
||||
|
||||
// 创建标签
|
||||
func (s *FriendServer) TagDoCreate(ctx context.Context, in *pb.TagDoCreateRequest) (*pb.StatusReply, error) {
|
||||
return friend.TagDoCreate(ctx, in)
|
||||
}
|
||||
|
||||
// 更新标签成员
|
||||
func (s *FriendServer) TagDoUpdate(ctx context.Context, in *pb.TagDoUpdateRequest) (*pb.StatusReply, error) {
|
||||
return friend.TagDoUpdate(ctx, in)
|
||||
}
|
||||
36
module/social/relation/internal/server/match_server.go
Normal file
36
module/social/relation/internal/server/match_server.go
Normal file
@@ -0,0 +1,36 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"bsm/full/module/social/relation/internal/logic/match"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
)
|
||||
|
||||
type MatchServer struct {
|
||||
pb.UnimplementedMatchServer
|
||||
}
|
||||
|
||||
func NewMatchServer() *MatchServer {
|
||||
return &MatchServer{}
|
||||
}
|
||||
|
||||
// 获取匹配列表
|
||||
func (s *MatchServer) Fetch(ctx context.Context, in *pb.FetchRequest) (*pb.FetchRelationItemReply, error) {
|
||||
return match.Fetch(ctx, in)
|
||||
}
|
||||
|
||||
// 获取匹配详情
|
||||
func (s *MatchServer) Get(ctx context.Context, in *pb.IdentRequest) (*pb.RelationItem, error) {
|
||||
return match.Get(ctx, in)
|
||||
}
|
||||
|
||||
// 执行通过,加为好友
|
||||
func (s *MatchServer) DoJoin(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return match.DoJoin(ctx, in)
|
||||
}
|
||||
|
||||
// 执行忽略
|
||||
func (s *MatchServer) DoIgnore(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
|
||||
return match.DoIgnore(ctx, in)
|
||||
}
|
||||
75
module/social/relation/internal/server/new.go
Normal file
75
module/social/relation/internal/server/new.go
Normal file
@@ -0,0 +1,75 @@
|
||||
// Code generated by protoc-gen-slc. DO NOT EDIT.
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
pb "bsm/full/module/social/relation/pb"
|
||||
gwRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/reflection"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
Grpc *grpc.Server
|
||||
Ctx context.Context
|
||||
Mux *gwRuntime.ServeMux
|
||||
}
|
||||
|
||||
func New(addr string) *Server {
|
||||
srv := &Server{Ctx: context.Background(), Grpc: grpc.NewServer(), Mux: gwRuntime.NewServeMux(
|
||||
gwRuntime.WithForwardResponseRewriter(responseEnvelope),
|
||||
)}
|
||||
|
||||
// register service to grpc.Server
|
||||
pb.RegisterFollowServer(srv.Grpc, NewFollowServer())
|
||||
pb.RegisterFriendServer(srv.Grpc, NewFriendServer())
|
||||
pb.RegisterMatchServer(srv.Grpc, NewMatchServer())
|
||||
|
||||
reflection.Register(srv.Grpc)
|
||||
|
||||
// 将服务注册到Gateway
|
||||
opts := []grpc.DialOption{grpc.WithInsecure()}
|
||||
pb.RegisterFollowHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
|
||||
pb.RegisterFriendHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
|
||||
pb.RegisterMatchHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
|
||||
|
||||
// Register services swagger
|
||||
srv.RegisterSwagger()
|
||||
|
||||
return srv
|
||||
}
|
||||
|
||||
// RegisterSwagger 注册swagger
|
||||
func (s *Server) RegisterSwagger() {
|
||||
srvKey := strings.ToLower(vars.ServiceKey)
|
||||
s.Mux.HandlePath("GET", "/"+srvKey+".swagger.json", func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
bytes, err := os.ReadFile("./swagger/" + srvKey + ".swagger.json")
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
w.Write(bytes)
|
||||
return
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
// response envelope
|
||||
func responseEnvelope(_ context.Context, response proto.Message) (interface{}, error) {
|
||||
name := string(response.ProtoReflect().Descriptor().Name())
|
||||
if name == "Status" || name == "Error" || name == "StatusReply" {
|
||||
return response, nil
|
||||
}
|
||||
return map[string]any{
|
||||
"code": 0,
|
||||
"message": "OK",
|
||||
"result": response,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user