Skip to content

FadyAlfred/retail-store

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Retail Store Discount API

Introduction

Retail Store Discount API is a simple project that is calculating discounts for different types of users, following specific Discount rules:

  • User of type "Employee" have 30% discount on the bill
  • User of type "Affiliate" have 10% discount on the bill
  • User of type "Loyalty" (or simple user), who is registered for over 2 years, is eligible for 5% discount on the bill
  • If the order contains groceries, no percentage discount is available.
  • User, who is eligible to several discounts, can take only one (with biggest percent).
  • There is another type of discount which is based on amount, not on the user role, as follows: for every 100 on the bill, there will be 5 discount, e.g. bill 990, 45 is the discount

Technologies

Retail Store Discount uses a number of open source projects to work properly:

  • Java - is a class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible.
  • Maven - is a software project management and comprehension tool.
  • Spring boot - makes it easy to create stand-alone, production-grade Spring based Applications.
  • Restful APIs - is architectural style for distributed hypermedia systems.
  • Hibernate JPA - is a framework for mapping an object-oriented domain model to a relational database.
  • Postgresql - is a powerful, open source object-relational database system.
  • Docker - is a set of platform as a service (PaaS) products that use OS-level virtualization.
  • Docker Compose - is a tool for running multi-container applications on Docker.
  • Mockito - is an open source testing framework for Java.
  • SonarQube - Catch bugs and vulnerabilities in your app, with thousands of automated Static Code Analysis rules.

And of course Retail Store Discount itself is open source with a public repository on GitHub.

Install and run

$ Clone the repository
$ Go into the project folder and exec docker-compose up --build
$ The app should be up and running on localhost:8080
$ SonarQube should be up and running on localhost:9000

Test Cases

$ Clone the repository
$ Go into the project folder and exec docker-compose up --build -d
$ To run the test cases execute docker exec -it web-app mvn test

SonarQube and Code coverage

$ Clone the repository
$ Go into the project folder and exec docker-compose up --build -d
$ Execute docker exec -it web-app mvn clean install
$ Execute docker exec -it web-app mvn sonar:sonar
$ The project will be listed on http://localhost:9000/projects

Demo Data

Currently we do not have authentication system, So you should provide one of the users ids below

5906873d-3507-4995-afbe-b731bd9121d1, Fady, Employee
17b034e8-d9d7-4b0e-826d-c5fa756110bb, John, Affiliate
d54f9b8a-4463-4859-8487-3e1aa836f62b, Maria, Loyalty (user for more than 2 years)
cceb42a0-9a27-47f8-bf4d-6c2362a56e6b, Remoon, New user

Sample request flow

  • Calculate discount for the logged in user
Request
GET 
'http://127.0.0.1:8080/bill/payable' 
--header 'Authorization: cceb42a0-9a27-47f8-bf4d-6c2362a56e6b'
--header 'Content-Type: application/json' 
'{
    "items": [
        {"productId": "698047e1-3f95-49bc-bdfa-1611276c12ab", "quantity": 2},
        {"productId": "aa66ff2f-acef-4bcc-ae9a-5a9a592dabf9", "quantity": 1}
    ]
}'
Response: success
{
    "amount": 127
}
Response: fail
{
    "errors": [
        {
            "error": "InvalidBill",
            "error_description": "invalid items"
        }
    ]
}

UML Class Diagram

Todos

  • Replace current Auth system with openId connect

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published