fooder-api/fooder/view/meal.py

50 lines
1.2 KiB
Python
Raw Normal View History

2023-04-01 16:19:12 +02:00
from fastapi import APIRouter, Depends, Request
2023-10-27 16:17:10 +02:00
from ..model.preset import Preset
2023-10-27 15:12:48 +02:00
from ..model.meal import (
Meal,
CreateMealPayload,
SaveMealPayload,
CreateMealFromPresetPayload,
)
2023-10-27 16:39:26 +02:00
from ..controller.meal import CreateMeal, SaveMeal, CreateMealFromPreset, DeleteMeal
2023-04-01 16:19:12 +02:00
router = APIRouter(tags=["meal"])
2023-04-01 20:23:04 +02:00
@router.post("", response_model=Meal)
2023-04-01 16:19:12 +02:00
async def create_meal(
request: Request,
data: CreateMealPayload,
contoller: CreateMeal = Depends(CreateMeal),
):
return await contoller.call(data)
2023-10-27 15:12:48 +02:00
2023-10-27 16:17:10 +02:00
@router.post("/{meal_id}/save", response_model=Preset)
2023-10-27 15:12:48 +02:00
async def save_meal(
request: Request,
meal_id: int,
data: SaveMealPayload,
contoller: SaveMeal = Depends(SaveMeal),
):
2023-10-27 16:17:10 +02:00
return await contoller.call(meal_id, data)
2023-10-27 15:12:48 +02:00
2023-10-27 16:39:26 +02:00
@router.delete("/{meal_id}")
async def delete_meal(
request: Request,
meal_id: int,
contoller: DeleteMeal = Depends(DeleteMeal),
):
return await contoller.call(meal_id)
2023-10-27 15:12:48 +02:00
@router.post("/from_preset", response_model=Meal)
async def create_meal_from_preset(
request: Request,
data: CreateMealFromPresetPayload,
contoller: CreateMealFromPreset = Depends(CreateMealFromPreset),
):
return await contoller.call(data)