Coder Social home page Coder Social logo

services-kotlin-spring-boot-test's Introduction

Objective

Create RESTful endpoint(s) to calculate, store, and retrieve customer rewards. No need to have a database, we'll store everything in memory.

Background

  • You will be using Spring Boot. We will be implementing a rewards service. Here is the list of rewards. You'll find the same list in the current code base
    [
        { "tier": "A", "rewardName": "5% off purchase", "points": 100 },
        { "tier": "B", "rewardName": "10% off purchase", "points": 200 },
        { "tier": "C", "rewardName": "15% off purchase", "points": 300 },
        { "tier": "D", "rewardName": "20% off purchase", "points": 400 },
        { "tier": "E", "rewardName": "25% off purchase", "points": 500 },
        { "tier": "F", "rewardName": "30% off purchase", "points": 600 },
        { "tier": "G", "rewardName": "35% off purchase", "points": 700 },
        { "tier": "H", "rewardName": "40% off purchase", "points": 800 },
        { "tier": "I", "rewardName": "45% off purchase", "points": 900 },
        { "tier": "J", "rewardName": "50% off purchase", "points": 1000 }
    ]
    

Implementation Instructions

  • Fork this repo.
  • Use incremental commits on a story branch to show how you arrived at your solutions.
  • Push your story branch to your fork.
  • Issue a pull request against the master branch of this repo.
  • Design and implement the following endpoints.
    • Endpoint 1:
      • Accept a customer's order data: email adress (ex. "[email protected]") and order total (ex. 100.80).
      • Calculate and store the following customer rewards data. For each dollar a customer spends, the customer will earn 1 reward point. For example, a customer whose order total is $100.80 earns 100 points and belongs to Rewards Tier A. Note: a customer can only belong to one rewards tier. For example, a customer with 205 reward points belongs to Rewards Tier B and cannot use the reward from Tier A. Once a customer has reached the top rewards tier, there are no additional rewards the customer can earn.
        • Email Address: the customer's email address (ex. "[email protected]")
        • Reward Points: the customer's rewards points (ex. 100)
        • Rewards Tier: the rewards tier the customer has reached (ex. "A")
        • Reward Tier Name: the name of the rewards tier (ex. "5% off purchase")
        • Next Rewards Tier: the next rewards tier the customer can reach (ex. "B")
        • Next Rewards Tier Name: the name of next rewards tier (ex. "10% off purchase")
        • Next Rewards Tier Progress: the percentage the customer is away from reaching the next rewards tier (ex. 0.5)
    • Endpoint 2: Accept a customer's email address, and return the customer's rewards data that was stored in Endpoint 1.
    • Endpoint 3: Return the same rewards data as Endpoint 2 but for all customers.
  • For bonus points, add error handling and unit tests.

Given:

Currently the project looks like the tree below.

  • All of the main logic should go into the RewardsService
  • The RewardsController the entrypoint of the web application. That is where you'll find the endpoints, e.g. /purchase
  • Some of the endpoints have been stubbed out for convenience.

How to run:

  • Import the project into Intellij
  • File
  • New Project From Existing Sources
  • Choose the directory
  • Press Ok
  • Right click the RewardsApplication.kt and click Run RewardsApplication

Stubbed methods

Example cURL request:

/purchase

curl -X POST \
  http://localhost:9005/purchase \
  -H 'Content-Type: application/json' \
  -d '{
	"email": "[email protected]",
	"purchaseTotal": 40
}
'

Folder structure:

src
├── main
│   ├── kotlin
│   │   └── com
│   │       └── urbn
│   │           └── rewards
│   │               ├── RewardsApplication.kt
│   │               ├── controller
│   │               │   └── RewardsController.kt
│   │               ├── models
│   │               │   ├── Customer.kt
│   │               │   ├── OrderRequest.kt
│   │               │   └── Rewards.kt
│   │               └── service
│   │                   └── OrderService.kt
│   └── resources
│       ├── Rewards.kt
│       ├── application.properties
│  

services-kotlin-spring-boot-test's People

Contributors

renjuju avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.