Project: Customer Management System API
Objective: Implement a RESTful API for a Customer Management System using Java and Spring Boot. The API should allow users to perform CRUD (Create, Read, Update, Delete) operations on customers.
Requirements:
-
Initialize a new Spring Boot project using Spring Initializr. Choose the following dependencies: Web, JPA, H2, Lombok, and Spring Data REST.
-
Structure your project with the following packages:
model
: Contains domain model classes (Customer
)repository
: Contains repository interfaces extendingJpaRepository
service
: Contains service classes to encapsulate business logiccontroller
: Contains REST API controllersexception
: Contains custom exception classesdto
: Contains data transfer objects (DTOs) used in the API
-
Implement the domain model:
Customer
class: Fields should includeid
,firstName
,lastName
,email
,phoneNumber
, andaddress
-
Implement the repositories:
CustomerRepository
: ExtendsJpaRepository<Customer, Long>
-
Implement the services:
CustomerService
: Contains methods for creating, updating, deleting, and retrieving customers. Use Spring's Dependency Injection to inject theCustomerRepository
into the service.
-
Implement the REST API controllers:
CustomerController
: Handles HTTP requests for CRUD operations on customers. Again, use Dependency Injection to inject theCustomerService
into the controller.
-
Implement DTOs for the API:
CustomerDTO
: Contains fields forid
,firstName
,lastName
,email
,phoneNumber
, andaddress
. Use Java's built-in serialization mechanism to ensure that this object can be easily converted to JSON for use in the API.
-
Implement exception handling:
- Create custom exceptions (
ResourceNotFoundException
,BadRequestException
) - Implement a global exception handler with
@ControllerAdvice
to handle exceptions and return appropriate HTTP response status codes
- Create custom exceptions (
-
Configure an H2 in-memory database for the application.
-
Implement logging using SLF4J. All significant events should be logged (at least at INFO level), including successful operations and errors. Logs should include relevant information that would help debug issues, but be careful not to log sensitive information like passwords.
-
Write unit tests for the service classes using JUnit and Mockito.
-
(Optional) Implement API documentation using Swagger or OpenAPI.
Deliverables:
- A fully functional Spring Boot project, including source code and tests
- A README file with instructions on how to build and run the project, as well as an explanation of any design decisions you made
When you submit your project, please include all necessary files in a single archive (e.g., ZIP or TAR) and provide clear instructions for building and running your application. Good luck!