diff --git a/src/Mealz/MealBundle/Controller/ParticipantController.php b/src/Mealz/MealBundle/Controller/ParticipantController.php index 613f46577..6ea11ffed 100644 --- a/src/Mealz/MealBundle/Controller/ParticipantController.php +++ b/src/Mealz/MealBundle/Controller/ParticipantController.php @@ -377,6 +377,24 @@ public function getProfilesWithoutParticipation(Week $week): JsonResponse return new JsonResponse($response, 200); } + /** + * Returns the dishes for a combi meal of a participant. + */ + public function getCombiForMeal(Meal $meal): JsonResponse + { + $profile = $this->getProfile(); + if (null === $profile) { + return new JsonResponse(null, 403); + } + + $participant = $meal->getParticipant($profile); + if (null === $participant) { + return new JsonResponse(['message' => 'No participation found'], 404); + } + + return new JsonResponse($participant->getCombinedDishes()->toArray(), 200); + } + private function generateResponse(string $route, string $action, Participant $participant): JsonResponse { return new JsonResponse([ diff --git a/src/Mealz/MealBundle/Resources/config/routing.yml b/src/Mealz/MealBundle/Resources/config/routing.yml index a903e77c3..40effdc8c 100644 --- a/src/Mealz/MealBundle/Resources/config/routing.yml +++ b/src/Mealz/MealBundle/Resources/config/routing.yml @@ -316,6 +316,11 @@ MealzMealBundle_api_non_participating: defaults: { _controller: App\Mealz\MealBundle\Controller\ParticipantController::getProfilesWithoutParticipation } methods: [ GET ] +MealzMealBundle_api_participation_combi: + path: /api/participations/combi/{meal} + defaults: { _controller: App\Mealz\MealBundle\Controller\ParticipantController::getCombiForMeal } + methods: [ GET ] + MealzMealBundle_Show_participations: path: /show/participations defaults: { _controller: App\Mealz\MealBundle\Controller\FrontendController::renderIndex } diff --git a/src/Resources/src/api/getDishesForCombi.ts b/src/Resources/src/api/getDishesForCombi.ts new file mode 100644 index 000000000..5ff87176e --- /dev/null +++ b/src/Resources/src/api/getDishesForCombi.ts @@ -0,0 +1,17 @@ +import { Dish } from "@/stores/dishesStore"; +import useApi from "./api"; + +/** + * Fetches the dishes a combi meal consists of + * @param mealId The id of the combi-meal + */ +export default async function getDishesForCombi(mealId: number) { + const { error, response, request } = useApi( + 'GET', + `api/participations/combi/${mealId}` + ); + + await request(); + + return { error, response }; +} \ No newline at end of file diff --git a/src/Resources/src/components/dashboard/MealData.vue b/src/Resources/src/components/dashboard/MealData.vue index 792c10843..d5477b796 100644 --- a/src/Resources/src/components/dashboard/MealData.vue +++ b/src/Resources/src/components/dashboard/MealData.vue @@ -17,6 +17,12 @@ > {{ description }}

+

+ {{ combiDescription.join(' - ') }} +

locale.value.substring(0, 2) === 'en' ? meal.title.en : meal.title.de); const description = computed(() => locale.value.substring(0, 2) === 'en' ? meal.description.en : meal.description.de); +const combiDescription = ref([]); + +onMounted(async () => { + if (combiDescription.value.length < 1) { + combiDescription.value = await getCombiDescription(); + } +}); + +watch( + () => meal.isParticipating, + async () => combiDescription.value = await getCombiDescription() +); const mealCSS = computed(() => { let css = 'flex content-center rounded-md h-[30px] xl:h-[20px] mr-[15px] ' @@ -90,6 +110,24 @@ const participationDisplayString = computed(() => { const fixedCount = Math.ceil(parseFloat(meal.participations.toFixed(1))); return meal.limit > 0 ? `${fixedCount}/${meal.limit}` : fixedCount; }); + +async function getCombiDescription() { + if (props.meal.isParticipating !== null && props.meal.dishSlug === 'combined-dish' && dayHasVariations()) { + const combiDishes = await getCombiDishes(typeof(props.mealID) === 'string' ? parseInt(props.mealID) : props.mealID); + return combiDishes.map(dish => locale.value === 'de' ? dish.titleDe : dish.titleEn); + } else { + return []; + } +} + +function dayHasVariations() { + for (const meal of Object.values(props.day.meals)) { + if ((meal as Meal).variations && Object.values((meal as Meal).variations).length > 0) { + return true; + } + } + return false; +}