A REST API developed with Spring Boot for managing customers and their contacts, created as a technical challenge solution for Nubank.
- Java 17
- Spring Boot 3.5.4
- Spring Data JPA
- PostgreSQL
- Maven
- Lombok
- MapStruct
- Bean Validation
- SpringDoc OpenAPI (Swagger)
- ✅ Create customer
- ✅ List all customers
- ✅ Update customer
- ✅ Delete customer
- ✅ List contacts for a specific customer
- ✅ Create contact
- ✅ List all contacts
- ✅ Get contact by ID
- ✅ Update contact
- ✅ Delete contact
customers
├── id (BIGINT, PRIMARY KEY)
├── name (VARCHAR, NOT NULL)contacts
├── id (BIGINT, PRIMARY KEY)
├── telephone (VARCHAR, NOT NULL)
├── email (VARCHAR, NOT NULL)
├── customer_id (BIGINT, FOREIGN KEY)Relationship: A customer can have multiple contacts (One-to-Many)
- Java 17+
- PostgreSQL
- Maven 3.6+
git clone https://github.com/Mirian97/costumer-and-contact-api.git
cd costumer-and-contact-apiCreate a PostgreSQL database named nubank_db:
CREATE DATABASE nubank_db;Edit the application.properties file if needed:
spring.datasource.url=jdbc:postgresql://localhost:5432/nubank_db
spring.datasource.username=postgres
spring.datasource.password=pass1234mvn spring-boot:runThe application will be available at: http://localhost:8080
Access the interactive documentation at: http://localhost:8080/swagger-ui.html
| Method | Endpoint | Description |
|---|---|---|
| GET | /customers |
List all customers |
| POST | /customers |
Create a new customer |
| PUT | /customers/{customerId} |
Update a customer |
| DELETE | /customers/{customerId} |
Delete a customer |
| GET | /customers/{customerId}/contacts |
List customer's contacts |
| Method | Endpoint | Description |
|---|---|---|
| GET | /contacts |
List all contacts |
| GET | /contacts/{contactId} |
Get contact by ID |
| POST | /contacts |
Create a new contact |
| PUT | /contacts/{contactId} |
Update a contact |
| DELETE | /contacts/{contactId} |
Delete a contact |
- Customer name: Required
- Contact telephone: Required
- Contact email: Required
- Customer ID (for contacts): Required
- Automatic validation with Bean Validation
- Global exception handling with
@RestControllerAdvice - Automatic documentation with OpenAPI 3
- Object-relational mapping with JPA/Hibernate
- Cascade relationships for CRUD operations
- DTOs for layer separation
The application uses Hibernate DDL auto-update mode, so tables will be created automatically on first run. The schema includes:
- customers table with auto-generated ID and name field
- contacts table with auto-generated ID, telephone, email, and foreign key to customer
- One-to-Many relationship between customers and contacts with cascade operations
- Ensure PostgreSQL is running on your machine
- Create the database
nubank_db - Update database credentials in
application.propertiesif necessary - Run
mvn spring-boot:run - Access the Swagger documentation at
http://localhost:8080/swagger-ui.html - Start making API calls!
This project was developed as part of a technical challenge.