Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correcting MapStruct mappings. (issue #157) #176

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<OwnerDto> toOwnerDtoCollection(Collection<Owner> ownerCollection);
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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")