From 63c4527dcdfb2b8d055d97ea68fb42b47de8f0ed Mon Sep 17 00:00:00 2001 From: Marcus Fihlon Date: Sat, 30 Mar 2024 20:06:51 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor=20session=20speak?= =?UTF-8?q?er=20to=20be=20a=20list=20of=20speakers=20closes=20#57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../swiss/fihlon/apus/conference/Session.java | 4 +++- .../swiss/fihlon/apus/conference/Speaker.java | 22 +++++++++++++++++++ .../apus/conference/doag/ConferenceAPI.java | 4 ++-- .../fihlon/apus/ui/view/SessionView.java | 14 ++++++++---- 4 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 src/main/java/swiss/fihlon/apus/conference/Speaker.java diff --git a/src/main/java/swiss/fihlon/apus/conference/Session.java b/src/main/java/swiss/fihlon/apus/conference/Session.java index b15d68b..e3aae0e 100644 --- a/src/main/java/swiss/fihlon/apus/conference/Session.java +++ b/src/main/java/swiss/fihlon/apus/conference/Session.java @@ -20,8 +20,10 @@ import org.jetbrains.annotations.NotNull; import java.time.LocalDateTime; +import java.util.List; -public record Session(String id, LocalDateTime startDate, LocalDateTime endDate, String room, String title, String speaker) +public record Session(@NotNull String id, @NotNull LocalDateTime startDate, @NotNull LocalDateTime endDate, + @NotNull String room, @NotNull String title, @NotNull List speakers) implements Comparable { @Override public int compareTo(@NotNull final Session other) { diff --git a/src/main/java/swiss/fihlon/apus/conference/Speaker.java b/src/main/java/swiss/fihlon/apus/conference/Speaker.java new file mode 100644 index 0000000..612eb8d --- /dev/null +++ b/src/main/java/swiss/fihlon/apus/conference/Speaker.java @@ -0,0 +1,22 @@ +/* + * Apus - A social wall for conferences with additional features. + * Copyright (C) Marcus Fihlon and the individual contributors to Apus. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package swiss.fihlon.apus.conference; + +import org.jetbrains.annotations.NotNull; + +public record Speaker(@NotNull String fullName) { } diff --git a/src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java b/src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java index 4936020..1670b20 100644 --- a/src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java +++ b/src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java @@ -23,6 +23,7 @@ import org.json.JSONObject; import swiss.fihlon.apus.conference.Session; import swiss.fihlon.apus.conference.SessionImportException; +import swiss.fihlon.apus.conference.Speaker; import swiss.fihlon.apus.configuration.Configuration; import java.io.IOException; @@ -68,7 +69,6 @@ public List getSessions() { final LocalDate date = LocalDate.parse(day.getString("date")).minus(daysBetween); final JSONObject rooms = day.getJSONObject("rooms"); - @SuppressWarnings("unchecked") final Iterator roomKeys = rooms.keys(); while (roomKeys.hasNext()) { final String room = roomKeys.next(); @@ -100,7 +100,7 @@ public List getSessions() { LocalDateTime.of(date, startTime).plus(duration), room, title, - String.join(", ", speakers)); + speakers.stream().map(Speaker::new).toList()); sessions.add(session); } } diff --git a/src/main/java/swiss/fihlon/apus/ui/view/SessionView.java b/src/main/java/swiss/fihlon/apus/ui/view/SessionView.java index 6175b93..4decd30 100644 --- a/src/main/java/swiss/fihlon/apus/ui/view/SessionView.java +++ b/src/main/java/swiss/fihlon/apus/ui/view/SessionView.java @@ -26,22 +26,25 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import swiss.fihlon.apus.conference.Session; +import swiss.fihlon.apus.conference.Speaker; import java.time.Duration; import java.time.LocalTime; +import java.util.List; +import java.util.stream.Collectors; @CssImport(value = "./themes/apus/views/session-view.css") public final class SessionView extends Div { public SessionView(@NotNull final String room) { - this(room, null, null, null, null); + this(room, null, List.of(), null, null); } public SessionView(@NotNull final Session session) { this( session.room(), session.title(), - session.speaker(), + session.speakers(), session.startDate().toLocalTime(), session.endDate().toLocalTime() ); @@ -49,12 +52,15 @@ public SessionView(@NotNull final Session session) { public SessionView(@NotNull final String room, @Nullable final String title, - @Nullable final String speaker, + @NotNull final List speakers, @Nullable final LocalTime startTime, @Nullable final LocalTime endTime) { addClassName("session-view"); add(new H3(new Text(title == null ? "CLOSED" : title))); - add(new Div(speaker == null ? nbsp() : new Text(String.format("\uD83D\uDC64 %s", speaker)))); + add(new Div(speakers.isEmpty() ? nbsp() : new Text(String.format("\uD83D\uDC64 %s", + speakers.stream() + .map(Speaker::fullName) + .collect(Collectors.joining(", ")))))); add(new Div(new Text(String.format("\uD83D\uDCCD %s", room)))); final var now = LocalTime.now();