Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

feat: add post commenting feature #9

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Pantani
Copy link

@Pantani Pantani commented Jul 14, 2022

Description

add post commenting feature to the x/blog moduleL

  • Add a new Msg service method called CreateComment. This method's input takes:
    • post_slug as string,
    • author as string (Bech32-encoded address),
    • body as a string.
  • New comments are persisted in the blockchain state. Comment cannot be inserted into the state if its corresponding Post does not exist in the state.
  • Add a new AllComments gRPC query method. This method's input should take a post_slug (a string) and returns all the comments on a post.
  • Add CLI subcommands, tx create-comment and query list-comments, which call the CreateComment and AllComments service methods under the hood.

Aditional features

  • A comment cannot be duplicated by the same user to avoid flooding the posts or the network.
  • Add config.yml for we can run the chain using ignite (eg: ignite c serve);

How to test

Run the chain:

  • Using the Makefile:
$ make build
$ ignite c serve

Test Commands:

  • Create posts:
$ becd tx blog create-post cosmos1ezptsm3npn54qx9vvpah4nymre59ykr9967vj9 slug1 title1 body1 --chain-id bec
$ becd tx blog create-post cosmos1ezptsm3npn54qx9vvpah4nymre59ykr9967vj9 slug2 title2 body2 --chain-id bec
  • Query posts:
$ becd q blog list-post
  • Create comments for the first post (slug1)
$ becd tx blog create-comment cosmos1ezptsm3npn54qx9vvpah4nymre59ykr9967vj9 slug1 body1-1 --chain-id bec 
$ becd tx blog create-comment cosmos1ezptsm3npn54qx9vvpah4nymre59ykr9967vj9 slug1 body1-2 --chain-id bec 
$ becd tx blog create-comment cosmos1ezptsm3npn54qx9vvpah4nymre59ykr9967vj9 slug1 body1-3 --chain-id bec 
$ becd tx blog create-comment cosmos1ezptsm3npn54qx9vvpah4nymre59ykr9967vj9 slug1 body1-4 --chain-id bec 
  • Query the comments
$ becd q blog list-comment slug1
  • Create comments for the second post (slug2), the last one was duplicated from the last
$ becd tx blog create-comment cosmos1ezptsm3npn54qx9vvpah4nymre59ykr9967vj9 slug2 body2-1 --chain-id bec 
$ becd tx blog create-comment cosmos1ezptsm3npn54qx9vvpah4nymre59ykr9967vj9 slug2 body2-2 --chain-id bec 
$ becd tx blog create-comment cosmos1ezptsm3npn54qx9vvpah4nymre59ykr9967vj9 slug2 body2-2 --chain-id bec 
  • Query the comments. You should see only two comments
$ becd q blog list-comment slug2
  • Try to create a comment for a invalid post slug
$ becd tx blog create-comment cosmos1ezptsm3npn54qx9vvpah4nymre59ykr9967vj9 invalidSlug bodyIn --chain-id bec 
  • The post should not exist
$ becd q blog list-comment invalidSlug

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant