diff --git a/backend/src/main/java/com/dhbw/get2gether/backend/event/model/Event.java b/backend/src/main/java/com/dhbw/get2gether/backend/event/model/Event.java index e760fe9..cbf7046 100644 --- a/backend/src/main/java/com/dhbw/get2gether/backend/event/model/Event.java +++ b/backend/src/main/java/com/dhbw/get2gether/backend/event/model/Event.java @@ -21,7 +21,7 @@ public class Event { private final LocalDateTime creationDate; private String name; private String description; - private String location; + private EventLocation location; private LocalDateTime date; private LocalDateTime endDate; private String invitationLink; diff --git a/backend/src/main/java/com/dhbw/get2gether/backend/event/model/EventCreateCommand.java b/backend/src/main/java/com/dhbw/get2gether/backend/event/model/EventCreateCommand.java index d12c1a1..dc13681 100644 --- a/backend/src/main/java/com/dhbw/get2gether/backend/event/model/EventCreateCommand.java +++ b/backend/src/main/java/com/dhbw/get2gether/backend/event/model/EventCreateCommand.java @@ -10,7 +10,7 @@ public class EventCreateCommand { private String name; private String description; - private String location; + private EventLocation location; private LocalDateTime date; private LocalDateTime endDate; } diff --git a/backend/src/main/java/com/dhbw/get2gether/backend/event/model/EventDetailDto.java b/backend/src/main/java/com/dhbw/get2gether/backend/event/model/EventDetailDto.java index b64bb26..932d61d 100644 --- a/backend/src/main/java/com/dhbw/get2gether/backend/event/model/EventDetailDto.java +++ b/backend/src/main/java/com/dhbw/get2gether/backend/event/model/EventDetailDto.java @@ -20,7 +20,7 @@ public class EventDetailDto { private final LocalDateTime creationDate; private String name; private String description; - private String location; + private EventLocation location; private LocalDateTime date; private LocalDateTime endDate; private String invitationLink; diff --git a/backend/src/main/java/com/dhbw/get2gether/backend/event/model/EventLocation.java b/backend/src/main/java/com/dhbw/get2gether/backend/event/model/EventLocation.java new file mode 100644 index 0000000..ebd3a05 --- /dev/null +++ b/backend/src/main/java/com/dhbw/get2gether/backend/event/model/EventLocation.java @@ -0,0 +1,16 @@ +package com.dhbw.get2gether.backend.event.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@AllArgsConstructor +@Getter +@Setter +@Builder +public class EventLocation { + private String street; + private String postalCode; + private String city; +} diff --git a/backend/src/main/java/com/dhbw/get2gether/backend/event/model/EventUpdateCommand.java b/backend/src/main/java/com/dhbw/get2gether/backend/event/model/EventUpdateCommand.java index d604d86..bb11f05 100644 --- a/backend/src/main/java/com/dhbw/get2gether/backend/event/model/EventUpdateCommand.java +++ b/backend/src/main/java/com/dhbw/get2gether/backend/event/model/EventUpdateCommand.java @@ -12,7 +12,7 @@ public class EventUpdateCommand { private String name; private String description; - private String location; + private EventLocation location; private LocalDateTime date; private LocalDateTime endDate; } diff --git a/frontend/src/app/create-event/create-event-dialog.component.html b/frontend/src/app/create-event/create-event-dialog.component.html index 366e09e..3942c46 100644 --- a/frontend/src/app/create-event/create-event-dialog.component.html +++ b/frontend/src/app/create-event/create-event-dialog.component.html @@ -36,11 +36,11 @@

Event {{ isCreatingNewEvent ? 'erstellen' : 'bearbeiten'}}<
PLZ - + Stadt - +
diff --git a/frontend/src/app/create-event/create-event-dialog.component.ts b/frontend/src/app/create-event/create-event-dialog.component.ts index 3c79318..d259fdf 100644 --- a/frontend/src/app/create-event/create-event-dialog.component.ts +++ b/frontend/src/app/create-event/create-event-dialog.component.ts @@ -19,7 +19,6 @@ export class CreateEventDialogComponent { private dialogRef: MatDialogRef, ) { this.event = data.event; - const location = this.extractAddress(this.event?.location); const time = this.extractDateAndTime(this.event?.date); this.form = this.fb.group({ name: new FormControl( @@ -36,13 +35,13 @@ export class CreateEventDialogComponent { time ?? null ), street: new FormControl( - location?.street ?? null + this.event?.location?.street ?? null ), - plz: new FormControl( - location?.postalCode ?? null + postalCode: new FormControl( + this.event?.location?.postalCode ?? null ), - stadt: new FormControl( - location?.city ?? null + city: new FormControl( + this.event?.location?.city ?? null ), location: new FormControl( this.event?.location ?? null @@ -65,52 +64,25 @@ export class CreateEventDialogComponent { return null; } - private extractAddress(location: string | undefined) { - if(location) { - const addressRegex = /^(?[\w\säöüÄÖÜß]+ \d+) (?\d{5}) (?[\w\säöüÄÖÜß]+)$/; - const match = location.match(addressRegex); - if (match && match.groups) { - return { - street: match.groups['street'], - postalCode: match.groups['postalCode'], - city: match.groups['city'] - }; - } - } - return null; - } - submit(): void { if (this.form.valid) { - this.updateAddress(); this.updateStartDate(); this.updateEndDate(); let data: CreateEventCommand = { name: this.form.value.name, date: this.form.value.date, endDate: this.form.value.endDate, - location: this.form.value.location, + location: { + street: this.form.value.street, + postalCode: this.form.value.postalCode, + city: this.form.value.city + }, description: this.form.value.description } this.dialogRef.close(data); } } - private updateAddress() { - const street = this.form.get('street')?.value || ''; - const plz = this.form.get('plz')?.value || ''; - const city = this.form.get('stadt')?.value || ''; - - if (!street && !plz && !city) { - return; - } - - const fullAddress = `${street} ${plz} ${city}`; - this.form.patchValue({ - location: fullAddress - }); - } - private updateStartDate() { const dateValue = this.form.get('date')?.value; const time = this.form.get('time')?.value; diff --git a/frontend/src/app/eventpage/event-banner/event-banner.component.html b/frontend/src/app/eventpage/event-banner/event-banner.component.html index b3d762e..03ee088 100644 --- a/frontend/src/app/eventpage/event-banner/event-banner.component.html +++ b/frontend/src/app/eventpage/event-banner/event-banner.component.html @@ -22,9 +22,9 @@
- @if (eventData.location) { + @if (hasValidLocation()) { location_on -

{{ eventData.location }}

+

{{ formattedLocation }}

}
diff --git a/frontend/src/app/eventpage/event-banner/event-banner.component.ts b/frontend/src/app/eventpage/event-banner/event-banner.component.ts index c158a3a..d3c55ad 100644 --- a/frontend/src/app/eventpage/event-banner/event-banner.component.ts +++ b/frontend/src/app/eventpage/event-banner/event-banner.component.ts @@ -85,4 +85,15 @@ export class EventBannerComponent implements OnInit { } }); } + + hasValidLocation(): boolean { + const location = this.eventData.location; + return !!location && (!!location.street || !!location.postalCode || !!location.city); + } + + get formattedLocation(): string { + const location = this.eventData.location; + if (!location) return ""; + return [location.street, location.postalCode, location.city].join(" "); + } } diff --git a/frontend/src/model/event.ts b/frontend/src/model/event.ts index e3b409d..9f5ab36 100644 --- a/frontend/src/model/event.ts +++ b/frontend/src/model/event.ts @@ -11,7 +11,7 @@ export type EventOverview = { export type Event = EventOverview & { creationDate: string; description: string; - location: string; + location: EventLocation; invitationLink: string | undefined; creatorId: string; participants: SimpleUser[]; @@ -21,7 +21,13 @@ export type Event = EventOverview & { export type CreateEventCommand = { name: string; description: string | undefined; - location: string | undefined; + location: EventLocation | undefined; date: string | undefined; endDate: string | undefined; } + +export type EventLocation = { + street: string; + postalCode: string; + city: string; +}