File tree Expand file tree Collapse file tree
src/main/java/com/sundorius/microservices Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .sundorius .microservices .config ;
2+
3+ import org .modelmapper .ModelMapper ;
4+ import org .modelmapper .convention .MatchingStrategies ;
5+ import org .springframework .context .annotation .Bean ;
6+ import org .springframework .context .annotation .Configuration ;
7+
8+ @ Configuration
9+ public class MapperConfig
10+ {
11+ @ Bean
12+ public ModelMapper modelMapper ()
13+ {
14+ ModelMapper modelMapper = new ModelMapper ();
15+ modelMapper .getConfiguration ().setMatchingStrategy (MatchingStrategies .LOOSE );
16+ return modelMapper ;
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ package com .sundorius .microservices .mappers ;
2+
3+ public interface Mapper <A ,B >
4+ {
5+ B mapTo (A a );
6+
7+ A mapFrom (B b );
8+ }
Original file line number Diff line number Diff line change 1+ package com .sundorius .microservices .mappers .impl ;
2+
3+ import com .sundorius .microservices .domain .dto .CarDto ;
4+ import com .sundorius .microservices .domain .enitities .CarEntity ;
5+ import com .sundorius .microservices .mappers .Mapper ;
6+ import org .modelmapper .ModelMapper ;
7+ import org .springframework .stereotype .Component ;
8+
9+ @ Component
10+ public class CarMapperImpl implements Mapper <CarEntity , CarDto >
11+ {
12+ private ModelMapper modelMapper ;
13+
14+ public CarMapperImpl (ModelMapper modelMapper )
15+ {
16+ this .modelMapper = modelMapper ;
17+ }
18+
19+ @ Override
20+ public CarDto mapTo (CarEntity carEntity )
21+ {
22+ return modelMapper .map (carEntity , CarDto .class );
23+ }
24+
25+ @ Override
26+ public CarEntity mapFrom (CarDto carDto )
27+ {
28+ return modelMapper .map (carDto , CarEntity .class );
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ package com .sundorius .microservices .mappers .impl ;
2+
3+ import com .sundorius .microservices .domain .dto .WarehouseDto ;
4+ import com .sundorius .microservices .domain .enitities .WarehouseEntity ;
5+ import com .sundorius .microservices .mappers .Mapper ;
6+ import org .modelmapper .ModelMapper ;
7+ import org .springframework .stereotype .Component ;
8+
9+ @ Component
10+ public class WarehouseMapperImpl implements Mapper <WarehouseEntity , WarehouseDto >
11+ {
12+ private ModelMapper modelMapper ;
13+
14+ public WarehouseMapperImpl (ModelMapper modelMapper )
15+ {
16+ this .modelMapper = modelMapper ;
17+ }
18+
19+ @ Override
20+ public WarehouseDto mapTo (WarehouseEntity warehouseEntity )
21+ {
22+ return modelMapper .map (warehouseEntity , WarehouseDto .class );
23+ }
24+
25+ @ Override
26+ public WarehouseEntity mapFrom (WarehouseDto warehouseDto )
27+ {
28+ return modelMapper .map (warehouseDto , WarehouseEntity .class );
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments