From df0bccff2ce777e4e6544e9edabc0d3b84b54818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Camblor?= Date: Thu, 31 Oct 2024 00:00:53 +0100 Subject: [PATCH] #74 introduced otherSpeakers in lineup talk firestore model + provided voxxrin model mappers for lineup speakers/talks --- cloud/functions/src/models/Event.ts | 1 + mobile/src/models/VoxxrinSpeaker.ts | 59 +++++++++++++++++++++++++++++ mobile/src/models/VoxxrinTalk.ts | 9 +---- shared/event-lineup.firestore.d.ts | 1 + 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/cloud/functions/src/models/Event.ts b/cloud/functions/src/models/Event.ts index 459ff060..8438c10b 100644 --- a/cloud/functions/src/models/Event.ts +++ b/cloud/functions/src/models/Event.ts @@ -50,6 +50,7 @@ export function detailedTalksToSpeakersLineup(talks: DetailedTalk[]): LineupSpea start: talk.start, end: talk.end, }, + otherSpeakers: talk.speakers.filter(sp => sp.id !== speaker.id), }) }) return speakers; diff --git a/mobile/src/models/VoxxrinSpeaker.ts b/mobile/src/models/VoxxrinSpeaker.ts index 3acf540e..27e8191b 100644 --- a/mobile/src/models/VoxxrinSpeaker.ts +++ b/mobile/src/models/VoxxrinSpeaker.ts @@ -1,7 +1,66 @@ import {ValueObject} from "@/models/utils"; import {Speaker} from "../../../shared/daily-schedule.firestore"; import {Replace} from "../../../shared/type-utils"; +import {LineupSpeaker, LineupTalk} from "../../../shared/event-lineup.firestore"; +import {TalkId} from "@/models/VoxxrinTalk"; +import {RoomId, VoxxrinRoom} from "@/models/VoxxrinRoom"; +import {findRoom, findTalkFormat, findTrack, VoxxrinConferenceDescriptor} from "@/models/VoxxrinConferenceDescriptor"; +import {match, P} from "ts-pattern"; +import {TalkFormatId, VoxxrinTalkFormat} from "@/models/VoxxrinTalkFormat"; +import {TrackId, VoxxrinTrack} from "@/models/VoxxrinTrack"; export class SpeakerId extends ValueObject{ _speakerIdClassDiscriminator!: never; } export type VoxxrinDetailedSpeaker = Replace; export type VoxxrinSimpleSpeaker = Omit; + +export type VoxxrinLineupTalk = Replace + +export type VoxxrinLineupSpeaker = Replace + +export const toVoxxrinSpeaker = (speaker: Speaker): VoxxrinSimpleSpeaker => { + return ({ + photoUrl: speaker.photoUrl, + companyName: speaker.companyName, + fullName: speaker.fullName, + id: new SpeakerId(speaker.id) + }) +} + +export const createVoxxrinSpeakerFromFirestore = (conferenceDescriptor: VoxxrinConferenceDescriptor, firestoreSpeaker: LineupSpeaker): VoxxrinLineupSpeaker => { + return { + ...firestoreSpeaker, + id: new SpeakerId(firestoreSpeaker.id), + talks: firestoreSpeaker.talks.map(firestoreTalk => { + const format = findTalkFormat(conferenceDescriptor, new TalkFormatId(firestoreTalk.format.id)); + const track = findTrack(conferenceDescriptor, new TrackId(firestoreTalk.track.id)); + const allocation = match(firestoreTalk.allocation) + .with(P.not(P.nullish), allocation => { + const room = findRoom(conferenceDescriptor, new RoomId(allocation.room.id)); + return { + ...firestoreTalk.allocation, + room + }; + }).otherwise(() => undefined); + + return { + ...firestoreTalk, + id: new TalkId(firestoreTalk.id), + allocation, + format, + track, + otherSpeakers: firestoreTalk.otherSpeakers.map(sp => toVoxxrinSpeaker(sp)), + }; + }) + } +} diff --git a/mobile/src/models/VoxxrinTalk.ts b/mobile/src/models/VoxxrinTalk.ts index 64d76d95..3909caf7 100644 --- a/mobile/src/models/VoxxrinTalk.ts +++ b/mobile/src/models/VoxxrinTalk.ts @@ -1,7 +1,7 @@ import {sortBy, ValueObject} from "@/models/utils"; import {Break, DetailedTalk, Talk, TalkAsset} from "../../../shared/daily-schedule.firestore"; import {RoomId, VoxxrinRoom} from "@/models/VoxxrinRoom"; -import {SpeakerId, VoxxrinDetailedSpeaker, VoxxrinSimpleSpeaker} from "@/models/VoxxrinSpeaker"; +import {SpeakerId, toVoxxrinSpeaker, VoxxrinDetailedSpeaker, VoxxrinSimpleSpeaker} from "@/models/VoxxrinSpeaker"; import {TalkFormatId, VoxxrinTalkFormat} from "@/models/VoxxrinTalkFormat"; import {TrackId, VoxxrinTrack} from "@/models/VoxxrinTrack"; import { @@ -48,12 +48,7 @@ export function createVoxxrinTalkFromFirestore(event: VoxxrinConferenceDescripto const talk: VoxxrinTalk = { language: new TalkLanguageCode(firestoreTalk.language), title: firestoreTalk.title, - speakers: firestoreTalk.speakers.map(sp => ({ - photoUrl: sp.photoUrl, - companyName: sp.companyName, - fullName: sp.fullName, - id: new SpeakerId(sp.id) - })), + speakers: firestoreTalk.speakers.map(sp => toVoxxrinSpeaker(sp)), format, track, room, diff --git a/shared/event-lineup.firestore.d.ts b/shared/event-lineup.firestore.d.ts index 9447214f..70fb41b9 100644 --- a/shared/event-lineup.firestore.d.ts +++ b/shared/event-lineup.firestore.d.ts @@ -13,6 +13,7 @@ export type LineupTalk = { start: ISODatetime, end: ISODatetime, }|undefined, + otherSpeakers: Speaker[], } export type LineupSpeaker = Speaker & {