This API enables users to manage events, points, registrations, favorites, and user accounts. It features authentication for user registration and login, as well as protected routes for user management, allowing for secure and efficient management of resources.
- Introduction
- Features
- Technologies Used
- Project Structure
- Data Modeling
- Project Setup
- Endpoints
- Developers
- License
This API is designed to facilitate the management of events and resources related to waste collection and community engagement. Users can register, log in, create and manage events, as well as mark their favorite events and points.
- User Management: Register, login, and manage user accounts with role-based access (admin or regular user).
- Event Management: Create, read, update, and delete events.
- Favorites Management: Add and manage favorite events and points.
- Point Management: Create and manage waste collection points.
- JWT Authentication: Secure endpoints with JSON Web Tokens for protected access.
- Error Handling: Standardized error responses for better debugging and user experience.
- Node.js: JavaScript runtime for server-side programming.
- Express: Web framework for Node.js to build APIs.
- Sequelize: ORM for PostgreSQL, simplifying database operations.
- JSON Web Tokens (JWT): For secure token-based authentication.
- Bcrypt: For hashing passwords securely.
- Dotenv: For managing environment variables.
- PostgreSQL: Relational database for data storage.
├── src
│ ├── config # Configuration files
│ ├── controllers # API controllers
│ ├── middlewares # Middleware functions
│ ├── migrations # Sequelize migrations
│ ├── models # Sequelize models
│ ├── routes # API routes
│ └── server.js # Entry point for the application
├── .env # Environment variables
├── .gitignore # Git ignore file
├── package.json # Project metadata and dependencies
└── README.md # Documentation
Link for ER Diagram
- Clone this repository:
git clone https://github.com/ste-coding/backend-projeto-final-M5.git
cd backend-projeto-final-M5
- Install the dependencies:
npm install
-
Create a .env file in the root of the project and define the environment variables as shown in
.env_EXAMPLE
: -
Run database migrations (assuming you have Sequelize CLI installed):
npm run migrate
- Start the server:
npm run dev
Base URL
http://localhost:3000/api
- Endpoint:
/auth/register
- Method:
POST
- Request Body:
{ "name": "User Name", "email": "user@example.com", "password": "password123", "cpf": "12345678901", "phone": "1234567890", "user_type": "regular" // or "admin" }
- Endpoint:
/auth/login
- Method:
POST
- Request Body:
{ "email": "user@example.com", "password": "password123" }
All routes that require authentication must include a JWT token in the Authorization
header as follows:
Authorization: Bearer <token>
- Endpoint:
/auth/users
- Method:
GET
- Endpoint:
/auth/users/:id
- Method:
GET
- Endpoint:
/auth/users/:id
- Method:
PUT
- Request Body:
{ "name": "Updated Name", "email": "updated@example.com", "phone": "0987654321", "cpf": "10987654321" }
- Endpoint:
/auth/users/:id
- Method:
DELETE
- Endpoint:
/events
- Method:
POST
- Request Body:
{ "name": "Event Name", "description": "Event Description", "date": "2024-10-10T10:00:00Z", "location": "Event Location", "event_type": "mutirão", "status": "pending", "created_by": "user_id_here" }
- Endpoint:
/events
- Method:
GET
- Endpoint:
/events/:id
- Method:
GET
- Endpoint:
/events/:id
- Method:
PUT
- Request Body:
{ "name": "Updated Event Name", "description": "Updated Description" // other fields as necessary }
- Endpoint:
/events/:id
- Method:
DELETE
- Endpoint:
/favorites
- Method:
POST
- Request Body:
{ "user_id": "user_id_here", "point_id": "point_id_here", // can be null "event_id": "event_id_here" // can be null }
- Endpoint:
/favorites
- Method:
GET
- Endpoint:
/favorites/:id
- Method:
GET
- Endpoint:
/favorites/:id
- Method:
PUT
- Request Body:
{ "user_id": "updated_user_id" // other fields as necessary }
- Endpoint:
/favorites/:id
- Method:
DELETE
- Endpoint:
/points
- Method:
POST
- Request Body:
{ "name": "Point Name", "location": "Point Location", "waste_type": "plastic", "operating_hours": "9 AM - 5 PM", "status": "approved", "created_by": "user_id_here" }
- Endpoint:
/points
- Method:
GET
- Endpoint:
/points/:id
- Method:
GET
- Endpoint:
/points/:id
- Method:
PUT
- Request Body:
{ "name": "Updated Point Name" // other fields as necessary }
- Endpoint:
/points/:id
- Method:
DELETE
Stéphanie |
Raissa |
Matheus |
This project is licensed by: GNU GPL-3.0