Skip to content

Commit

Permalink
Fix model mapping bug where ChapterEntity.id is erroneously set.
Browse files Browse the repository at this point in the history
  • Loading branch information
myluki2000 committed Dec 4, 2024
1 parent 784331c commit b8bf9e1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,7 @@
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class ChapterService {

private final ChapterMapper chapterMapper;
Expand Down

0 comments on commit b8bf9e1

Please sign in to comment.