diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/Mapper/DTOMapper.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/Mapper/DTOMapper.java index 43b3f50..c01429a 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/Mapper/DTOMapper.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/Mapper/DTOMapper.java @@ -14,7 +14,7 @@ import io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Thermometer; import org.modelmapper.ModelMapper; import org.modelmapper.TypeMap; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.stream.Collectors; @@ -22,38 +22,31 @@ /** * Class responsible for mapping model objects to DTOs */ -@Component +@Service public class DTOMapper { - private static final HashMap, Class> CLASS_TO_DTO; - private static final HashMap, Class> DTO_TO_CLASS; + private final HashMap, Class> CLASS_TO_DTO = new HashMap<>(); + private final HashMap, Class> DTO_TO_CLASS = new HashMap<>(); - static { - CLASS_TO_DTO = new HashMap<>(); + private final ModelMapper modelMapper; + + /** + * Constructs DTOMapper for all instances of the House interface + * + * @param modelMapper instance of ModelMapper + */ + public DTOMapper(ModelMapper modelMapper) { CLASS_TO_DTO.put(Device.class, DeviceDTO.class); CLASS_TO_DTO.put(Fireplace.class, FireplaceDTO.class); CLASS_TO_DTO.put(Door.class, DoorDTO.class); CLASS_TO_DTO.put(Thermometer.class, ThermometerDTO.class); CLASS_TO_DTO.put(RGBLight.class, RGBLightDTO.class); - } - static { - DTO_TO_CLASS = new HashMap<>(); DTO_TO_CLASS.put(DeviceDTO.class, Device.class); DTO_TO_CLASS.put(FireplaceDTO.class, Fireplace.class); DTO_TO_CLASS.put(DoorDTO.class, Door.class); DTO_TO_CLASS.put(ThermometerDTO.class, Thermometer.class); DTO_TO_CLASS.put(RGBLightDTO.class, RGBLight.class); - } - - private final ModelMapper modelMapper; - - /** - * Constructs DTOMapper for all instances of the House interface - * - * @param modelMapper instance of ModelMapper - */ - public DTOMapper(ModelMapper modelMapper) { this.modelMapper = modelMapper; final TypeMap fireplaceTypeMap = this.modelMapper