- Docker
docker build --tag mcabezas-api:0.1.0 .
docker run --publish 9092:9092 --detach mcabezas-api:0.1.0
- Make
- Golang 13+
make
./api
This project has been built using clean architecture
.
The database implementation is an in memory database. However, it can be easily replaced by another one once the database technology has been chosen.
-
There is a huge separation of concerns between the business (use cases) and infrastructure (databases / cache / etc). Use cases are the heart of the application because all the business logic lives there.
-
Rest API is only a to expose the business over an HTTP protocol communication.
-
It's very easy to implement other communication channels like Protocol Buffer or GraphQL without changing anything in the business logic.
-
Infrastructure is only an implementation of third party components.
-
Allow us to easily expand the api over microservices or contract us into a monolithic with no business changes.
The core functionality of this challenge belongs to the discount calculation.
It was decided by me to have a very flexible discount modeling using the model.Discount
interface.
In this exercise I have created a model.ComboDiscount
implementation of model.Discount
.
Combo discount configuration comes from the infrastructure.ComboDiscountRepository
providing an extra quote of flexibility.
The application has two repositories
(Path cmd/web/rest/main.go:29)
WatchCatalogue comes preloaded with the following data
WATCH ID | Name | Unit Price |
---|---|---|
001 | Rolex | 100 |
002 | Michael Kors | 80 |
003 | Swatch | 50 |
004 | Casio | 30 |
( Path cmd/web/rest/main.go:21 )
ComboDiscountRepository comes preloaded with the following data
WATCH ID | Unit | Fixed Price |
---|---|---|
001 | 3 | 200 |
002 | 2 | 120 |