From b8bf9e1ddbe685413e66813c372540309fa0151b Mon Sep 17 00:00:00 2001 From: myluki2000 Date: Wed, 4 Dec 2024 11:40:53 +0100 Subject: [PATCH] Fix model mapping bug where ChapterEntity.id is erroneously set. --- .../course_service/config/ModelMapperConfiguration.java | 7 ++++++- .../course_service/persistence/mapper/ChapterMapper.java | 1 - .../meitrex/course_service/service/ChapterService.java | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/unistuttgart/iste/meitrex/course_service/config/ModelMapperConfiguration.java b/src/main/java/de/unistuttgart/iste/meitrex/course_service/config/ModelMapperConfiguration.java index 2019ffc..5b669ac 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/course_service/config/ModelMapperConfiguration.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/course_service/config/ModelMapperConfiguration.java @@ -1,6 +1,8 @@ package de.unistuttgart.iste.meitrex.course_service.config; import org.modelmapper.ModelMapper; +import org.modelmapper.convention.MatchingStrategies; +import org.modelmapper.spi.MatchingStrategy; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -12,6 +14,9 @@ public class ModelMapperConfiguration { @Bean public ModelMapper modelMapper() { - return new ModelMapper(); + ModelMapper mapper = new ModelMapper(); + mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); + + return mapper; } } diff --git a/src/main/java/de/unistuttgart/iste/meitrex/course_service/persistence/mapper/ChapterMapper.java b/src/main/java/de/unistuttgart/iste/meitrex/course_service/persistence/mapper/ChapterMapper.java index af1a10d..ef402c7 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/course_service/persistence/mapper/ChapterMapper.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/course_service/persistence/mapper/ChapterMapper.java @@ -20,7 +20,6 @@ public Chapter entityToDto(ChapterEntity chapterEntity) { public ChapterEntity dtoToEntity(CreateChapterInput chapterInput) { ChapterEntity entity = modelMapper.map(chapterInput, ChapterEntity.class); - entity.setCourseId(chapterInput.getCourseId()); return entity; } diff --git a/src/main/java/de/unistuttgart/iste/meitrex/course_service/service/ChapterService.java b/src/main/java/de/unistuttgart/iste/meitrex/course_service/service/ChapterService.java index a9ecad1..e56628b 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/course_service/service/ChapterService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/course_service/service/ChapterService.java @@ -12,6 +12,7 @@ import de.unistuttgart.iste.meitrex.generated.dto.*; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.*; import org.springframework.data.jpa.domain.Specification; import org.springframework.lang.Nullable; @@ -27,6 +28,7 @@ */ @Service @RequiredArgsConstructor +@Slf4j public class ChapterService { private final ChapterMapper chapterMapper;