Skip to content

Commit 963f33f

Browse files
Merge pull request #296 from AndreWohnsland/dev
Prevent preparation of not possible cocktails
2 parents 5ef066c + a231f25 commit 963f33f

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/api/routers/cocktails.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from src.api.internal.utils import calculate_cocktail_volume_and_concentration, map_cocktail, not_on_demo
88
from src.api.middleware import maker_protected
99
from src.api.models import Cocktail, CocktailInput, CocktailStatus, ErrorDetail, PrepareCocktailRequest
10+
from src.config.config_manager import CONFIG as cfg
1011
from src.config.config_manager import shared
1112
from src.database_commander import DatabaseCommander
1213
from src.dialog_handler import DIALOG_HANDLER as DH
@@ -65,6 +66,11 @@ async def prepare_cocktail(
6566
if cocktail is None:
6667
message = DH.get_translation("element_not_found", element_name=f"Cocktail (id={cocktail_id})")
6768
raise HTTPException(status_code=404, detail=message)
69+
# need to check if the cocktail is possible
70+
# this can happen if there is no ui guidance, e.g. only a direct post of an id
71+
hand_ids = DBC.get_available_ids()
72+
if not cocktail.is_possible(hand_ids, cfg.MAKER_MAX_HAND_INGREDIENTS):
73+
raise HTTPException(status_code=400, detail=DH.get_translation("cocktail_not_possible"))
6874
cocktail.scale_cocktail(request.volume, factor)
6975
result, msg, ingredient = maker.validate_cocktail(cocktail)
7076
if result != PrepareResult.VALIDATION_OK:

src/dialog_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"cleaning_started",
8282
"cocktail_canceled",
8383
"cocktail_in_progress",
84+
"cocktail_not_possible",
8485
"cocktail_ready_add",
8586
"cocktail_ready",
8687
"cocktailberry_up_to_date",

src/language.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ dialog:
6767
cocktail_ready_add:
6868
en: 'Also add:'
6969
de: 'Noch hinzufügen:'
70+
cocktail_not_possible:
71+
en: 'Cocktail is not possible to make, not all ingredients are available!'
72+
de: 'Cocktail zubereiten ist nicht möglich, nicht alle Zutaten sind verfügbar!'
7073
enter_cocktail_name:
7174
en: 'Please enter cocktail name!'
7275
de: 'Bitte Cocktail Namen eingeben!'

0 commit comments

Comments
 (0)