Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
FE-#148: Code-QA
Browse files Browse the repository at this point in the history
Split location field of event into street, postalCode and city
  • Loading branch information
Drumber committed May 27, 2024
1 parent 493b3eb commit fb8a959
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ <h1 mat-dialog-title>Event {{ isCreatingNewEvent ? 'erstellen' : 'bearbeiten'}}<
<div class="grid-container">
<mat-form-field>
<mat-label>PLZ</mat-label>
<input matInput formControlName="plz">
<input matInput formControlName="postalCode">
</mat-form-field>
<mat-form-field>
<mat-label>Stadt</mat-label>
<input matInput formControlName="stadt">
<input matInput formControlName="city">
</mat-form-field>
</div>
</div>
Expand Down
48 changes: 10 additions & 38 deletions frontend/src/app/create-event/create-event-dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class CreateEventDialogComponent {
private dialogRef: MatDialogRef<CreateEventDialogComponent>,
) {
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(
Expand All @@ -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
Expand All @@ -65,52 +64,25 @@ export class CreateEventDialogComponent {
return null;
}

private extractAddress(location: string | undefined) {
if(location) {
const addressRegex = /^(?<street>[\w\säöüÄÖÜß]+ \d+) (?<postalCode>\d{5}) (?<city>[\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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
<mat-card-content class="details">

<div class="details-div">
@if (eventData.location) {
@if (hasValidLocation()) {
<mat-icon inline>location_on</mat-icon>
<p class="location">{{ eventData.location }}</p>
<p class="location">{{ formattedLocation }}</p>
}
</div>
<div class="datetime-container">
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/app/eventpage/event-banner/event-banner.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ");
}
}
10 changes: 8 additions & 2 deletions frontend/src/model/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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;
}

0 comments on commit fb8a959

Please sign in to comment.