Skip to content

Commit

Permalink
feat(post): add ListPostUserInfos
Browse files Browse the repository at this point in the history
  • Loading branch information
linehk committed Mar 8, 2024
1 parent fb0b487 commit 7c2166a
Show file tree
Hide file tree
Showing 5 changed files with 659 additions and 4 deletions.
7 changes: 5 additions & 2 deletions service/post/rpc/internal/logic/get_post_user_infos_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ func (l *GetPostUserInfosLogic) GetPostUserInfos(in *post.GetPostUserInfosReq) (
l.Error(errcode.Msg(errcode.Database))
return nil, errcode.Wrap(errcode.Database)
}
return GetPostUserInfos(l.ctx, l.svcCtx, l, postUserInfosModel)
}

func GetPostUserInfos(ctx context.Context, svcCtx *svc.ServiceContext, l logx.Logger, postUserInfosModel *model.PostUserInfo) (*post.PostUserInfos, error) {
var postUserInfosResp post.PostUserInfos
postUserInfosResp.Kind = "blogger#postUserInfo"
postUserInfosResp.PostUserInfo = &post.PostUserInfo{}
Expand All @@ -46,7 +49,7 @@ func (l *GetPostUserInfosLogic) GetPostUserInfos(in *post.GetPostUserInfosReq) (
postUserInfosResp.PostUserInfo.BlogId = postUserInfosModel.BlogUuid.String
postUserInfosResp.PostUserInfo.PostId = postUserInfosModel.PostUuid.String

postModel, err := l.svcCtx.PostModel.FindOneByBlogUuidAndPostUuid(l.ctx, in.GetBlogId(), in.GetPostId())
postModel, err := svcCtx.PostModel.FindOneByBlogUuidAndPostUuid(ctx, postUserInfosModel.BlogUuid.String, postUserInfosModel.PostUuid.String)
if errors.Is(err, model.ErrNotFound) {
l.Error(errcode.Msg(errcode.PostNotExist))
return nil, errcode.Wrap(errcode.PostNotExist)
Expand All @@ -55,7 +58,7 @@ func (l *GetPostUserInfosLogic) GetPostUserInfos(in *post.GetPostUserInfosReq) (
l.Error(errcode.Msg(errcode.Database))
return nil, errcode.Wrap(errcode.Database)
}
postResp, err := Get(l.ctx, l.svcCtx, l.Logger, postModel)
postResp, err := Get(ctx, svcCtx, l, postModel)
if err != nil {
return nil, err
}
Expand Down
26 changes: 24 additions & 2 deletions service/post/rpc/internal/logic/list_post_user_infos_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package logic

import (
"context"
"errors"

"github.com/linehk/go-microservices-blogger/errcode"
"github.com/linehk/go-microservices-blogger/service/post/rpc/internal/svc"
"github.com/linehk/go-microservices-blogger/service/post/rpc/model"
"github.com/linehk/go-microservices-blogger/service/post/rpc/post"

"github.com/zeromicro/go-zero/core/logx"
Expand All @@ -24,7 +27,26 @@ func NewListPostUserInfosLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}

func (l *ListPostUserInfosLogic) ListPostUserInfos(in *post.ListPostUserInfosReq) (*post.ListPostUserInfosResp, error) {
// todo: add your logic here and delete this line
postUserInfosModelList, err := l.svcCtx.PostUserInfoModel.ListByUserUuidAndBlogUuid(l.ctx, in.GetUserId(), in.GetBlogId())
if errors.Is(err, model.ErrNotFound) {
l.Error(errcode.Msg(errcode.PostUserInfosNotExist))
return nil, errcode.Wrap(errcode.PostUserInfosNotExist)
}
if err != nil {
l.Error(errcode.Msg(errcode.Database))
return nil, errcode.Wrap(errcode.Database)
}

var listPostUserInfosResp post.ListPostUserInfosResp
listPostUserInfosResp.Kind = "blogger#postUserInfosList"
listPostUserInfosResp.NextPageToken = ""
for _, postUserInfosModel := range postUserInfosModelList {
postUserInfosResp, err := GetPostUserInfos(l.ctx, l.svcCtx, l.Logger, postUserInfosModel)
if err != nil {
return nil, err
}
listPostUserInfosResp.Items = append(listPostUserInfosResp.Items, postUserInfosResp)
}

return &post.ListPostUserInfosResp{}, nil
return &listPostUserInfosResp, nil
}
Loading

0 comments on commit 7c2166a

Please sign in to comment.