Skip to content

Commit

Permalink
Merge pull request #409 from AOEpeople/feature/#262127-combi-meal-des…
Browse files Browse the repository at this point in the history
…cription

added description for combi meals that contain variations
  • Loading branch information
MalibusParty authored Jan 24, 2024
2 parents 88981f8 + 93acf92 commit a3b8106
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/Mealz/MealBundle/Controller/ParticipantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
5 changes: 5 additions & 0 deletions src/Mealz/MealBundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
17 changes: 17 additions & 0 deletions src/Resources/src/api/getDishesForCombi.ts
Original file line number Diff line number Diff line change
@@ -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<Dish[]>(
'GET',
`api/participations/combi/${mealId}`
);

await request();

return { error, response };
}
40 changes: 39 additions & 1 deletion src/Resources/src/components/dashboard/MealData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
>
{{ description }}
</p>
<p
v-if="combiDescription.length > 0 && meal.dishSlug === 'combined-dish'"
class="m-0 break-words text-[12px] font-light leading-[20px] text-primary min-[380px]:text-[14px]"
>
{{ combiDescription.join(' - ') }}
</p>
</div>
</div>
<PriceTag
Expand Down Expand Up @@ -46,10 +52,11 @@
import ParticipationCounter from '@/components/menuCard/ParticipationCounter.vue';
import MealCheckbox from '@/components/dashboard/MealCheckbox.vue';
import {useI18n} from 'vue-i18n';
import { computed } from 'vue';
import { computed, onMounted, ref, watch } from 'vue';
import { dashboardStore } from '@/stores/dashboardStore';
import PriceTag from '@/components/dashboard/PriceTag.vue';
import { Day, Meal } from '@/api/getDashboardData';
import { useDishes } from '@/stores/dishesStore';
const props = defineProps<{
weekID: number | string,
Expand All @@ -62,10 +69,23 @@ const props = defineProps<{
const meal = props.meal ? props.meal : dashboardStore.getMeal(props.weekID, props.dayID, props.mealID)
const { t, locale } = useI18n();
const { getCombiDishes } = useDishes();
const title = computed(() => 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<string[]>([]);
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] '
Expand All @@ -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;
}
</script>

<style scoped>
Expand Down
20 changes: 19 additions & 1 deletion src/Resources/src/stores/dishesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { isResponseObjectOkay, isResponseArrayOkay } from '@/api/isResponseOkay'
import useFlashMessage from '@/services/useFlashMessage';
import { FlashMessageType } from '@/enums/FlashMessage';
import { refThrottled } from '@vueuse/core';
import getDishesForCombi from '@/api/getDishesForCombi';

export interface Dish {
id: number,
Expand Down Expand Up @@ -234,6 +235,22 @@ export function useDishes() {
}
}

/**
* Fetches the dishes a combi meal consists of
* @param mealId The id of the combi-meal
*/
async function getCombiDishes(combiMealId: number) {
const { error, response } = await getDishesForCombi(combiMealId);

if (error.value === true) {
DishesState.error = 'Error on getting dishes for combi meal';
return [];
} else {
DishesState.error = '';
return response.value;
}
}

/**
* Updates the DishesState with the new values of a dish
*/
Expand Down Expand Up @@ -360,6 +377,7 @@ export function useDishes() {
resetState,
getDishBySlug,
getDishArrayBySlugs,
getDishById
getDishById,
getCombiDishes
};
}

0 comments on commit a3b8106

Please sign in to comment.