I found Strapi, and I love it!
I have three questions to better understand how I can handle two different cases, and I apologize if my questions are noobies.
I’m building up a simple site similar to a WordPress site. However, I got stuck in implementing a few features, and I would like to know if I’m doing something wrong or simply the approach I’m taking is wrong.
The website has one collection type called “Story”. Looking at how to implement comments, I found the comments plugin that works great, however, this is where I get stuck.
When I use the API to get the comments for a specific post, for example: /strapi/api/comments/api::story.story:50/flat?pagination[page]=1&pagination[pageSize]=5, I would expect the metadata to be like :
However, the metadata I get is the following:
This is the first issue. I would need to know the total and the page count as well, so, on the website I could implement a load more button to load additional comments. Am I doing something wrong with the API call?
The second question I have is if it’s possible to get the number of the total comment in the story itself. So, if for example I run this:
I get all the stories for the specific author. Is there a way, to count how many comments there are specified for each post (story)? So, in my front end, I can display the total comment number before opening the story, or I could sort the story based on the number of comments I guess?
Do I need to edit the controller? If so, I’m not really sure how I should start. I would guess, that in the controller, I need to make a call to count all the comments relative to each story and then return the count for each story.
The last question is to know the best way to implement the like/reaction system without killing the performance. So, let’s say I make a like button that the user can click on the story to like, and click again to unlike it. If I make a relation field to the story content, called “like,” as “Story has many Users,” I could populate this field with all the users who clicked the like button. However, I’m not sure about this approach, because if 10,000 users like the same story, I think I might encounter an issue with performance. I also thought to add a field to the user collection called “post liked,” where I store all the post IDs that the user liked, and another field in the story type to just keep the count of how many times the user liked the story. So, when the user clicks on the like button, first we add the post ID on the user field, and if the response status is 200, then we increment the count in the story number by one. However, with this last approach, I wouldn’t be able to show the usernames who liked the post, which might be a problem. Also, if I do this approach, should I handle the second call on the client? Or should I implement it on the server side? If so, how do you suggest doing it?
Sorry, but I’m really new to Strapi, and I want to make sure I follow the best practices. Thanks :))