refactor: reorganize modules and add Linux build tooling
This commit is contained in:
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
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user