diff --git a/front/src/components/NavLink.vue b/front/src/components/NavLink.vue index a306255..bb0ca0c 100644 --- a/front/src/components/NavLink.vue +++ b/front/src/components/NavLink.vue @@ -1,19 +1,34 @@ diff --git a/front/src/dto/EventDto.ts b/front/src/dto/EventDto.ts new file mode 100644 index 0000000..b65e0a9 --- /dev/null +++ b/front/src/dto/EventDto.ts @@ -0,0 +1,17 @@ +import type {Participant} from "@/models/Participant.ts"; +import type {TimeStamp} from "@/models/TimeStamp.ts"; +import type {ParticipantDto} from "@/dto/ParticipantDto.ts"; + +export class EventDto { + + public name: string; + public token: string; + public participants: ParticipantDto[]; + + public constructor(name: string, token: string, participants: ParticipantDto[]) { + this.name = name; + this.token = token; + this.participants = participants; + } + +} diff --git a/front/src/dto/ParticipantDto.ts b/front/src/dto/ParticipantDto.ts new file mode 100644 index 0000000..76c6808 --- /dev/null +++ b/front/src/dto/ParticipantDto.ts @@ -0,0 +1,13 @@ +import type {TimeStampDto} from "@/dto/TimeStampDto.ts"; + +export class ParticipantDto { + + public name: string; + public dates: TimeStampDto[]; + + public constructor(name: string, dates: TimeStampDto[]) { + this.name = name; + this.dates = dates; + } +} + diff --git a/front/src/dto/TimeStampDto.ts b/front/src/dto/TimeStampDto.ts new file mode 100644 index 0000000..0696c08 --- /dev/null +++ b/front/src/dto/TimeStampDto.ts @@ -0,0 +1,8 @@ +export class TimeStampDto { + + public timestamp : number; + + public constructor(date : Date) { + this.timestamp = date.getTime(); + } +} diff --git a/front/src/helpers/DateHelper.ts b/front/src/helpers/DateHelper.ts new file mode 100644 index 0000000..f53de8a --- /dev/null +++ b/front/src/helpers/DateHelper.ts @@ -0,0 +1,7 @@ +export abstract class DateHelper { + + public static toDate(timestamp: number): Date { + return new Date(timestamp); + } + +} diff --git a/front/src/layouts/LayoutDefault.vue b/front/src/layouts/LayoutDefault.vue index 8dba45e..2f274af 100644 --- a/front/src/layouts/LayoutDefault.vue +++ b/front/src/layouts/LayoutDefault.vue @@ -9,9 +9,9 @@ import NavLink from "@/components/NavLink.vue"; diff --git a/front/src/models/Event.ts b/front/src/models/Event.ts index 1cdd81a..8873be8 100644 --- a/front/src/models/Event.ts +++ b/front/src/models/Event.ts @@ -1,4 +1,5 @@ -import type {Participant} from "@/models/Participant.ts"; +import type {Participant, ParticipantState} from "@/models/Participant.ts"; +import type {TimeStampState} from "@/models/TimeStamp.ts"; export class Event { @@ -12,4 +13,23 @@ export class Event { this.participants = participants; } + public getName() : string { + return this.name; + } + + public getToken() : string { + return this.token; + } + + public getParticipants() : Participant[] { + return this.participants; + } + } + +export interface EventState { + name : String + token : String + participants: ParticipantState[]; +} + diff --git a/front/src/models/Participant.ts b/front/src/models/Participant.ts index 226ebeb..f40d287 100644 --- a/front/src/models/Participant.ts +++ b/front/src/models/Participant.ts @@ -1,4 +1,4 @@ -import type {TimeStamp} from "@/models/TimeStamp.ts"; +import type {TimeStamp, TimeStampState} from "@/models/TimeStamp.ts"; export class Participant { @@ -10,4 +10,16 @@ export class Participant { this.dates = dates; } + public getName(){ + return this.name; + } + + public getDate() : TimeStamp[]{ + return this.dates; + } +} + +export interface ParticipantState { + name : String + dates : TimeStampState[] } diff --git a/front/src/models/TimeStamp.ts b/front/src/models/TimeStamp.ts index 5aa23bb..c42151c 100644 --- a/front/src/models/TimeStamp.ts +++ b/front/src/models/TimeStamp.ts @@ -10,3 +10,7 @@ export class TimeStamp { return this.value; } } + +export interface TimeStampState { + value : number; +} diff --git a/front/src/requests/EventRequests.ts b/front/src/requests/EventRequests.ts index 5b484ad..207f45d 100644 --- a/front/src/requests/EventRequests.ts +++ b/front/src/requests/EventRequests.ts @@ -1,4 +1,5 @@ -import { API_PATHS } from "@/config/ApiConfig.ts"; +import {API_PATHS} from "@/config/ApiConfig.ts"; +import {EventDto} from "@/dto/EventDto.ts"; export class EventRequests { @@ -12,22 +13,18 @@ export class EventRequests { private formatUrl(parts:string[]) : string { let res = ""; - console.log(parts) parts.forEach((value) => { - console.log(value) res += value.trim(); }) - return res.replace(/(http|https?:\/\/[^\/]+)\/\//, '$1/'); + return res.replace(/([^:]\/)\/+/g, "$1"); } - public queryEvent(token : string) { + public async queryEvent(token : string): Promise { let url = this.formatUrl([this.baseUrl, this.endpoints.EVENTS, token]); - console.log(url); - fetch(url) + return fetch(url) .then(response => response.json()) - .then(data => console.log(data)) + .then(data => new EventDto(data.name, data.token, data.participants)) .catch(error => console.error(error)); - } } diff --git a/front/src/router/index.ts b/front/src/router/index.ts index 452a990..97edbf3 100644 --- a/front/src/router/index.ts +++ b/front/src/router/index.ts @@ -9,13 +9,13 @@ import EventView from "@/views/EventView.vue"; const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes: [ - { path: '/', name: 'home', component: HomeView}, - { path: '/about', name: 'about', component: AboutView}, - { path: '/create', name: 'create', component: CreateView}, - { path: '/join', name: 'join', component: JoinView}, - { path: '/event', name: 'event', component: EventView}, - { path: '/error', name: 'error', component: ErrorView}, - { path: '/:pathMatch(.*)*', component: ErrorView } + { path: '/', name: 'home', component: HomeView}, + { path: '/about', name: 'about', component: AboutView}, + { path: '/create', name: 'create', component: CreateView}, + { path: '/join', name: 'join', component: JoinView}, + { path: '/event/:token', name: 'event', component: EventView}, + { path: '/error', name: 'error', component: ErrorView}, + { path: '/:pathMatch(.*)*', component: ErrorView } ] }) diff --git a/front/src/stores/EventStore.ts b/front/src/stores/EventStore.ts index 7bae744..e44ebe9 100644 --- a/front/src/stores/EventStore.ts +++ b/front/src/stores/EventStore.ts @@ -1,18 +1,44 @@ -import { defineStore } from 'pinia' +import {defineStore} from 'pinia' import {EventRequests} from "@/requests/EventRequests.ts"; +import type {EventDto} from "@/dto/EventDto.ts"; +import type {EventState} from "@/models/Event.ts"; +import type {ParticipantDto} from "@/dto/ParticipantDto.ts"; +import type {ParticipantState} from "@/models/Participant.ts"; +import type {TimeStamp, TimeStampState} from "@/models/TimeStamp.ts"; +import type {TimeStampDto} from "@/dto/TimeStampDto.ts"; const requests = new EventRequests(); -export const eventStore = defineStore('datePicker', { - state: () => { +export const eventStore = defineStore('eventStore', { + state: (): {event : EventState} => { return { - event: Event + event : { + name: "", + token: "", + participants: [] as ParticipantState[] + }}; + }, + getters : { + getEvent() { } }, - actions: { - fetch: (token : string) => { - requests.queryEvent(token); - } + async fetch(token: string): Promise { + try{ + let data : EventDto | void = await requests.queryEvent(token); + if(!data) throw new Error("No event found"); + this.event.name = data.name; + this.event.token = data.token; + + this.event.participants = data.participants.map((p: ParticipantDto) => ({ + name: p.name, + dates: p.dates.map((date: TimeStampDto) => ({ + value: date.timestamp + })) as TimeStampState[] + })); + } catch (error) { + console.error("Unable to fetch. " + error); + } + }, }, -}) +}); diff --git a/front/src/views/CreateView.vue b/front/src/views/CreateView.vue index a9a5ff6..ca7efb3 100644 --- a/front/src/views/CreateView.vue +++ b/front/src/views/CreateView.vue @@ -13,7 +13,7 @@ import NavLink from "@/components/NavLink.vue";
- +
diff --git a/front/src/views/EventView.vue b/front/src/views/EventView.vue index 85af715..3b5b6cc 100644 --- a/front/src/views/EventView.vue +++ b/front/src/views/EventView.vue @@ -1,9 +1,33 @@