Skip to content

Commit

Permalink
add: add postslug argument to comment request
Browse files Browse the repository at this point in the history
  • Loading branch information
eleijonmarck committed Jun 28, 2022
1 parent 91dc77a commit 452f6e2
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 31 deletions.
3 changes: 2 additions & 1 deletion proto/blog/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ message QueryAllPostsResponse {
}

message QueryAllCommentsRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
string postSlug = 1;
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

message QueryAllCommentsResponse {
Expand Down
102 changes: 77 additions & 25 deletions x/blog/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions x/blog/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ func (m *MsgCreatePost) GetSigners() []sdk.AccAddress {
}

func (m *MsgCreateComment) ValidateBasic() error {
if m.PostSlug == "" {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "no post slug")
}
if m.Author == "" {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "no author")
}
if m.Body == "" {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "no body")
}
if m.PostSlug == "" {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "no slug")
}

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions x/blog/server/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func (s serverImpl) CreateComment(goCtx context.Context, request *blog.MsgCreate
store := prefix.NewStore(ctx.KVStore(s.storeKey), blog.KeyPrefix(blog.CommentKey))

key := []byte(request.PostSlug)
if store.Has(key) {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "duplicate slug %s found", request.PostSlug)
if !store.Has(key) {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "post %s to comment on does not exist in state", request.PostSlug)
}

comment := blog.Comment{
Expand Down

0 comments on commit 452f6e2

Please sign in to comment.