diff --git a/src/main/java/org/springframework/samples/petclinic/mapper/OwnerMapper.java b/src/main/java/org/springframework/samples/petclinic/mapper/OwnerMapper.java index 04e679c2..5acb8a19 100755 --- a/src/main/java/org/springframework/samples/petclinic/mapper/OwnerMapper.java +++ b/src/main/java/org/springframework/samples/petclinic/mapper/OwnerMapper.java @@ -1,8 +1,9 @@ package org.springframework.samples.petclinic.mapper; import org.mapstruct.Mapper; -import org.springframework.samples.petclinic.rest.dto.OwnerDto; +import org.mapstruct.Mapping; import org.springframework.samples.petclinic.model.Owner; +import org.springframework.samples.petclinic.rest.dto.OwnerDto; import org.springframework.samples.petclinic.rest.dto.OwnerFieldsDto; import java.util.Collection; @@ -18,6 +19,8 @@ public interface OwnerMapper { Owner toOwner(OwnerDto ownerDto); + @Mapping(target = "id", ignore = true) + @Mapping(target = "pets", ignore = true) Owner toOwner(OwnerFieldsDto ownerDto); List toOwnerDtoCollection(Collection ownerCollection); diff --git a/src/main/java/org/springframework/samples/petclinic/mapper/PetMapper.java b/src/main/java/org/springframework/samples/petclinic/mapper/PetMapper.java index 1270af8d..ae161009 100755 --- a/src/main/java/org/springframework/samples/petclinic/mapper/PetMapper.java +++ b/src/main/java/org/springframework/samples/petclinic/mapper/PetMapper.java @@ -2,18 +2,18 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; +import org.springframework.samples.petclinic.model.Pet; +import org.springframework.samples.petclinic.model.PetType; import org.springframework.samples.petclinic.rest.dto.PetDto; import org.springframework.samples.petclinic.rest.dto.PetFieldsDto; import org.springframework.samples.petclinic.rest.dto.PetTypeDto; -import org.springframework.samples.petclinic.model.Pet; -import org.springframework.samples.petclinic.model.PetType; import java.util.Collection; /** * Map Pet & PetDto using mapstruct */ -@Mapper +@Mapper(uses = VisitMapper.class) public interface PetMapper { @Mapping(source = "owner.id", target = "ownerId") @@ -26,6 +26,9 @@ public interface PetMapper { @Mapping(source = "ownerId", target = "owner.id") Pet toPet(PetDto petDto); + @Mapping(target = "id", ignore = true) + @Mapping(target = "owner", ignore = true) + @Mapping(target = "visits", ignore = true) Pet toPet(PetFieldsDto petFieldsDto); PetTypeDto toPetTypeDto(PetType petType); diff --git a/src/main/java/org/springframework/samples/petclinic/mapper/PetTypeMapper.java b/src/main/java/org/springframework/samples/petclinic/mapper/PetTypeMapper.java index 05617161..efb6d60b 100644 --- a/src/main/java/org/springframework/samples/petclinic/mapper/PetTypeMapper.java +++ b/src/main/java/org/springframework/samples/petclinic/mapper/PetTypeMapper.java @@ -1,8 +1,9 @@ package org.springframework.samples.petclinic.mapper; import org.mapstruct.Mapper; -import org.springframework.samples.petclinic.rest.dto.PetTypeDto; +import org.mapstruct.Mapping; import org.springframework.samples.petclinic.model.PetType; +import org.springframework.samples.petclinic.rest.dto.PetTypeDto; import org.springframework.samples.petclinic.rest.dto.PetTypeFieldsDto; import java.util.Collection; @@ -16,6 +17,7 @@ public interface PetTypeMapper { PetType toPetType(PetTypeDto petTypeDto); + @Mapping(target = "id", ignore = true) PetType toPetType(PetTypeFieldsDto petTypeFieldsDto); PetTypeDto toPetTypeDto(PetType petType); diff --git a/src/main/java/org/springframework/samples/petclinic/mapper/UserMapper.java b/src/main/java/org/springframework/samples/petclinic/mapper/UserMapper.java index 718e5410..2b5aea0f 100644 --- a/src/main/java/org/springframework/samples/petclinic/mapper/UserMapper.java +++ b/src/main/java/org/springframework/samples/petclinic/mapper/UserMapper.java @@ -1,10 +1,11 @@ package org.springframework.samples.petclinic.mapper; import org.mapstruct.Mapper; -import org.springframework.samples.petclinic.rest.dto.RoleDto; -import org.springframework.samples.petclinic.rest.dto.UserDto; +import org.mapstruct.Mapping; import org.springframework.samples.petclinic.model.Role; import org.springframework.samples.petclinic.model.User; +import org.springframework.samples.petclinic.rest.dto.RoleDto; +import org.springframework.samples.petclinic.rest.dto.UserDto; import java.util.Collection; @@ -13,6 +14,9 @@ */ @Mapper public interface UserMapper { + + @Mapping(target = "id", ignore = true) + @Mapping(target = "user", ignore = true) Role toRole(RoleDto roleDto); RoleDto toRoleDto(Role role); diff --git a/src/main/java/org/springframework/samples/petclinic/mapper/VetMapper.java b/src/main/java/org/springframework/samples/petclinic/mapper/VetMapper.java index 3c25e514..fdcab6cd 100644 --- a/src/main/java/org/springframework/samples/petclinic/mapper/VetMapper.java +++ b/src/main/java/org/springframework/samples/petclinic/mapper/VetMapper.java @@ -1,8 +1,9 @@ package org.springframework.samples.petclinic.mapper; import org.mapstruct.Mapper; -import org.springframework.samples.petclinic.rest.dto.VetDto; +import org.mapstruct.Mapping; import org.springframework.samples.petclinic.model.Vet; +import org.springframework.samples.petclinic.rest.dto.VetDto; import org.springframework.samples.petclinic.rest.dto.VetFieldsDto; import java.util.Collection; @@ -14,6 +15,7 @@ public interface VetMapper { Vet toVet(VetDto vetDto); + @Mapping(target = "id", ignore = true) Vet toVet(VetFieldsDto vetFieldsDto); VetDto toVetDto(Vet vet); diff --git a/src/main/java/org/springframework/samples/petclinic/mapper/VisitMapper.java b/src/main/java/org/springframework/samples/petclinic/mapper/VisitMapper.java index 7960c6d2..98dc2db9 100644 --- a/src/main/java/org/springframework/samples/petclinic/mapper/VisitMapper.java +++ b/src/main/java/org/springframework/samples/petclinic/mapper/VisitMapper.java @@ -2,8 +2,8 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.springframework.samples.petclinic.rest.dto.VisitDto; import org.springframework.samples.petclinic.model.Visit; +import org.springframework.samples.petclinic.rest.dto.VisitDto; import org.springframework.samples.petclinic.rest.dto.VisitFieldsDto; import java.util.Collection; @@ -16,6 +16,8 @@ public interface VisitMapper { @Mapping(source = "petId", target = "pet.id") Visit toVisit(VisitDto visitDto); + @Mapping(target = "id", ignore = true) + @Mapping(target = "pet", ignore = true) Visit toVisit(VisitFieldsDto visitFieldsDto); @Mapping(source = "pet.id", target = "petId")