npm install
npm run dev
A mongodb instance must be running on port 27017. Use docker-compose.yml that lives on the root.
Fetches the likes for the given topic, and a flag that tells if the user has liked the topic.
GET localhost:3001/ufc-257?user=johnnylawrence
{
likes: 10,
liked: true
}
This is the equivalent of a Like action. The user will be added to a users list, on the topics collection. It is a void operation, as the UI can handle the state.
POST localhost:3001/ufc-257?user=johnnylawrence
//void
This is the equivalent of a dislike action. The user will be removed from the users list on the topics collection. It is a void too, like the POST above.
DELETE localhost:3001/ufc-257?user=johnnylawrence
//void
The persistance layer is simple.
It has one collection, called userlikes
. This collection has two fields:
- topic: string
- users: string[]
A like action will work by querying the database for the topic and adding the user to the users array. A dislike action will work by querying the database for the topic and removing the user from the array.
The buildQuery method builds the query, using an aggregate to fetch the like count and the liked flag, based on a user and a topic.