README
GPL-3.0 License
2 min read · 8 months ago
Daily Diet API
Repository- APINode.jsFastifyKnex.jsSQLiteRocketseat
Daily Diet is a challenge from @Rocketseat to implement the back-end of a meal registration application, where the user can mark what they consumed during the day and their commitment to the diet.
Functional requirements
- It must be possible to create a user;
- It must be possible to identify the user among the requests;
- It must be possible to record a meal made, with the following information:
- Type (Breakfast, lunch, dinner, snack or dessert);
- Description;
- Date and time;
- Is it within the diet or not.
- It must be possible to edit a meal, being able to change all the data above;
- It must be possible to delete a meal;
- It must be possible to list all the meals of a user;
- It must be possible to view a single meal;
- It must be possible to retrieve the metrics of a user:
- Total number of meals recorded;
- Total number of meals within the diet;
- Total number of meals outside the diet;
- Best sequence of meals within the diet;
Business rules
- The user can only view, edit and delete the meals he created;
Database
Stack
- Node.js;
- Typescript;
- Fastify;
- SQLite;
- Knex.js;
- Vitest;
- Zod;
Routes
User manipulation
GET - /users
: Lists all users;GET - /users/:id/meals
: Retrieves a user’s meals;POST - /users
: Creates a user with the data provided in the request body;
Meal manipulation
GET - /meals
: Lists all meals;GET - /meals/:id
: Retrieves a single meal;PUT - /meals/:id
: Edits a meal with the data provided in the request body;POST - /meals
: Creates a meal with the data provided in the request body;DELETE - /meals/:id
: Deletes a meal;
Selected data
GET - /users/:userId/meals/count
: Total number of meals registered by the user;GET - /users/:userId/meals/in-diet
: Total number of meals within the diet;GET - /users/:userId/meals/not-in-diet
: Total number of meals outside the diet;GET - /users/:userId/best-streak
: Best sequence of meals within the diet;