- Simple RulesEngine
com.example.myntcostapi.engine.RulesEngine
implementation:- adding rules by creating java class which extends Rule
com.example.myntcostapi.interfaces.Rule
interface, and add it on Beanscom.example.myntcostapi.configuration.Beans
, take note that the order is defined when adding it. - removing rules by just remove it on Beans and you can also remove the java file
- priority update on rules by just adjusting the order how rule will be added
- update of condition and other stuff on rules can be achieved by updating in the specific rule implementation
- (Future plans) - rules can be external or maybe some portion of it.
- adding rules by creating java class which extends Rule
- ControllerAdvice - this will handle all the exceptions and create error responses
- Validation - validations on the request body
- Dependency Injection - uses spring's dependency injection for auto initialization and dependency injection of classes
API URL
POST http://localhost:8080/api/v1/deliveryCost
{
"weight": 49,
"height": 10,
"width": 10,
"length": 10,
"voucherCode": "MYNT"
}
Sample Responses:
- Success with no voucher code
{
"weight": 49.0,
"volume": 1000.0,
"cost": 980.0
}
- Success with voucher code
{
"weight": 49.0,
"volume": 1000.0,
"cost": 967.75,
"originalCost": 980.0,
"discount": 12.25,
"discounted": true
}
- Validation errors on fields
{
"code": "VALIDATION_EXCEPTION",
"message": "[width must not be null; length must not be null; weight must not be null; height must not be null]"
}
- If weight field exceed 50
{
"code": "RUNTIME_EXCEPTION",
"message": "Rejected - Parcel exceed 50kgs"
}
- Error on fetching from voucher client
{
"code": "RUNTIME_EXCEPTION",
"message": "Error on getting voucher details: I/O error on GET request for \"https://mynt-exam.mocklab.ioa/voucher/MYNT\": mynt-exam.mocklab.ioa; nested exception is java.net.UnknownHostException: mynt-exam.mocklab.ioa"
}
Haven't added it since it would take more time, but if you let me I am capable of doing unit testing in Mockito and Powermock