* #183 added backend validation for mealplanning timespan

* Fixes #183

Disabling save button when dateDif is negative, replacing non-functional invisible button(?) with proper spacing

Co-authored-by: Bernhard Großer <30469627+boerniee@users.noreply.github.com>
Co-authored-by: Andreas Waschinski <an.andreas@posteo.de>
This commit is contained in:
Andreas Waschinski 2021-02-24 21:15:04 +01:00 committed by GitHub
commit 2717613443
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View file

@ -69,16 +69,14 @@
<MealPlanCard v-model="meals" /> <MealPlanCard v-model="meals" />
</v-card-text> </v-card-text>
<v-row align="center" justify="end"> <v-row align="center" justify="end">
<v-card-actions> <v-card-actions class="mr-5">
<v-btn color="success" @click="random" v-if="meals[1]" text> <v-btn color="success" @click="random" v-if="meals.length > 0" text>
{{ $t("general.random") }} {{ $t("general.random") }}
</v-btn> </v-btn>
<v-btn color="success" @click="save" text> <v-btn color="success" @click="save" text :disabled="meals.length == 0">
{{ $t("general.save") }} {{ $t("general.save") }}
</v-btn> </v-btn>
<v-spacer></v-spacer>
<v-btn icon @click="show = !show"> </v-btn>
</v-card-actions> </v-card-actions>
</v-row> </v-row>
</v-card> </v-card>
@ -136,7 +134,7 @@ export default {
let dateDif = (endDate - startDate) / (1000 * 3600 * 24) + 1; let dateDif = (endDate - startDate) / (1000 * 3600 * 24) + 1;
if (dateDif <= 1) { if (dateDif < 1) {
return null; return null;
} }

View file

@ -2,7 +2,7 @@ from datetime import date, timedelta
from typing import List, Optional from typing import List, Optional
from db.database import db from db.database import db
from pydantic import BaseModel from pydantic import BaseModel, validator
from sqlalchemy.orm.session import Session from sqlalchemy.orm.session import Session
from services.recipe_services import Recipe from services.recipe_services import Recipe
@ -41,6 +41,12 @@ class MealPlan(BaseModel):
} }
} }
@validator('endDate')
def endDate_after_startDate(cls, v, values, **kwargs):
if 'startDate' in values and v < values['startDate']:
raise ValueError('EndDate should be greater than StartDate')
return v
def process_meals(self, session: Session): def process_meals(self, session: Session):
meals = [] meals = []
for x, meal in enumerate(self.meals): for x, meal in enumerate(self.meals):