I am currently writing a blog PoC on EOS. I would like the ability to delete a post. Now deleting by the ID alone is simple, I have it implemented as follows:
whisper::post_index posts(_code, _code.value);
//Find the post with the key
auto itr = posts.find(key);
if (itr != posts.end())
{
.....
}
Now obviously anyone can then just pass on an ID and delete a post, so I would like to ensure that only the owner of the post can delete their post.
My posts table does store the owner of the post, it is as follows:
struct [[ eosio::table, eosio::contract("whisper") ]] posts
{
uint64_t key; //Primary key (ID)
name account; //Account that made the post
std::string headerImage; //Header image of the post
std::string title; //Title of the post
std::string excerpt; //Excerpt of the post
std::string content; //Content of the post
uint64_t primary_key() const { return key; }
};
Is there a way to use .find
on the table to search for both the primary key and the owner of the post? If not - how would you suggest on ensuring that only the owner can delete the post?+