Skip to content

Commit ea88936

Browse files
committed
fixed backend structure of events works but destroyed join and leave methods
1 parent c4f60db commit ea88936

File tree

8 files changed

+61
-39
lines changed

8 files changed

+61
-39
lines changed

src/Mealz/MealBundle/Controller/ApiController.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,16 @@ public function getDashboardData(ParticipationCountService $partCountSrv): JsonR
104104
'slots' => [],
105105
'meals' => [],
106106
'isEnabled' => $day->isEnabled(),
107-
'events' => [],
107+
'events' => $this->apiSrv->getEventParticipationsData($day, $profile),
108108
];
109-
$events = [];
110-
foreach($day->getEvents() as $event){
111-
$events = $this->setEventData($event, $events);
112-
}
113-
$response[$week->getId()]['days'][$day->getId()]['events'] = $events;
109+
// $events = [];
110+
// // if($day->getId() == 1111){
111+
// // var_dump($this->apiSrv->getEventParticipationData($day, $profile));
112+
// // }
113+
// foreach($day->getEvents() as $event){
114+
// $events = $this->setEventData($event, $events);
115+
// }
116+
// $response[$week->getId()]['days'][$day->getId()]['events'] = $events;
114117
$this->addSlots($response[$week->getId()]['days'][$day->getId()]['slots'], $slots, $day, $activeParticipations);
115118
/** @var Meal $meal */
116119
foreach ($day->getMeals() as $meal) {

src/Mealz/MealBundle/Entity/EventParticipation.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ class EventParticipation
3030
#[ORM\JoinColumn(name: 'event', referencedColumnName: 'id')]
3131
public Event $event;
3232

33-
#[ORM\OneToMany(mappedBy: 'event', targetEntity: Participant::class)]
33+
#[ORM\OneToMany(mappedBy: 'event', targetEntity: Participant::class, cascade: ['persist', 'remove'])]
3434
public ?Collection $participants = null;
3535

36+
3637
public function __construct(Day $day, Event $event, ?Collection $participants = null)
3738
{
3839
$this->day = $day;
3940
$this->event = $event;
40-
$this->participants = $participants;
41+
$this->participants = $participants ?? new ArrayCollection();
4142
}
4243

4344
public function getId(): ?int
@@ -80,6 +81,11 @@ public function getParticipant(Profile $profile): ?Participant
8081
return null;
8182
}
8283

84+
public function setParticipant(Participant $participant) : void
85+
{
86+
$this->participants->add($participant);
87+
}
88+
8389
public function getParticipants(): ArrayCollection
8490
{
8591
if (null === $this->participants) {

src/Mealz/MealBundle/Service/ApiService.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,15 @@ public function isParamValid($parameters, $key, $type): bool
124124

125125
public function getEventParticipationData(Day $day, ?Profile $profile = null): ?array
126126
{
127-
return $this->eventPartSrv->getEventParticipationData($day, $profile);
127+
return $this->eventPartSrv->getEventParticipationData($day,null, $profile);
128+
}
129+
public function getEventParticipationsData(Day $day, ?Profile $profile = null): ?array
130+
{
131+
$participations = [];
132+
foreach($day->getEvents() as $eventParticipation){
133+
$participations[] = $this->eventPartSrv->getEventParticipationData($day,$eventParticipation->getId(), $profile);
134+
}
135+
return $participations;
128136
}
129137

130138
/**

src/Mealz/MealBundle/Service/EventParticipationService.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Doctrine\ORM\EntityManagerInterface;
1313
use Exception;
1414

15+
use function Amp\Iterator\toArray;
16+
1517
class EventParticipationService
1618
{
1719
private Doorman $doorman;
@@ -56,7 +58,7 @@ public function handleEventParticipation(Day $day, EventParticipation $event): v
5658
public function getEventParticipationData(Day $day, ?int $eventId = null, ?Profile $profile = null,): ?array
5759
{
5860
if($eventId === null){
59-
return $day->getEvents();
61+
return $day->getEvents()->toArray();
6062
} else{
6163
$eventParticipation = $day->getEvent($day,$eventId);
6264
if (null === $eventParticipation) {
@@ -178,9 +180,14 @@ private function removeEventFromDay(Day $day, EventParticipation $event): void
178180
$day->removeEvent($event);
179181
}
180182

181-
private function createEventParticipation(Profile $profile, EventParticipation $eventParticiation): Participant
183+
private function createEventParticipation(Profile $profile, EventParticipation $eventParticipation): Participant
182184
{
183-
return new Participant($profile, null, $eventParticiation);
185+
$participant = new Participant($profile, null, $eventParticipation);
186+
$eventParticipation->setParticipant($participant);
187+
$this->em->persist($participant);
188+
$this->em->persist($eventParticipation);
189+
$this->em->flush();
190+
return $participant;
184191
}
185192

186193
private function getParticipantName(Participant $participant): string

src/Resources/src/api/getDashboardData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export type Slot = {
4040
};
4141

4242
export type EventParticipation = {
43-
eventId: number;
43+
id: number;
4444
event: Event;
4545
day: Date;
4646
participationId: number;

src/Resources/src/components/dashboard/EventData.vue

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<span
2929
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"
3030
>
31-
{{ event.event.title }}
31+
{{ getEventById(event?.id ?? -1)?.title }}
3232
</span>
3333
<div class="flex w-fit flex-row items-center gap-1 self-end justify-self-end max-[380px]:basis-3/12">
3434
<GuestButton
@@ -40,7 +40,7 @@
4040
class="col-start-1 w-[24px] text-center"
4141
/>
4242
<EventPopup
43-
:event-title="event.event.title"
43+
:event-title="getEventById(event?.id ?? -1)?.title"
4444
:date="day.date.date"
4545
/>
4646
<ParticipationCounter
@@ -52,7 +52,7 @@
5252
<CheckBox
5353
:isActive="new Date(day.date.date) > new Date()"
5454
:isChecked="event?.isParticipating ?? false"
55-
@click="handleClick"
55+
@click="handleClick(event)"
5656
/>
5757
</div>
5858
</div>
@@ -62,7 +62,7 @@
6262
</template>
6363

6464
<script setup lang="ts">
65-
import { type Day } from '@/api/getDashboardData';
65+
import { type Day, type EventParticipation } from '@/api/getDashboardData';
6666
import { useEvents } from '@/stores/eventsStore';
6767
import ParticipationCounter from '../menuCard/ParticipationCounter.vue';
6868
import CheckBox from '../misc/CheckBox.vue';
@@ -80,20 +80,19 @@ const props = defineProps<{
8080
}>();
8181
8282
const twoEvents: boolean = props.day?.events !== undefined && Object.keys(props.day?.events).length === 2;
83-
console.log('Events am Tag '+JSON.stringify(props.day.events));
8483
const { t } = useI18n();
85-
const { joinEvent, leaveEvent } = useEvents();
84+
const { getEventById, joinEvent, leaveEvent } = useEvents();
8685
const { addLock, isLocked, removeLock } = useLockRequests();
8786
88-
async function handleClick() {
87+
async function handleClick(event: EventParticipation) {
8988
if (isLocked(props.dayId) === true || isEventPast() === true) {
9089
return;
9190
}
9291
addLock(props.dayId);
93-
if (props.day.events.EventParticipation?.isParticipating === false) {
94-
await joinEvent(props.day.date.date, props.day.events.EventParticipation.eventId);
92+
if (event?.isParticipating === undefined || event?.isParticipating === false) {
93+
await joinEvent(props.day.date.date, event.id);
9594
} else {
96-
await leaveEvent(props.day.date.date, props.day.events.EventParticipation.eventId);
95+
await leaveEvent(props.day.date.date, event.id);
9796
}
9897
removeLock(props.dayId);
9998
}

src/Resources/src/stores/dashboardStore.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ class DashboardStore extends Store<Dashboard> {
3535
const week = this.getWeek(weekID);
3636
if (week !== undefined) {
3737
const day = week.days[dayID as number];
38-
console.log(JSON.stringify(day.events));
39-
4038
return day;
4139
}
4240
return undefined;
@@ -45,10 +43,11 @@ class DashboardStore extends Store<Dashboard> {
4543
public getDayByEventParticipationId(eventParticipationId: number): Day | undefined {
4644
for (const week of Object.values(this.state.weeks)) {
4745
for (const day of Object.values(week.days)) {
46+
for(const event of Object.values(day.events))
4847
if (
49-
day.events.EventParticipation.eventId !== null &&
50-
day.events.EventParticipation.eventId !== undefined &&
51-
day.events.EventParticipation.eventId === eventParticipationId
48+
event.id !== null &&
49+
event.id !== undefined &&
50+
event.id === eventParticipationId
5251
) {
5352
return day;
5453
}
@@ -110,20 +109,20 @@ class DashboardStore extends Store<Dashboard> {
110109

111110
public updateEventParticipation(weekId: number, dayId: number, eventId: number, participations: number) {
112111
const day = this.getDay(weekId, dayId);
113-
if (
114-
day !== null &&
115-
day !== undefined &&
116-
day.events.Dictionary !== null &&
117-
day.events.Dictionary.eventId === eventId
118-
) {
119-
day.events.EventParticipation.participations = participations;
120-
}
112+
if (
113+
day !== null &&
114+
day !== undefined &&
115+
day.events !== null &&
116+
day.events[eventId] !== undefined
117+
) {
118+
day.events[eventId].participations = participations;
119+
}
121120
}
122121

123122
public setIsParticipatingEvent(participationId: number, isParticipating: boolean) {
124123
const day = this.getDayByEventParticipationId(participationId);
125-
if (day !== undefined) {
126-
day.events.EventParticipation.isParticipating = isParticipating;
124+
if (day !== undefined && day.events[participationId] !== undefined) {
125+
day.events[participationId].isParticipating = isParticipating;
127126
}
128127
}
129128

src/Resources/src/stores/eventsStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ export function useEvents() {
7979
const { error, events } = await getEvents();
8080
if (isResponseArrayOkay<Event>(error, events, isEvent) === true) {
8181
EventsState.events = events.value as Event[];
82-
console.log('fetch Events ' + JSON.stringify(EventsState.events));
8382
EventsState.error = '';
8483
} else {
8584
EventsState.error = 'Error on fetching events';
@@ -190,6 +189,7 @@ export function useEvents() {
190189
* @param date The date the event is on (format: 'YYYY-mm-dd hh:MM:ss')
191190
*/
192191
async function joinEvent(date: string, eventId: number) {
192+
console.log('Join event im EventStore ' + eventId);
193193
const { error, response } = await postJoinEvent(date, eventId);
194194

195195
if (error.value === true && isMessage(response.value) === true) {

0 commit comments

Comments
 (0)