started with boilerplate and BasketEndpoint
This commit is contained in:
parent
d1e48f8c52
commit
7a451097f2
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"nuxt.isNuxtApp": false
|
||||||
|
}
|
||||||
55
README.md
55
README.md
|
|
@ -1,2 +1,57 @@
|
||||||
# Hiring-Task-Shy-Badger
|
# Hiring-Task-Shy-Badger
|
||||||
|
|
||||||
|
# Shopping-Basket
|
||||||
|
|
||||||
|
Implement a virtual shopping-basket in the programming language of your choice (Java, Ruby, Elixir, JavaScript, ...). It should be possible to add items to the shopping-basket. Implementing a graphical user interface (GUI) is not necessary - it's enough to show the behavior using test cases.
|
||||||
|
The following `API` shows the desired interface/behavior in pseudo-code. The final implementation can deviate from that.
|
||||||
|
|
||||||
|
## API
|
||||||
|
A warehouse has a set of products with fixed prices
|
||||||
|
|
||||||
|
```
|
||||||
|
INVENTORY = [["A0001", 12.99], ["A0002", 3.99], ...]
|
||||||
|
```
|
||||||
|
|
||||||
|
Each user has a shopping-basket
|
||||||
|
|
||||||
|
```
|
||||||
|
basket = Basket.new
|
||||||
|
```
|
||||||
|
|
||||||
|
It is possible to add items to the shopping-basket
|
||||||
|
|
||||||
|
```
|
||||||
|
basket.scan("A0001")
|
||||||
|
```
|
||||||
|
|
||||||
|
A user can check the total price of all items in his shopping basket at any given time
|
||||||
|
|
||||||
|
```
|
||||||
|
basket.total
|
||||||
|
=> 12.99 Euro
|
||||||
|
```
|
||||||
|
|
||||||
|
## Task
|
||||||
|
Additionally, certain sales deals shall be supported:
|
||||||
|
|
||||||
|
* Buy 1 get 1 free for a certain article
|
||||||
|
|
||||||
|
```
|
||||||
|
# Buy1Get1Free A0002
|
||||||
|
basket.scan("A0002")
|
||||||
|
basket.scan("A0001")
|
||||||
|
basket.scan("A0002")
|
||||||
|
basket.total
|
||||||
|
=> 16.98
|
||||||
|
```
|
||||||
|
|
||||||
|
* 10% off a given article
|
||||||
|
|
||||||
|
```
|
||||||
|
# 10Percent A0001
|
||||||
|
basket.scan("A0002")
|
||||||
|
basket.scan("A0001")
|
||||||
|
basket.scan("A0002")
|
||||||
|
basket.total
|
||||||
|
=> 19.67
|
||||||
|
```
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
# left empty so the user has to import all submodules explicitly,
|
||||||
|
# this ensures clear namespace separation
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
from flask_restful import Resource, reqparse
|
||||||
|
import flask
|
||||||
|
|
||||||
|
class Basket(Resource):
|
||||||
|
def get(self, id = None):
|
||||||
|
if id is None:
|
||||||
|
flask.make_response(flask.jsonify({'error': "No ID supplied"}), 401)
|
||||||
|
return flask.Response({"data": {}}, mimetype='image/png')
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
from flask import Flask, request, g, render_template, redirect
|
||||||
|
from flask_restful import Resource, reqparse
|
||||||
|
from flask_restful_swagger_3 import Api
|
||||||
|
from json import dumps
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import ShyBadger.endpoints.BasketEndpoint as BasketEndpoint
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
api = Api(app)
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
api.add_resource(BasketEndpoint.Basket,'/api/v1/recipe/<string:id>/image')
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def index():
|
||||||
|
"""in lieu of a UI redirect to the API doc"""
|
||||||
|
app.logger.info(f"request from {request.remote_addr}")
|
||||||
|
return redirect("/api/doc/swagger.json", code=302)
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
from ShyBadger.main import app
|
||||||
|
|
||||||
|
# disabled threading for easier session handleing in this demo project
|
||||||
|
# if threaded was True, as session store would be needed
|
||||||
|
app.run(host="0.0.0.0", port='80', debug=False, threaded=False)
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
flask
|
||||||
|
flask_restful
|
||||||
|
requests
|
||||||
|
flask-restful-swagger-3
|
||||||
Loading…
Reference in New Issue