Skip to content

Mirian97/costumer-and-contact-api

Repository files navigation

Customer and Contact Management API

A REST API developed with Spring Boot for managing customers and their contacts, created as a technical challenge solution for Nubank.

🚀 Technologies Used

  • Java 17
  • Spring Boot 3.5.4
  • Spring Data JPA
  • PostgreSQL
  • Maven
  • Lombok
  • MapStruct
  • Bean Validation
  • SpringDoc OpenAPI (Swagger)

📋 Features

Customers

  • ✅ Create customer
  • ✅ List all customers
  • ✅ Update customer
  • ✅ Delete customer
  • ✅ List contacts for a specific customer

Contacts

  • ✅ Create contact
  • ✅ List all contacts
  • ✅ Get contact by ID
  • ✅ Update contact
  • ✅ Delete contact

🗄️ Data Model

Customer

customers
├── id (BIGINT, PRIMARY KEY)
├── name (VARCHAR, NOT NULL)

Contact

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)

🔧 Setup and Installation

Prerequisites

  • Java 17+
  • PostgreSQL
  • Maven 3.6+

1. Clone the repository

git clone https://github.com/Mirian97/costumer-and-contact-api.git
cd costumer-and-contact-api

2. Setup the database

Create a PostgreSQL database named nubank_db:

CREATE DATABASE nubank_db;

3. Configure credentials

Edit the application.properties file if needed:

spring.datasource.url=jdbc:postgresql://localhost:5432/nubank_db
spring.datasource.username=postgres
spring.datasource.password=pass1234

4. Run the application

mvn spring-boot:run

The application will be available at: http://localhost:8080

📖 API Documentation

Swagger UI

Access the interactive documentation at: http://localhost:8080/swagger-ui.html

Endpoints

Customers

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

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

✅ Validations

  • Customer name: Required
  • Contact telephone: Required
  • Contact email: Required
  • Customer ID (for contacts): Required

🛠️ Technical Features

  • 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

📊 Database Schema

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

🚀 Getting Started

  1. Ensure PostgreSQL is running on your machine
  2. Create the database nubank_db
  3. Update database credentials in application.properties if necessary
  4. Run mvn spring-boot:run
  5. Access the Swagger documentation at http://localhost:8080/swagger-ui.html
  6. Start making API calls!

📄 License

This project was developed as part of a technical challenge.

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published