Added mappers

This commit is contained in:
2023-07-09 15:05:45 +02:00
parent 3e178885b5
commit f799fafaa7
11 changed files with 251 additions and 0 deletions
@@ -0,0 +1,26 @@
package de.twomartens.wahlrecht.mapper.v1;
import de.twomartens.wahlrecht.model.db.Candidate;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.ReportingPolicy;
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface CandidateMapper {
de.twomartens.wahlrecht.model.dto.v1.Candidate mapToExternal(Candidate candidate);
de.twomartens.wahlrecht.model.internal.Candidate mapToInternal(
de.twomartens.wahlrecht.model.dto.v1.Candidate candidate);
de.twomartens.wahlrecht.model.internal.Candidate mapToInternal(Candidate candidate);
@Mapping(target = "id", ignore = true)
@Mapping(target = "created", ignore = true)
@Mapping(target = "lastModified", ignore = true)
Candidate mapToDB(de.twomartens.wahlrecht.model.dto.v1.Candidate candidate);
}
@@ -0,0 +1,26 @@
package de.twomartens.wahlrecht.mapper.v1;
import de.twomartens.wahlrecht.model.db.Constituency;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.ReportingPolicy;
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface ConstituencyMapper {
de.twomartens.wahlrecht.model.dto.v1.Constituency mapToExternal(Constituency constituency);
de.twomartens.wahlrecht.model.internal.Constituency mapToInternal(
de.twomartens.wahlrecht.model.dto.v1.Constituency constituency);
de.twomartens.wahlrecht.model.internal.Constituency mapToInternal(Constituency constituency);
@Mapping(target = "id", ignore = true)
@Mapping(target = "created", ignore = true)
@Mapping(target = "lastModified", ignore = true)
Constituency mapToDB(de.twomartens.wahlrecht.model.dto.v1.Constituency constituency);
}
@@ -0,0 +1,17 @@
package de.twomartens.wahlrecht.mapper.v1;
import de.twomartens.wahlrecht.model.internal.ElectedCandidate;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.ReportingPolicy;
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface ElectedCandidateMapper {
de.twomartens.wahlrecht.model.dto.v1.ElectedCandidate mapToExternal(ElectedCandidate candidate);
ElectedCandidate mapToInternal(de.twomartens.wahlrecht.model.dto.v1.ElectedCandidate candidate);
}
@@ -0,0 +1,17 @@
package de.twomartens.wahlrecht.mapper.v1;
import de.twomartens.wahlrecht.model.internal.Elected;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.ReportingPolicy;
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface ElectedMapper {
de.twomartens.wahlrecht.model.dto.v1.Elected mapToExternal(Elected elected);
Elected mapToInternal(de.twomartens.wahlrecht.model.dto.v1.Elected elected);
}
@@ -0,0 +1,35 @@
package de.twomartens.wahlrecht.mapper.v1;
import de.twomartens.wahlrecht.model.dto.v1.ElectedCandidate;
import de.twomartens.wahlrecht.model.dto.v1.VotingResult;
import de.twomartens.wahlrecht.model.internal.ElectedResult;
import java.util.Collection;
import java.util.Map;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.ReportingPolicy;
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface ElectedResultMapper {
de.twomartens.wahlrecht.model.dto.v1.ElectedResult mapToExternal(ElectedResult result);
Map<VotingResult, Collection<ElectedCandidate>> mapToExternal(
Map<de.twomartens.wahlrecht.model.internal.VotingResult,
Collection<de.twomartens.wahlrecht.model.internal.ElectedCandidate>> value);
Collection<ElectedCandidate> mapToExternal(
Collection<de.twomartens.wahlrecht.model.internal.ElectedCandidate> value);
ElectedResult mapToInternal(de.twomartens.wahlrecht.model.dto.v1.ElectedResult result);
Map<de.twomartens.wahlrecht.model.internal.VotingResult,
Collection<de.twomartens.wahlrecht.model.internal.ElectedCandidate>> mapToInternal(
Map<VotingResult, Collection<ElectedCandidate>> value);
Collection<de.twomartens.wahlrecht.model.internal.ElectedCandidate> mapToInternal(
Collection<ElectedCandidate> value);
}
@@ -0,0 +1,26 @@
package de.twomartens.wahlrecht.mapper.v1;
import de.twomartens.wahlrecht.model.db.Election;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.ReportingPolicy;
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface ElectionMapper {
de.twomartens.wahlrecht.model.dto.v1.Election mapToExternal(Election election);
de.twomartens.wahlrecht.model.internal.Election mapToInternal(
de.twomartens.wahlrecht.model.dto.v1.Election election);
de.twomartens.wahlrecht.model.internal.Election mapToInternal(Election election);
@Mapping(target = "id", ignore = true)
@Mapping(target = "created", ignore = true)
@Mapping(target = "lastModified", ignore = true)
Election mapToDB(de.twomartens.wahlrecht.model.dto.v1.Election election);
}
@@ -0,0 +1,30 @@
package de.twomartens.wahlrecht.mapper.v1;
import de.twomartens.wahlrecht.model.db.Nomination;
import de.twomartens.wahlrecht.model.internal.Candidate;
import java.util.Collection;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.ReportingPolicy;
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface NominationMapper {
de.twomartens.wahlrecht.model.dto.v1.Nomination mapToExternal(Nomination nomination);
de.twomartens.wahlrecht.model.internal.Nomination mapToInternal(
de.twomartens.wahlrecht.model.dto.v1.Nomination nomination);
de.twomartens.wahlrecht.model.internal.Nomination mapToInternal(Nomination nomination);
@Mapping(target = "id", ignore = true)
@Mapping(target = "created", ignore = true)
@Mapping(target = "lastModified", ignore = true)
Nomination mapToDB(de.twomartens.wahlrecht.model.dto.v1.Nomination nomination);
Collection<Candidate> map(Collection<de.twomartens.wahlrecht.model.db.Candidate> candidates);
}
@@ -0,0 +1,21 @@
package de.twomartens.wahlrecht.mapper.v1;
import de.twomartens.wahlrecht.model.db.PartyInElection;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.ReportingPolicy;
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface PartyInElectionMapper {
de.twomartens.wahlrecht.model.dto.v1.PartyInElection mapToExternal(PartyInElection election);
@Mapping(target = "id", ignore = true)
@Mapping(target = "created", ignore = true)
@Mapping(target = "lastModified", ignore = true)
PartyInElection mapToDB(de.twomartens.wahlrecht.model.dto.v1.PartyInElection election);
}
@@ -0,0 +1,19 @@
package de.twomartens.wahlrecht.mapper.v1;
import de.twomartens.wahlrecht.model.internal.SeatResult;
import java.util.Deque;
import java.util.LinkedList;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.ReportingPolicy;
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface SeatResultMapper {
de.twomartens.wahlrecht.model.dto.v1.SeatResult mapToExternal(SeatResult result);
SeatResult mapToInternal(de.twomartens.wahlrecht.model.dto.v1.SeatResult result);
}
@@ -0,0 +1,17 @@
package de.twomartens.wahlrecht.mapper.v1;
import de.twomartens.wahlrecht.model.internal.VotingResult;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.ReportingPolicy;
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface VotingResultMapper {
de.twomartens.wahlrecht.model.dto.v1.VotingResult mapToExternal(VotingResult result);
VotingResult mapToInternal(de.twomartens.wahlrecht.model.dto.v1.VotingResult result);
}
@@ -0,0 +1,17 @@
package de.twomartens.wahlrecht.mapper.v1;
import de.twomartens.wahlrecht.model.internal.VotingThreshold;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.ReportingPolicy;
@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface VotingThresholdMapper {
de.twomartens.wahlrecht.model.dto.v1.VotingThreshold mapToExternal(VotingThreshold threshold);
VotingThreshold mapToInternal(de.twomartens.wahlrecht.model.dto.v1.VotingThreshold threshold);
}