Skip to content

Commit

Permalink
Merge pull request #405 from AOEpeople/feature/#261405-participations…
Browse files Browse the repository at this point in the history
…-api-events

Feature/#261405 participations api events
  • Loading branch information
MalibusParty authored Jan 18, 2024
2 parents 3ceb2b0 + 2b09fef commit 7251e39
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/Mealz/MealBundle/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ public function list(): JSONResponse
$list['meals'] = $list['meals'] + $this->getDishData($meal);
}

$list['event'] = $this->apiSrv->getEventParticipationInfo($day);

$list['day'] = $day->getDateTime();

return new JsonResponse($list, 200);
Expand Down
19 changes: 18 additions & 1 deletion src/Mealz/MealBundle/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,25 @@ public function isParamValid($parameters, $key, $type): bool
&& $type === gettype($parameters[$key]);
}

public function getEventParticipationData(Day $day, Profile $profile): ?array
public function getEventParticipationData(Day $day, Profile $profile = null): ?array
{
return $this->eventPartSrv->getEventParticipationData($day, $profile);
}

public function getEventParticipationInfo(Day $day): ?array
{
if (null === $day->getEvent()) {
return null;
}

return [
'name' => $day->getEvent()->getEvent()->getTitle(),
'participants' => $this->getEventParticipants($day),
];
}

private function getEventParticipants(Day $day): array
{
return $this->eventPartSrv->getParticipants($day);
}
}
24 changes: 21 additions & 3 deletions src/Mealz/MealBundle/Service/EventParticipationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,24 @@ public function handleEventParticipation(Day $day, int $eventId = null)
}
}

public function getEventParticipationData(Day $day, Profile $profile): ?array
public function getEventParticipationData(Day $day, Profile $profile = null): ?array
{
$eventParticipation = $day->getEvent();
if (null === $eventParticipation) {
return null;
}

return [
$participationData = [
'eventId' => $eventParticipation->getEvent()->getId(),
'participationId' => $eventParticipation->getId(),
'participations' => count($eventParticipation->getParticipants()),
'isParticipating' => null !== $eventParticipation->getParticipant($profile),
];

if (null !== $profile) {
$participationData['isParticipating'] = null !== $eventParticipation->getParticipant($profile);
}

return $participationData;
}

public function join(Profile $profile, Day $day): ?EventParticipation
Expand Down Expand Up @@ -87,6 +92,19 @@ public function leave(Profile $profile, Day $day): ?EventParticipation
return $eventParticipation;
}

public function getParticipants(Day $day): array
{
$eventParticipation = $day->getEvent();
if (null === $eventParticipation) {
return [];
}

return array_map(
fn (Participant $participant) => $participant->getProfile()->getFullName(),
$day->getEvent()->getParticipants()->toArray()
);
}

private function addEventToDay(Day $day, ?Event $event)
{
// new eventparticipation
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/src/components/dashboard/EventData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<ParticipationCounter
class="justify-self-end"
:limit="0"
:mealCSS="new Date(day.date.date) > new Date() ? 'bg-primary-4' : 'bg-[#80909F]'"
:mealCSS="!day.isLocked ? 'bg-primary-4' : 'bg-[#80909F]'"
>
{{ day.event?.participations }}
</ParticipationCounter>
Expand Down
6 changes: 5 additions & 1 deletion src/Resources/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@
"503": "Die Anfrage zum Ausgleich ist fehlgeschlagen.",
"504": "Das Profil für den Ausgleich konnte nicht gefunden werden.",
"505": "Diese Anfrage zum Ausgleich wurde entweder bereits bearbeitet, oder ist ungültig.",
"601": "Der Betrag der dem Konto hinzugefügt werden soll, muss mehr als 0 sein."
"601": "Der Betrag der dem Konto hinzugefügt werden soll, muss mehr als 0 sein.",
"701": "Es wurden noch nicht alle Details zu dem Event eingefügt",
"801": "Keine Berechtigung zum beitreten oder verlassen",
"802": "Dem Event konnte nicht beigetreten werden",
"803": "Das Event konnte nicht verlassen werden"
},
"success": {
"menu": {
Expand Down
6 changes: 5 additions & 1 deletion src/Resources/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@
"503": "The settlement request failed.",
"504": "The profile for the settlement request could not be found.",
"505": "The settlement request has either already been processed or the request is invalid.",
"601": "The amount to add to the account must be more than 0."
"601": "The amount to add to the account must be more than 0.",
"701": "Event creation parameters are missing",
"801": "No permission to enter or leave the event",
"802": "Couldn't join the event",
"803": "Couldn't leave the event"
},
"success": {
"menu": {
Expand Down
8 changes: 8 additions & 0 deletions src/Resources/src/stores/eventsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ export function useEvents() {
}
}

/**
* Joins an event on a specific date and emits an {EventParticipationResponse}
* @param date The date the event is on (format: 'YYYY-mm-dd hh:MM:ss')
*/
async function joinEvent(date: string) {
const { error, response } = await postJoinEvent(date);

Expand All @@ -165,6 +169,10 @@ export function useEvents() {
}
}

/**
* Leaves an event on a specific date
* @param date The date the event is on (format: 'YYYY-mm-dd hh:MM:ss')
*/
async function leaveEvent(date: string) {
const { error, response } = await deleteLeaveEvent(date);

Expand Down
2 changes: 1 addition & 1 deletion src/Resources/src/views/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const {
const { CategoriesState, fetchCategories } = useCategories();
const { t } = useI18n();
const router = useRouter();
const { fetchEvents, EventsState } = useEvents();
const { fetchEvents } = useEvents();
const props = withDefaults(defineProps<{
Expand Down

0 comments on commit 7251e39

Please sign in to comment.