refactor: reorganize modules and add Linux build tooling
This commit is contained in:
34
module/social/feed/internal/logic/post/action.go
Normal file
34
module/social/feed/internal/logic/post/action.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package post
|
||||
|
||||
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/feed/internal/models"
|
||||
pb "bsm/full/module/social/feed/pb"
|
||||
)
|
||||
|
||||
// 计数操作
|
||||
func Action(ctx context.Context, in *pb.PostActionRequest) (reply *pb.StatusReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.GetActionOp() == "" || in.GetActionType() == "" || in.GetIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
if err := models.LikeAction(in.ActionOp, in.ActionType, in.Identity); err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
40
module/social/feed/internal/logic/post/add_comment.go
Normal file
40
module/social/feed/internal/logic/post/add_comment.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package post
|
||||
|
||||
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/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"bsm/full/module/social/feed/internal/models"
|
||||
pb "bsm/full/module/social/feed/pb"
|
||||
)
|
||||
|
||||
// 新建评论
|
||||
func AddComment(ctx context.Context, in *pb.CommentItem) (reply *pb.StatusReply, err error) {
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var data = &models.FeedComment{
|
||||
Std_IICUDS: types.Std_IICUDS{Identity: utils.UUID()},
|
||||
PostIdentity: in.PostIdentity,
|
||||
Content: in.Content,
|
||||
}
|
||||
if in.Identity != "" {
|
||||
data.ParentIdentity = in.Identity
|
||||
}
|
||||
if err := models.AddComment(data, auth.Identity); err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.StatusReply{
|
||||
Data: data.Identity,
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
50
module/social/feed/internal/logic/post/change.go
Normal file
50
module/social/feed/internal/logic/post/change.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package post
|
||||
|
||||
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/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"bsm/full/module/social/feed/internal/models"
|
||||
pb "bsm/full/module/social/feed/pb"
|
||||
)
|
||||
|
||||
// 修改推文
|
||||
func Change(ctx context.Context, in *pb.PostItem) (reply *pb.StatusReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.GetContent() == "" || in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
var postData = models.FeedPost{
|
||||
Std_IICUDS: types.Std_IICUDS{Identity: in.Identity},
|
||||
Content: in.Content,
|
||||
IsOpen: in.IsOpen,
|
||||
}
|
||||
|
||||
if len(in.GetAttachs()) != 0 {
|
||||
for _, val := range in.Attachs {
|
||||
postData.Attachs = append(postData.Attachs, models.FeedRelateAttach{
|
||||
Identity: utils.UUID(),
|
||||
AttachType: val.AttachType,
|
||||
Url: val.Url,
|
||||
})
|
||||
}
|
||||
}
|
||||
err = models.ChargePost(&postData)
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.StatusReply{
|
||||
Data: postData.Identity,
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
29
module/social/feed/internal/logic/post/comment_list.go
Normal file
29
module/social/feed/internal/logic/post/comment_list.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package post
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
pb "bsm/full/module/social/feed/pb"
|
||||
)
|
||||
|
||||
// 评论列表
|
||||
func CommentList(ctx context.Context, in *pb.FetchRequest) (reply *pb.CommentListReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// valildate request page_no,page_size.
|
||||
if in.GetPageNo() < 1 {
|
||||
in.PageNo = 1
|
||||
}
|
||||
if in.GetPageSize() < 10 {
|
||||
in.PageSize = 50
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
62
module/social/feed/internal/logic/post/create.go
Normal file
62
module/social/feed/internal/logic/post/create.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package post
|
||||
|
||||
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/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"bsm/full/module/social/feed/internal/models"
|
||||
pb "bsm/full/module/social/feed/pb"
|
||||
)
|
||||
|
||||
// 新建推文
|
||||
func Create(ctx context.Context, in *pb.PostItem) (reply *pb.StatusReply, err error) {
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.GetContent() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
var postData = models.FeedPost{
|
||||
Std_IICUDS: types.Std_IICUDS{Identity: utils.UUID()},
|
||||
Std_Passport: types.Std_Passport{PassportID: auth.ID, PassportIdentity: auth.Identity},
|
||||
Content: in.Content,
|
||||
IsOpen: in.IsOpen,
|
||||
}
|
||||
|
||||
if len(in.GetAttachs()) > 0 {
|
||||
for _, val := range in.Attachs {
|
||||
postData.Attachs = append(postData.Attachs, models.FeedRelateAttach{
|
||||
PostIdentity: postData.Std_IICUDS.Identity,
|
||||
Identity: utils.UUID(),
|
||||
AttachType: val.AttachType,
|
||||
Url: val.Url,
|
||||
})
|
||||
}
|
||||
}
|
||||
if len(in.GetTags()) > 0 {
|
||||
for _, val := range in.Tags {
|
||||
postData.Tags = append(postData.Tags, models.FeedRelateTags{
|
||||
PostIdentity: postData.Std_IICUDS.Identity,
|
||||
Content: val.Content,
|
||||
Key: val.Key,
|
||||
})
|
||||
}
|
||||
}
|
||||
err = models.CreatePost(&postData)
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Data: postData.Identity,
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
34
module/social/feed/internal/logic/post/delete_comment.go
Normal file
34
module/social/feed/internal/logic/post/delete_comment.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package post
|
||||
|
||||
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/feed/internal/models"
|
||||
pb "bsm/full/module/social/feed/pb"
|
||||
)
|
||||
|
||||
// 删除评论
|
||||
func DeleteComment(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.GetId() == 0 && in.GetIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
err = models.DeleteComment(in.Identity)
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
67
module/social/feed/internal/logic/post/fetch.go
Normal file
67
module/social/feed/internal/logic/post/fetch.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package post
|
||||
|
||||
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/feed/internal/models"
|
||||
pb "bsm/full/module/social/feed/pb"
|
||||
)
|
||||
|
||||
// 推文列表
|
||||
func Fetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.PostListReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.GetPageNo() <= 0 {
|
||||
in.PageNo = 1
|
||||
}
|
||||
if in.GetPageSize() <= 0 {
|
||||
in.PageSize = 10
|
||||
}
|
||||
|
||||
data, cnt, err := models.PostList(in.PageNo, in.PageSize, in.Params["key"])
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
var res = &pb.PostListReply{Cnt: cnt}
|
||||
if cnt > 0 {
|
||||
res.List = AssembleList(data)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func AssembleList(data []*models.FeedPost) (res []*pb.PostItem) {
|
||||
for _, val := range data {
|
||||
post := &pb.PostItem{
|
||||
Identity: val.Identity,
|
||||
Content: val.Content,
|
||||
FeedIdentity: val.Identity,
|
||||
FeedId: int64(val.ID),
|
||||
IsOpen: val.IsOpen,
|
||||
CntUnlike: val.CntUnlike,
|
||||
CntLike: val.CntLike,
|
||||
CntComment: val.CntComment,
|
||||
}
|
||||
for _, tag := range val.Tags {
|
||||
post.Tags = append(post.Tags, &pb.TagItem{
|
||||
Key: tag.Key,
|
||||
Content: tag.Content,
|
||||
})
|
||||
}
|
||||
for _, attachs := range val.Attachs {
|
||||
post.Attachs = append(post.Attachs, &pb.AttachItem{
|
||||
Identity: attachs.Identity,
|
||||
AttachType: attachs.AttachType,
|
||||
Url: attachs.Url,
|
||||
})
|
||||
}
|
||||
res = append(res, post)
|
||||
}
|
||||
return
|
||||
}
|
||||
36
module/social/feed/internal/logic/post/remove.go
Normal file
36
module/social/feed/internal/logic/post/remove.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package post
|
||||
|
||||
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/feed/internal/models"
|
||||
pb "bsm/full/module/social/feed/pb"
|
||||
)
|
||||
|
||||
// 删除推文
|
||||
func Remove(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.GetIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = models.DeletePost(in.Identity)
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Data: vars.OK,
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user