Files
swiss-backend/src/main/java/nl/connectedit/swiss/mapper/StandingsMapper.java
2024-10-12 13:37:59 +02:00

43 lines
1.5 KiB
Java

package nl.connectedit.swiss.mapper;
import java.util.Iterator;
import java.util.List;
import lombok.RequiredArgsConstructor;
import nl.connectedit.swiss.dto.StandingsDto;
import nl.connectedit.swiss.dto.StandingsEntry;
import nl.connectedit.swiss.dto.StandingsEntryDto;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class StandingsMapper {
private final TeamMapper teamMapper;
public StandingsDto toDto(List<StandingsEntry> standings) {
var standingsDto = new StandingsDto();
Long position = 1L;
for (Iterator<StandingsEntry> i = standings.iterator(); i.hasNext(); position++ ) {
standingsDto.getEntries().add(toDto(i.next(), position));
}
return standingsDto;
}
private StandingsEntryDto toDto(StandingsEntry standingsEntry, Long position) {
var standingsEntryDto = new StandingsEntryDto();
standingsEntryDto.setPosition(position);
standingsEntryDto.setTeam(teamMapper.toDto(standingsEntry.getTeam()));
standingsEntryDto.setPlayed(standingsEntry.getPlayed());
standingsEntryDto.setWon(standingsEntry.getWon());
standingsEntryDto.setLost(standingsEntry.getLost());
standingsEntryDto.setPoints(standingsEntry.getPoints());
standingsEntryDto.setGamesWon(standingsEntry.getGamesWon());
standingsEntryDto.setGamesLost(standingsEntry.getGamesLost());
standingsEntryDto.setPointsWon(standingsEntry.getPointsWon());
standingsEntryDto.setPointsLost(standingsEntry.getPointsLost());
return standingsEntryDto;
}
}