27 lines
1.1 KiB
Python
27 lines
1.1 KiB
Python
from fooder.controller.base import ModelController
|
|
from fooder.domain import UserSettings
|
|
from fooder.model.user_settings import UserSettingsUpdateModel
|
|
from fooder.utils.calories import calculate_calories
|
|
|
|
|
|
class UserSettingsController(ModelController[UserSettings]):
|
|
async def update(self, data: UserSettingsUpdateModel) -> None:
|
|
if data.protein_goal is not None:
|
|
self.obj.protein_goal = data.protein_goal
|
|
if data.carb_goal is not None:
|
|
self.obj.carb_goal = data.carb_goal
|
|
if data.fat_goal is not None:
|
|
self.obj.fat_goal = data.fat_goal
|
|
if data.fiber_goal is not None:
|
|
self.obj.fiber_goal = data.fiber_goal
|
|
if data.calories_goal is not None:
|
|
self.obj.calories_goal = data.calories_goal
|
|
else:
|
|
self.obj.calories_goal = calculate_calories(
|
|
protein=self.obj.protein_goal,
|
|
carb=self.obj.carb_goal,
|
|
fat=self.obj.fat_goal,
|
|
fiber=self.obj.fiber_goal,
|
|
)
|
|
|
|
await self.ctx.repo.user_settings.update(self.obj)
|