Skip to content

Commit

Permalink
updated join and delete methods
Browse files Browse the repository at this point in the history
  • Loading branch information
IrisOlfermann committed Sep 2, 2024
1 parent ea88936 commit c88cfc0
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Mealz/MealBundle/Controller/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function join(DateTime $date, int $eventId): JsonResponse
if (new DateTime() > $day->getDateTime()->modify($eventLockModifier)) {
return new JsonResponse(['message' => '804: User could not join the event'], Response::HTTP_INTERNAL_SERVER_ERROR);
}

// var_dump($day->getDateTime()); exit;
$eventParticipation = $this->eventPartSrv->join($profile, $day, $eventId);
if (null === $eventParticipation) {
return new JsonResponse(['message' => '802: User could not join the event'], Response::HTTP_INTERNAL_SERVER_ERROR);
Expand Down
4 changes: 2 additions & 2 deletions src/Mealz/MealBundle/Entity/Day.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public function getEvents(): EventCollection
}


public function getEvent(Day $day, int $id):EventParticipation | null{
public function getEvent(int $id):EventParticipation | null{
foreach ($this->getEvents() as $event) {
if($event->getId() === $id && $event->getDay() === $day){
if($event->getId() === $id){
return $event;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/Mealz/MealBundle/Service/EventParticipationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getEventParticipationData(Day $day, ?int $eventId = null, ?Profi
if($eventId === null){
return $day->getEvents()->toArray();
} else{
$eventParticipation = $day->getEvent($day,$eventId);
$eventParticipation = $day->getEvent($eventId);
if (null === $eventParticipation) {
return null;
}
Expand All @@ -81,7 +81,7 @@ public function getEventParticipationData(Day $day, ?int $eventId = null, ?Profi

public function join(Profile $profile, Day $day, int $eventId): ?EventParticipation
{
$eventParticipation = $day->getEvent($day, $eventId);
$eventParticipation = $day->getEvent($eventId);
if (null !== $eventParticipation && true === $this->doorman->isUserAllowedToJoinEvent($eventParticipation)) {
$participation = $this->createEventParticipation($profile, $eventParticipation);
$this->em->persist($participation);
Expand Down Expand Up @@ -115,7 +115,7 @@ public function joinAsGuest(

try {
$this->em->persist($guestProfile);
$eventParticipation = $eventDay->getEvent($eventDay, $eventId);
$eventParticipation = $eventDay->getEvent($eventId);
$participation = $this->createEventParticipation($guestProfile, $eventParticipation);

$this->em->persist($participation);
Expand All @@ -132,7 +132,7 @@ public function joinAsGuest(

public function leave(Profile $profile, Day $day, int $eventId): ?EventParticipation
{
$eventParticipation = $day->getEvent($day, $eventId);
$eventParticipation = $day->getEvent( $eventId);
$participation = $eventParticipation->getParticipant($profile);

if (null !== $participation) {
Expand All @@ -152,14 +152,14 @@ public function leave(Profile $profile, Day $day, int $eventId): ?EventParticipa
*/
public function getParticipants(Day $day, int $eventId): array
{
$eventParticipation = $day->getEvent($day, $eventId);
$eventParticipation = $day->getEvent($eventId);
if (null === $eventParticipation) {
return [];
}

return array_map(
fn (Participant $participant) => $this->getParticipantName($participant),
$day->getEvent($day, $eventId)->getParticipants()->toArray()
$day->getEvent( $eventId)->getParticipants()->toArray()
);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Resources/src/api/getDashboardData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ export type Slot = {
};

export type EventParticipation = {
id: number;
event: Event;
day: Date;
eventId: number;
participationId: number;
participations: number;
isParticipating: boolean;
Expand Down
2 changes: 0 additions & 2 deletions src/Resources/src/api/postJoinEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export default async function postJoinEvent(date: string, eventId: number) {
'POST',
`api/events/participation/${date}/${eventId}`
);

await request();

return { error, response };
}
12 changes: 7 additions & 5 deletions src/Resources/src/components/dashboard/EventData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@
<span
class="inline-block grow self-start break-words text-[12px] font-bold leading-[20px] tracking-[0.5px] text-primary-1 max-[380px]:basis-9/12 min-[380px]:self-center min-[380px]:text-note"
>
{{ getEventById(event?.id ?? -1)?.title }}
{{ getEventById(event?.eventId ?? -1)?.title }}
</span>
<div class="flex w-fit flex-row items-center gap-1 self-end justify-self-end max-[380px]:basis-3/12">
<GuestButton
v-if="!day.isLocked && day.events.isPublic"
v-if="!day.isLocked && event.isPublic"
:dayID="dayId"
:index="0"
:invitation="Invitation.EVENT"
:icon-white="false"
class="col-start-1 w-[24px] text-center"
/>
<EventPopup
:event-title="getEventById(event?.id ?? -1)?.title"
:event-title="getEventById(event?.eventId ?? -1)?.title"
:date="day.date.date"
/>
<ParticipationCounter
Expand Down Expand Up @@ -90,9 +90,11 @@ async function handleClick(event: EventParticipation) {
}
addLock(props.dayId);
if (event?.isParticipating === undefined || event?.isParticipating === false) {
await joinEvent(props.day.date.date, event.id);
await joinEvent(props.day.date.date, event?.participationId);
event.isParticipating = true;
} else {
await leaveEvent(props.day.date.date, event.id);
await leaveEvent(props.day.date.date,event?.participationId);
event.isParticipating = false;
}
removeLock(props.dayId);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Resources/src/stores/eventsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function useEvents() {
* Returns the event with the given id from the EventsState
* @param eventId The id of the event
*/
function getEventById(eventId: number) {
function getEventById(eventId: number){
return EventsState.events.find((event) => event.id === eventId);
}

Expand Down Expand Up @@ -189,9 +189,7 @@ export function useEvents() {
* @param date The date the event is on (format: 'YYYY-mm-dd hh:MM:ss')
*/
async function joinEvent(date: string, eventId: number) {
console.log('Join event im EventStore ' + eventId);
const { error, response } = await postJoinEvent(date, eventId);

if (error.value === true && isMessage(response.value) === true) {
EventsState.error = (response.value as IMessage)?.message;
} else if (error.value === true) {
Expand Down

0 comments on commit c88cfc0

Please sign in to comment.