Evolvion Sales Service is a microservice developed as part of the Evolvion Business Management System. It manages sales, orders, and customer requirements, allowing businesses to track transactions, order statuses, and client preferences. This service integrates with other components like the Accounts Service to streamline operations.
- Sales Management: Create, update, and track sales with various payment methods and statuses.
- Order Tracking: Manage and update orders with multiple statuses and dynamic pricing.
- Customer Requirement Handling: Capture and manage customer preferences, types, and priorities.
- Enum-Based Categories: Flexible enums for payment methods, delivery options, and more.
- Data Validation: Ensures data integrity for all operations.
- Custom Exception Handling: Robust error handling with specific exceptions for sales, orders, and customer requirements.
- RESTful API: Easy integration with clear, well-structured endpoints.
Evolvion_Sales_Service
├── controller
│ ├── SaleController
│ ├── OrderController
│ └── CustomerRequirementController
├── controller_advise
│ ├── Sale_Exceptions
│ ├── Order_Exceptions
│ ├── CustomerRequirement_Exceptions
│ ├── ErrorResponse
│ └── GlobalExceptionHandler
├── model
│ ├── core
│ └── enums
├── dto
│ ├── SaleDTO
│ ├── OrderDTO
│ └── CustomerRequirementDTO
├── mappers
│ ├── SaleMapper
│ ├── OrderMapper
│ └── CustomerRequirementMapper
├── repository
│ ├── SaleRepository
│ ├── OrderRepository
│ └── CustomerRequirementRepository
└── service
├── implementation
│ ├── SaleServiceImpl
│ ├── OrderServiceImpl
│ └── CustomerRequirementServiceImpl
└── interface
├── SaleService
├── OrderService
└── CustomerRequirementService
- Purpose: Manages sales operations, including creation, updates, retrieval, and deletion of sales.
- Core Functionality:
- Create a new sale.
- Update an existing sale.
- Fetch details of a specific sale.
- Retrieve a list of all sales.
- Delete a sale by ID.
- Purpose: Handles orders related to sales, such as processing orders, managing order statuses, and tracking payments.
- Core Functionality:
- Create a new order.
- Update an existing order.
- Get details of a specific order.
- Retrieve all orders.
- Delete an order by ID.
- Purpose: Manages customer-specific requirements, ensuring customer needs and priorities are addressed.
- Core Functionality:
- Create new customer requirements.
- Update existing customer requirements.
- Retrieve a specific customer requirement.
- Fetch all customer requirements.
- Delete a customer requirement by ID.
- Contains RESTful controllers responsible for handling HTTP requests and directing them to the appropriate services.
- Files:
SaleController
: Manages sale-related endpoints.OrderController
: Handles order-related API requests.CustomerRequirementController
: Manages customer requirement-related operations.
- Provides centralized exception handling for the application by using
@ControllerAdvice
. - Files:
Sale_Exceptions
: Custom exceptions for Sale operations.Order_Exceptions
: Custom exceptions for Order operations.CustomerRequirement_Exceptions
: Custom exceptions for Customer Requirement operations.ErrorResponse
: Defines the structure of error responses.GlobalExceptionHandler
: Captures and handles exceptions thrown across the application.
- Defines the core entities and enums used throughout the application.
- Files:
core
: Holds the entity models forSale
,Order
, andCustomerRequirement
.enums
: Contains enumerations for payment methods, statuses, customer priorities, etc.
- Contains Data Transfer Objects (DTOs) that are used to pass data between the controller and service layers.
- Files:
SaleDTO
: DTO for Sale data.OrderDTO
: DTO for Order data.CustomerRequirementDTO
: DTO for Customer Requirement data.
- Provides mapper classes to convert between entities and DTOs.
- Files:
SaleMapper
: Maps betweenSale
entities andSaleDTO
.OrderMapper
: Maps betweenOrder
entities andOrderDTO
.CustomerRequirementMapper
: Maps betweenCustomerRequirement
entities andCustomerRequirementDTO
.
- Contains repository interfaces for database access, extending JPA repositories.
- Files:
SaleRepository
: Repository for Sale operations.OrderRepository
: Repository for Order operations.CustomerRequirementRepository
: Repository for Customer Requirement operations.
- Defines the business logic of the application.
- Sub-packages:
- Implementation: Implements the service interfaces.
SaleServiceImpl
: Implements sale operations.OrderServiceImpl
: Implements order operations.CustomerRequirementServiceImpl
: Implements customer requirement operations.
- Interface: Defines the service interfaces.
SaleService
: Interface for sale-related methods.OrderService
: Interface for order-related methods.CustomerRequirementService
: Interface for customer requirement-related methods.
- Implementation: Implements the service interfaces.
Exception handling in the application is managed centrally using Spring's @ControllerAdvice
and custom exception classes. This ensures a clean separation of concerns, allowing controllers to focus on business logic while delegating error handling to a centralized mechanism.
- The GlobalExceptionHandler class, annotated with
@ControllerAdvice
, captures exceptions thrown from any controller and handles them uniformly. - It ensures that specific exceptions are translated into meaningful HTTP responses, such as
400 Bad Request
,404 Not Found
, or500 Internal Server Error
. - Key Methods:
- Handles common exceptions like
IllegalArgumentException
,MethodArgumentNotValidException
, etc. - Customizes responses for business-specific exceptions.
- Handles common exceptions like
Custom exceptions are defined for each domain entity (Sale, Order, CustomerRequirement) to capture specific error scenarios.
-
Sale_Exceptions:
SaleNotFoundException
: Thrown when a requested sale is not found.SaleCreationException
: Raised when the system encounters an issue during sale creation.SaleUpdateException
: Thrown when updating a sale fails.
-
Order_Exceptions:
OrderNotFoundException
: Thrown when an order does not exist.OrderCreationException
: Raised if there’s an issue during order creation.OrderUpdateException
: Thrown when updating an order fails.
-
CustomerRequirement_Exceptions:
CustomerRequirementNotFoundException
: Thrown when a customer requirement is not found.CustomerRequirementCreationException
: Raised during customer requirement creation errors.CustomerRequirementUpdateException
: Thrown when customer requirement updates fail.
- The
ErrorResponse
class is used to encapsulate details of the error response sent to the client. - Contains fields like:
timestamp
: The date and time when the error occurred.message
: A user-friendly message explaining the error.details
: Additional context or details about the error.
- The
GlobalExceptionHandler
ensures that all exceptions return a well-structuredErrorResponse
object. - This provides consistency and clarity to clients consuming the API, detailing the cause of errors with appropriate HTTP status codes (e.g., 404 for not found, 400 for bad request).
DTO validation in the application is handled using Java Bean Validation (JSR 380) annotations provided by the javax.validation
package. This ensures that incoming data is verified before reaching the service layer, helping maintain data integrity and preventing invalid input.
- @NotNull: Ensures that fields like
amount
,quantity
, andstatus
are not null. - @Size: Limits the size of fields such as
saleNumber
,orderNumber
, andcustomerName
to prevent overly large inputs. - @Min / @Max: Applies to numeric fields like
amount
andprice
to enforce valid ranges. - @PastOrPresent: Validates date fields like
createdAt
andupdatedAt
to ensure they are not set in the future.
By leveraging these annotations, the system automatically triggers validation errors when invalid data is submitted, providing feedback through standardized error responses.
The application uses SLF4J with Logback as the logging framework to capture important runtime events and errors. Logging is implemented across the services to ensure transparency in operations and to aid in debugging.
- Info Logs: Used to log significant business events, such as the creation or updating of a sale, order, or customer requirement.
- Error Logs: Captures exceptions and errors, especially in cases of service failures or invalid operations, ensuring detailed traceability.
- Debug Logs: Provides insights during development and debugging to track detailed internal operations.
- Centralized Logging: All logs are centrally managed, and log levels can be adjusted via
logback.xml
to suit different environments (development, testing, production).
This setup ensures efficient monitoring and quick resolution of issues during runtime.
We welcome contributions to the Evolvion Accounts Service project! To contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them with clear messages.
- Push your changes to your fork.
- Submit a pull request to the main repository.