ignite / cli

Ignite is a CLI tool and hub designed for constructing Proof of Stake Blockchains rooted in Cosmos-SDK
https://ignite.com
Other
1.26k stars 549 forks source link

scaffold: propose `list` as a field type #1775

Open lumtis opened 3 years ago

lumtis commented 3 years ago

Adding the field type name list(<typename>) (or other format), that would allow to scaffold a nested list inside a type

starport scaffold type comment content
starport scaffold list post title content comment:list(Comment)

With indexed-list https://github.com/tendermint/starport/pull/1733 the necessary structures can be scaffolded for nested list

starport scaffold list post title content
starport scaffold indexed-list comment content --index postId:uint

However, the relation logic between comment and post must still be manually defined by the user. While list as a field type would allow us to scaffold the useful method and checks (checking that the post exist for each operation)

So starport scaffold list post title content comment:list(Comment) would additionally scaffold in keeper:

// Check that post exists, automatically set the id for comment and store it indexed by the post
func (Keeper) appendPostComment(sdk.Context, Post, Comment)

// Retrieve the comment of a post form a comment ID
func (Keeper) getPostComment(sdk.Context, Post, uint64) Comment

// Retrieve all comments of a post
func (Keeper) getAllPostComment(sdk.Context, Post) []Comment

And CLI commands:

show-post-comment [post-id] [comment-id]
list-post-comment [post-id]
fadeev commented 3 years ago

Shouldn't this:

starport scaffold type comment content
starport scaffold list post title content comment:list(Comment)

Be:

starport scaffold list comment content
starport scaffold list post title content comment:comment

Or is the problem that in scaffold list post... we can't deduce that a comment has been scaffolded as a list?