Skip to content

Commit

Permalink
🚧 modify conference service to produce sample data
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Fihlon <[email protected]>
  • Loading branch information
McPringle committed Mar 25, 2024
1 parent 9ceb168 commit fb207a2
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 5 deletions.
43 changes: 38 additions & 5 deletions src/main/java/swiss/fihlon/apus/service/ConferenceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,47 @@
package swiss.fihlon.apus.service;

import org.springframework.stereotype.Service;
import swiss.fihlon.apus.conference.Session;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Service
public class ConferenceService implements Serializable {
public final class ConferenceService {

@Serial
private static final long serialVersionUID = -5273205444017934528L;
private final List<Session> sessions;

public ConferenceService() {
sessions = new ArrayList<>(100);

for (int counter = 0; counter < 100; counter++) {
final String id = UUID.randomUUID().toString();
final LocalDateTime startDate = LocalDateTime.now()
.plusMinutes(Math.round(counter / 3f + 0.5f)) // 3 sessions start each minute
.truncatedTo(ChronoUnit.SECONDS)
.withSecond(0);
final LocalDateTime endDate = startDate.plusMinutes(1);
final String title = "Test Session #" + counter;
final String speaker = "Speaker #" + counter;
sessions.add(new Session(id, startDate, endDate, title, speaker));
}
}

public List<Session> getRunningSessions() {
final LocalDateTime now = LocalDateTime.now();
return sessions.stream()
.filter(session -> session.startDate().isBefore(now) && session.endDate().isAfter(now))
.toList();
}

public List<Session> getFutureSessions() {
final LocalDateTime now = LocalDateTime.now();
return sessions.stream()
.filter(session -> session.startDate().isAfter(now))
.toList();
}

}
35 changes: 35 additions & 0 deletions src/test/java/swiss/fihlon/apus/service/ConferenceServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package swiss.fihlon.apus.service;

import org.junit.jupiter.api.Test;
import swiss.fihlon.apus.conference.Session;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

class ConferenceServiceTest {

@Test
void getSessions() {
final ConferenceService conferenceService = new ConferenceService();
final List<Session> sessions = conferenceService.getFutureSessions();
assertEquals(100, sessions.size());
}
}

0 comments on commit fb207a2

Please sign in to comment.