mirror of
https://github.com/PaulReichmuth/timekeep-backend.git
synced 2025-12-22 22:41:59 +00:00
refactor passedStations and members to be of type List instead of Map, as a key is not needed
This commit is contained in:
@@ -4,54 +4,55 @@ import de.pnreichmuth.timekeep_backend.entities.Racer;
|
|||||||
import de.pnreichmuth.timekeep_backend.entities.Station;
|
import de.pnreichmuth.timekeep_backend.entities.Station;
|
||||||
import de.pnreichmuth.timekeep_backend.entities.Team;
|
import de.pnreichmuth.timekeep_backend.entities.Team;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public record TeamWSTO(String teamName,
|
public record TeamWSTO(String teamName,
|
||||||
boolean firstSemesterTeam,
|
boolean firstSemesterTeam,
|
||||||
Map<String, RacerWSTO> teamMembers,
|
List<RacerWSTO> teamMembers,
|
||||||
Map<String, StationWSTO> passedStations) {
|
List<StationWSTO> passedStations) {
|
||||||
public TeamWSTO{
|
public TeamWSTO{
|
||||||
Objects.requireNonNull(teamName, "Cannot identify Team without a name");
|
Objects.requireNonNull(teamName, "Cannot identify Team without a name");
|
||||||
teamMembers = Map.copyOf(teamMembers);
|
teamMembers = List.copyOf(teamMembers);
|
||||||
passedStations = Map.copyOf(passedStations);
|
passedStations = List.copyOf(passedStations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TeamWSTO of(Team team){
|
public static TeamWSTO of(Team team){
|
||||||
Map<String, RacerWSTO> tmpMemberMap = new HashMap<>();
|
List<RacerWSTO> tempMemberList = new ArrayList<>();
|
||||||
for(Map.Entry<String, Racer> member : team.getMembers().entrySet()){
|
team.getMembers().forEach(member -> {
|
||||||
tmpMemberMap.put(member.getKey(), RacerWSTO.of(member.getValue()));
|
tempMemberList.add(RacerWSTO.of(member));
|
||||||
}
|
});
|
||||||
|
|
||||||
|
List<StationWSTO> tempStationList = new ArrayList<>();
|
||||||
|
team.getPassedStations().forEach(passedStation -> {
|
||||||
|
tempStationList.add(StationWSTO.of(passedStation));
|
||||||
|
});
|
||||||
|
|
||||||
Map<String, StationWSTO> tmpStationMap = new HashMap<>();
|
|
||||||
for(Map.Entry<String,Station> station : team.getPassedStations().entrySet()){
|
|
||||||
tmpStationMap.put(station.getKey(), StationWSTO.of(station.getValue()));
|
|
||||||
}
|
|
||||||
return new TeamWSTO(
|
return new TeamWSTO(
|
||||||
team.getTeamName(),
|
team.getTeamName(),
|
||||||
team.isFirstSemesterTeam(),
|
team.isFirstSemesterTeam(),
|
||||||
Map.copyOf(tmpMemberMap),
|
List.copyOf(tempMemberList),
|
||||||
Map.copyOf(tmpStationMap)
|
List.copyOf(tempStationList)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Team toEntity(TeamWSTO teamWSTO){
|
public static Team toEntity(TeamWSTO teamWSTO){
|
||||||
Map<String, Racer> tmpMemberMap = new HashMap<>();
|
List<Racer> tempMemberList = new ArrayList<>();
|
||||||
for(Map.Entry<String, RacerWSTO> member : teamWSTO.teamMembers().entrySet()){
|
teamWSTO.teamMembers().forEach(member -> {
|
||||||
tmpMemberMap.put(member.getKey(), RacerWSTO.toEntity(member.getValue()));
|
tempMemberList.add(RacerWSTO.toEntity(member));
|
||||||
}
|
});
|
||||||
|
|
||||||
Map<String, Station> tmpStationMap = new HashMap<>();
|
List<Station> tempStationList = new ArrayList<>();
|
||||||
for (Map.Entry<String, StationWSTO> station : teamWSTO.passedStations().entrySet()) {
|
teamWSTO.passedStations().forEach(passedStation -> {
|
||||||
tmpStationMap.put(station.getKey(), StationWSTO.toEntity(station.getValue()));
|
tempStationList.add(StationWSTO.toEntity(passedStation));
|
||||||
}
|
});
|
||||||
|
|
||||||
return new Team(
|
return new Team(
|
||||||
teamWSTO.teamName(),
|
teamWSTO.teamName(),
|
||||||
teamWSTO.firstSemesterTeam(),
|
teamWSTO.firstSemesterTeam(),
|
||||||
tmpMemberMap,
|
tempMemberList,
|
||||||
tmpStationMap
|
tempStationList
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user