Skip to content

Commit

Permalink
Fixed issue #196 - create separate display of any in-progress Ensemble
Browse files Browse the repository at this point in the history
  • Loading branch information
tedyoung committed Jan 31, 2024
1 parent 71b921a commit 56a6184
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 319 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ static Status createStatusFor(Ensemble ensemble, MemberStatus memberStatusForEns
};
}

private static String memberStatusToViewString(Ensemble ensemble, MemberId memberId) {
return ensemble.statusFor(memberId, ZonedDateTime.now())
.toString()
.toLowerCase();
}

private static List<MemberView> transform(MemberService memberService, Stream<MemberId> memberIdStream) {
return memberIdStream
.map(memberService::findById)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.jitterted.mobreg.adapter.in.web.member;

import com.jitterted.mobreg.application.MemberService;
import com.jitterted.mobreg.domain.Ensemble;
import com.jitterted.mobreg.domain.MemberId;

import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Stream;

public record InProgressEnsembleView(String name,
String url,
String startTime,
List<String> participants,
List<String> spectators) {

public static InProgressEnsembleView from(Ensemble ensemble, MemberService memberService) {
return new InProgressEnsembleView(ensemble.name(),
ensemble.meetingLink().toString(),
ensemble.startDateTime()
.toLocalTime()
.format(DateTimeFormatter.ofPattern("hh:mm a")),
namesOf(ensemble.acceptedMembers(), memberService),
namesOf(ensemble.spectators(), memberService));
}

public static List<String> namesOf(Stream<MemberId> memberIds, MemberService memberService) {
return memberIds
.map(memberId -> memberService.findById(memberId).firstName())
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.time.ZonedDateTime;
import java.util.List;
import java.util.Optional;

@Controller
public class MemberController {
Expand Down Expand Up @@ -58,8 +59,13 @@ public String showEnsemblesForUser(Model model,
public void addEnsemblesToModel(Model model, Member member) {
MemberId memberId = member.getId();

List<Ensemble> availableEnsembles = ensembleService.allUpcomingEnsembles(ZonedDateTime.now());
List<EnsembleSummaryView> availableEnsembleSummaryViews = EnsembleSummaryView.from(availableEnsembles, memberId, memberService, EnsembleSortOrder.ASCENDING_ORDER);
Optional<InProgressEnsembleView> inProgressEnsemble =
ensembleService.inProgressEnsemble(ZonedDateTime.now(), memberId)
.map(ensemble -> InProgressEnsembleView.from(ensemble, memberService));
model.addAttribute("inProgressEnsembleViewOptional", inProgressEnsemble);

List<Ensemble> upcomingEnsembles = ensembleService.allUpcomingEnsembles(ZonedDateTime.now());
List<EnsembleSummaryView> availableEnsembleSummaryViews = EnsembleSummaryView.from(upcomingEnsembles, memberId, memberService, EnsembleSortOrder.ASCENDING_ORDER);
model.addAttribute("upcomingEnsembles", availableEnsembleSummaryViews);

List<Ensemble> pastEnsembles = ensembleService.allInThePastFor(memberId, ZonedDateTime.now());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Stream;

import static java.util.function.Predicate.not;

Expand Down Expand Up @@ -102,6 +103,7 @@ public void triggerEnsembleScheduledNotification(Ensemble ensemble) {
LOGGER.info("Done notifying for Ensemble {}", ensemble.name());
}

// TODO: return Stream<> instead of List<>
public List<Ensemble> allEnsembles() {
return ensembleRepository.findAll();
}
Expand Down Expand Up @@ -129,14 +131,25 @@ public List<Ensemble> allUpcomingEnsembles(ZonedDateTime now) {
}

public List<Ensemble> allInThePastFor(MemberId memberId, ZonedDateTime now) {
return allEnsembles()
.stream()
.filter(not(Ensemble::isCanceled))
return allEnsemblesNotCanceled()
.filter(ensemble -> ensemble.isRegistered(memberId))
.filter(ensemble -> ensemble.endTimeIsInThePast(now))
.toList();
}

public Stream<Ensemble> allEnsemblesNotCanceled() {
return allEnsembles()
.stream()
.filter(not(Ensemble::isCanceled));
}

public Optional<Ensemble> inProgressEnsemble(ZonedDateTime now, MemberId memberId) {
return allEnsemblesNotCanceled()
.filter(ensemble -> ensemble.isInProgress(now))
.filter(ensemble -> ensemble.isRegistered(memberId))
.findFirst();
}

public Optional<Ensemble> findById(EnsembleId ensembleId) {
return ensembleRepository.findById(ensembleId);
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/jitterted/mobreg/domain/Ensemble.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ public String toString() {
'}';
}

public boolean isInProgress(ZonedDateTime now) {
return now.isAfter(startDateTime()) && now.isBefore(startDateTime()
.plus(duration));
}

record WhenSpaceRsvp(When when, Space space, Rsvp rsvp) {
// @formatter: off
private static final Map<WhenSpaceRsvp, MemberEnsembleStatus> STATE_TO_STATUS = Map.ofEntries(
Expand Down
Loading

0 comments on commit 56a6184

Please sign in to comment.