This API returns a list of items that can be bought with a coupon, without exceeding its amount.
The knapsack problem is a problem in combinatorial optimization: Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most valuable items. Wikipedia
The API premise is based on the knapsack problem but with a little twist: instead of take care of the value and weight, we have to worry about the item prices and also return the selected items.
Build the artifact and docker image run:
mvn clean install
Build a runnable java artifact without creating a docker image
mvn clean package
docker run stefy421/coupon-api
The project includes:
- Java documentation into PROJECT_ROOT_PATH/javadoc.
- Swagger documentation
http://localhost:8080/swagger-ui/
- Actuator for checking health of application
http://localhost:8080/actuator/health
Body application/json
{
"item_ids":["MCO569635558",
"MCO613591599",
"MCO593323015",
"MCO596414800",
"MCO564169608",
"MCO453857398"],
"amount": 200000
}
Body application/json
{
"item_ids": [
"MCO453857398",
"MCO593323015",
"MCO613591599"
],
"total": 198700.0
}
When the coupon amount sent is not enough to buy at least one item, the API reponse with 404 - NOT FOUND