Skip to content

Commit

Permalink
feat(post): add List
Browse files Browse the repository at this point in the history
  • Loading branch information
linehk committed Mar 8, 2024
1 parent ae351f8 commit fb0b487
Show file tree
Hide file tree
Showing 4 changed files with 609 additions and 2 deletions.
26 changes: 24 additions & 2 deletions service/post/rpc/internal/logic/list_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 NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
}

func (l *ListLogic) List(in *post.ListReq) (*post.ListResp, error) {
// todo: add your logic here and delete this line
postModelList, err := l.svcCtx.PostModel.ListByBlogUuid(l.ctx, in.GetBlogId())
if errors.Is(err, model.ErrNotFound) {
l.Error(errcode.Msg(errcode.PostNotExist))
return nil, errcode.Wrap(errcode.PostNotExist)
}
if err != nil {
l.Error(errcode.Msg(errcode.Database))
return nil, errcode.Wrap(errcode.Database)
}

return &post.ListResp{}, nil
var listResp post.ListResp
listResp.Kind = "blogger#postList"
listResp.NextPageToken = ""
for _, postModel := range postModelList {
postResp, err := Get(l.ctx, l.svcCtx, l.Logger, postModel)
if err != nil {
return nil, err
}
listResp.Items = append(listResp.Items, postResp)
}

return &listResp, nil
}
Loading

0 comments on commit fb0b487

Please sign in to comment.