initial commit
This commit is contained in:
38
order.py
Normal file
38
order.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import json
|
||||
|
||||
MILK_TYPES = ["Cream", "Half-and-half", "Whole-milk", "Part-Skim", "Skim", "Non-Dairy"]
|
||||
|
||||
SYRUP_TYPES = ["Vanilla", "Almond", "Raspberry", "Chocolate"]
|
||||
|
||||
ALCOHOL_TYPES = ["Whisky", "Rum", "Kahlua", "Aquavit"]
|
||||
|
||||
ADDITION_HEADER = "Accept-Additions"
|
||||
|
||||
|
||||
class Order(object):
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.milk = "None"
|
||||
self.syrup = "None"
|
||||
self.alcohol = "None"
|
||||
print(f"Configuring order - {name}")
|
||||
|
||||
def configure(self, header):
|
||||
additions = []
|
||||
for k, v in header.items():
|
||||
if ADDITION_HEADER in k:
|
||||
additions = v
|
||||
print(additions)
|
||||
addition_list = additions.split(';')
|
||||
for ad in addition_list:
|
||||
print(ad)
|
||||
if ad.strip() in MILK_TYPES:
|
||||
self.milk = ad
|
||||
elif ad.strip() in SYRUP_TYPES:
|
||||
self.syrup = ad
|
||||
elif ad.strip() in ALCOHOL_TYPES:
|
||||
self.alcohol = ad
|
||||
|
||||
def json_dump(self):
|
||||
return json.dumps([{'name': self.name}, {'milk': self.milk}, {'syrup': self.syrup}, {'alcohol': self.alcohol}])
|
||||
33
pots.py
Normal file
33
pots.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import logging
|
||||
import order
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Pot(object):
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
def get(self):
|
||||
return "GET REQUEST RECEIVED"
|
||||
|
||||
def when(self):
|
||||
return "WHEN REQUEST RECEIVED"
|
||||
|
||||
def brew(self, headers):
|
||||
return "BREW REQUEST RECEIVED"
|
||||
|
||||
class CoffeePot(Pot):
|
||||
|
||||
def __init__(self, name):
|
||||
super(CoffeePot, self).__init__(name)
|
||||
print("Coffee pot initialised")
|
||||
|
||||
def brew(self, headers):
|
||||
print("Brewing coffee")
|
||||
new_order = order.Order("NewOrder")
|
||||
new_order.configure(headers)
|
||||
print(new_order.json_dump())
|
||||
return "Brewing"
|
||||
|
||||
18
requirements.txt
Normal file
18
requirements.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
certifi==2025.11.12
|
||||
charset-normalizer==3.4.4
|
||||
click==8.1.8
|
||||
colorama==0.4.6
|
||||
Flask==2.2.5
|
||||
flask-sqlalchemy==3.0.5
|
||||
greenlet==3.1.1
|
||||
idna==3.10
|
||||
importlib-metadata==6.7.0
|
||||
itsdangerous==2.1.2
|
||||
jinja2==3.1.6
|
||||
MarkupSafe==2.1.5
|
||||
requests==2.31.0
|
||||
SQLAlchemy==2.0.44
|
||||
typing-extensions==4.7.1
|
||||
urllib3==2.0.7
|
||||
Werkzeug==2.2.3
|
||||
zipp==3.15.0
|
||||
25
server.py
Normal file
25
server.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from flask import Flask, request
|
||||
import pots
|
||||
|
||||
app = Flask(__name__)
|
||||
pot = pots.CoffeePot("TestPot")
|
||||
|
||||
|
||||
@app.route('/pot', methods=['GET'])
|
||||
def get():
|
||||
return pot.get()
|
||||
|
||||
|
||||
@app.route('/pot', methods=['BREW', 'POST'])
|
||||
def brew():
|
||||
return pot.brew(request.headers)
|
||||
|
||||
|
||||
@app.route('/pot', methods=['WHEN'])
|
||||
def when():
|
||||
return pot.when()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(port=8081)
|
||||
|
||||
Reference in New Issue
Block a user