- Computes discount
- Computes discount along with est delivery time
- Validate offers schema
Uses go way of designing services (DI) using Hexagonal architecture.
- Offer service : Offer service is responsible for applying offer discount amount when meets the expected criteria.
- Delivery Service: Delivery service responsible for computing delivery cost and applies offer discount if applicable by using
offer service
- Total delivery cost can be computed using method available on PackageDetails, so that all computation logic will be at one place (The better way could be have its own service).
π¦ services
β£ π delivery_svc
β β£ π default_svc.go
β β π delivery_svc.go
β£ π offers_svc
β β£ π default_svc.go
β β π offers_svc.go
β π shell_io_svc
β β£ π default_svc.go
β β π shell_io_svc.go
The domain models
π¦ models
β£ π offers.go
β£ π package_details.go
β£ π package_stats.go
β π vehicles.go
Write your own client
π¦ clients
β£ π base_client.go
β£ π shell_client.go
We have created a schema to validate whether give offer is valid or applicable.
type Offer struct {
Code OfferCode
Conditions []Condition
Discount float64
}
Maintains a list of offers in offers.json
file, which adheres to schema defined above. We can add any no of offers or remove existing ones from offers.json
. The modifications to offers.json
file wont require any other code changes. We can keep this offers.json
in a database for maintainability and ease of deployments.
The current implementation calculates discount when all conditions specified for the offer code are met.
Fact | Data type |
---|---|
distance | decimal or integer |
weight | decimal or integer |
Operator | effect |
---|---|
lessThan | < |
greaterThanOrEqual | < |
lessThanOrEqual | < |
Validates offers.json
schema
π¦scripts
β£ π src
β£ π package.json
β π tsconfig.json
-
Make sure to setup
-
Navigate to scripts directory
-
Install dependencies
yarn setup
-
Validate
offers.json
data (format)yarn validate
make dev
This works for osx (Mac), for other operating system, refer to this doc.
# Build
make build
# Run app
make start
100 3
pkg1 5 5 OFR001
pkg2 15 5 OFR002
pkg3 10 100 OFR003
2 70 200
pkg1 0.00 175.00
pkg2 0.00 275.00
pkg3 35.00 665.00
100 5
PKG1 50 30 OFR001
PKG2 75 125 OFR002
PKG3 175 100 OFR008
PKG4 110 60 OFR002
PKG5 155 95 NA
2 70 200
100 7
PKG1 3 30 OFR001
PKG2 2 125 OFR002
PKG3 3 100 OFR008
PKG4 4 60 OFR002
PKG5 1 95 NA
PKG6 5 95 NA
PKG7 6 95 NA
2 70 6
make test
make coverage
Install golangci-lint. Refer Local Installation for installing.
make lint
- CI/CD
- There scope for improvement interns (bigO - knapsack)