formatting

This commit is contained in:
Askill 2024-08-15 18:02:13 +02:00
parent f94c87c06f
commit 12b58e7bf1
7 changed files with 32 additions and 30 deletions

View File

@ -4,6 +4,7 @@ import uuid
from src.services import BasketService
class Basket(Resource):
basket_service = BasketService()
@ -15,7 +16,9 @@ class Basket(Resource):
def get(self):
if "session_id" not in session:
session["session_id"] = self.get_session_id()
return Response({"total": self.basket_service.total()}, mimetype="application/json")
return Response(
{"total": self.basket_service.total()}, mimetype="application/json"
)
def post(self):
# expects something similar: {"items": [{"item_id": abc002}]}

View File

@ -7,14 +7,14 @@ import logging
import endpoints.BasketEndpoint as BasketEndpoint
app = Flask(__name__)
app.secret_key = 'SUPER_DUPER_BAD_SECRET_KEY'
app.secret_key = "SUPER_DUPER_BAD_SECRET_KEY"
api = Api(app)
logging.basicConfig(level=logging.DEBUG)
api.add_resource(BasketEndpoint.Basket,'/api/v1/basket/')
api.add_resource(BasketEndpoint.Basket, "/api/v1/basket/")
@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)

View File

@ -1,5 +1,6 @@
from dataclasses import dataclass
@dataclass
class Item:
id: str

View File

@ -2,4 +2,4 @@ from 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)
app.run(host="0.0.0.0", port="80", debug=False, threaded=False)

View File

@ -1,4 +1,3 @@
from collections import defaultdict
from DealsService import DealsService
from ProductService import ProductService

View File

@ -1,4 +1,3 @@
from collections import defaultdict
import math
@ -18,7 +17,6 @@ class DealsService:
# changed with the rollout of a new version,
self.deals["two_for_one"] = DealsService.two_for_one_deal
def get_items_with_final_prices(self, items) -> list:
groups = defaultdict(list)
@ -43,7 +41,8 @@ class DealsService:
@staticmethod
def two_for_one_deal(group):
'''' applies deal onto item group in place '''
"""' applies deal onto item group in place"""
# ideally would be an object implementing a "Deal"-interface,
# which has 2 functions, deal_is_applicable() and apply_deal()
def _round_up(self, val: float):
@ -62,7 +61,8 @@ class DealsService:
@staticmethod
def ten_percent_off(group):
# the percentage discount could be added to function signature
'''' applies deal onto item group in place '''
"""' applies deal onto item group in place"""
# ideally would be an object implementing a "Deal"-interface,
# which has 2 functions, deal_is_applicable() and apply_deal()
def _round_up(self, val: float):

View File

@ -11,6 +11,5 @@ class ProductService:
self.prices["A0001"] = 12.99
self.prices["A0002"] = 3.99
def get_item_from_id(self, item_id: str) -> Item:
return Item(id=item_id, price=self.prices.get(item_id))