This challenge is about creating a RESTful API to control a daily diet. Here are the application's use cases:
[X] Create a user
[X] Idenfify the user when making a request
[X] Create a meal related to a user with the following informations:
[X] Name
[X] Description
[X] Date and time
[X] Let the user select if this meal is on a diet or not
[X] Update one or more fields of a meal
[X] Delete a meal
[X] List all meals of a user
[X] List a single meal
[X] Get metrics of a user by returning the following:
[X] Amount of meals
[X] Amount of meals on a diet
[X] Amount of meals off a diet
[X] Best day on a diet
[X] The user can only view, edit and delete meals which he created.
Run the following command to start the project:
npm run dev
Now, with the server running locally using the port 3333, we are ready to make some requests.
- Create a user
- Method → POST
- Endpoint → http://localhost:3333/users
- Body request must contain both name and email parameters. The avatar parameter is optional.
- Create a meal
- Method → POST
- Endpoint → http://localhost:3333/meals
- Body request must contain name, description, is_diet, and date parameters.
- Get meal by id
- Method → GET
- Endpoint → http://localhost:3333/meals/:id
- Get all meals
- Method → GET
- Endpoint → http://localhost:3333/meals
- Get meals' metrics
- Method → GET
- Endpoint → http://localhost:3333/meals/metrics
- Update a meal
- Method → PUT
- Endpoint → http://localhost:3333/meals/:id
- Body request must contain at least one of the following parameters name, description, is_diet, and date.
- Delete a meal
- Method → DELETE
- Endpoint → http://localhost:3333/meals/:id
Run the following command to run the tests:
npm test