Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RaminMammadzada/b40c4e493d3d7300575952c73c8dcfa3 to your computer and use it in GitHub Desktop.
Save RaminMammadzada/b40c4e493d3d7300575952c73c8dcfa3 to your computer and use it in GitHub Desktop.
Sample Project: Customer Management System API

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:

  1. Initialize a new Spring Boot project using Spring Initializr. Choose the following dependencies: Web, JPA, H2, Lombok, and Spring Data REST.

  2. Structure your project with the following packages:

    • model: Contains domain model classes (Customer)
    • repository: Contains repository interfaces extending JpaRepository
    • service: Contains service classes to encapsulate business logic
    • controller: Contains REST API controllers
    • exception: Contains custom exception classes
    • dto: Contains data transfer objects (DTOs) used in the API
  3. Implement the domain model:

    • Customer class: Fields should include id, firstName, lastName, email, phoneNumber, and address
  4. Implement the repositories:

    • CustomerRepository: Extends JpaRepository<Customer, Long>
  5. Implement the services:

    • CustomerService: Contains methods for creating, updating, deleting, and retrieving customers. Use Spring's Dependency Injection to inject the CustomerRepository into the service.
  6. Implement the REST API controllers:

    • CustomerController: Handles HTTP requests for CRUD operations on customers. Again, use Dependency Injection to inject the CustomerService into the controller.
  7. Implement DTOs for the API:

    • CustomerDTO: Contains fields for id, firstName, lastName, email, phoneNumber, and address. Use Java's built-in serialization mechanism to ensure that this object can be easily converted to JSON for use in the API.
  8. 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
  9. Configure an H2 in-memory database for the application.

  10. 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.

  11. Write unit tests for the service classes using JUnit and Mockito.

  12. (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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment