-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EnsembleTimer and Rotation now store Member objects instead of just M…
…emberIds. This will make the Adapter transformers easier, since they won't have to keep fetching the Member objects from the MemberRepository every time they want to render the member's name. This is OK from "don't hold onto one Aggregate from within another" as EnsembleTimer (and therefore Rotation) are transient Value Objects.
- Loading branch information
Showing
14 changed files
with
169 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 10 additions & 16 deletions
26
src/main/java/com/jitterted/mobreg/adapter/in/web/admin/ParticipantsTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,30 @@ | ||
package com.jitterted.mobreg.adapter.in.web.admin; | ||
|
||
import com.jitterted.mobreg.application.port.MemberRepository; | ||
import com.jitterted.mobreg.domain.EnsembleTimer; | ||
import com.jitterted.mobreg.domain.Member; | ||
import com.jitterted.mobreg.domain.MemberId; | ||
import com.jitterted.mobreg.domain.Rotation; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ParticipantsTransformer { | ||
public static Map<String, List<String>> participantsToRolesAndNames(MemberRepository memberRepository, EnsembleTimer ensembleTimer) { | ||
public static Map<String, List<String>> participantsToRolesAndNames(EnsembleTimer ensembleTimer) { | ||
Map<String, List<String>> rolesToNames = new HashMap<>(); | ||
Rotation rotation = ensembleTimer.rotation(); | ||
mapRoleToNames("Driver", List.of(rotation.driver()), rolesToNames, memberRepository); | ||
mapRoleToNames("Navigator", List.of(rotation.navigator()), rolesToNames, memberRepository); | ||
mapRoleToNames("Next Driver", List.of(rotation.nextDriver()), rolesToNames, memberRepository); | ||
mapRoleToNames("Participant", rotation.restOfParticipants(), rolesToNames, memberRepository); | ||
mapRoleToNames("Driver", List.of(rotation.driver()), rolesToNames); | ||
mapRoleToNames("Navigator", List.of(rotation.navigator()), rolesToNames); | ||
mapRoleToNames("Next Driver", List.of(rotation.nextDriver()), rolesToNames); | ||
mapRoleToNames("Participant", rotation.restOfParticipants(), rolesToNames); | ||
return rolesToNames; | ||
} | ||
|
||
private static void mapRoleToNames(String roleName, | ||
List<MemberId> memberIds, | ||
Map<String, List<String>> rolesToNames, | ||
MemberRepository memberRepository) { | ||
List<String> memberNames = memberIds.stream() | ||
.map(memberId -> memberRepository | ||
.findById(memberId) | ||
.orElseThrow()) | ||
.map(Member::firstName) | ||
.toList(); | ||
List<Member> members, | ||
Map<String, List<String>> rolesToNames) { | ||
List<String> memberNames = members.stream() | ||
.map(Member::firstName) | ||
.toList(); | ||
rolesToNames.put(roleName, memberNames); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.