[f29cd58] | 1 | package edu.gjoko.schedlr.mappers;
|
---|
| 2 |
|
---|
| 3 | import edu.gjoko.schedlr.dto.AppointmentDto;
|
---|
| 4 | import edu.gjoko.schedlr.dto.ServiceDto;
|
---|
| 5 | import edu.gjoko.schedlr.entity.Appointment;
|
---|
| 6 | import org.modelmapper.ModelMapper;
|
---|
| 7 | import org.modelmapper.TypeMap;
|
---|
| 8 | import org.modelmapper.config.Configuration;
|
---|
| 9 | import org.springframework.stereotype.Service;
|
---|
| 10 |
|
---|
| 11 | import java.lang.reflect.Type;
|
---|
| 12 |
|
---|
| 13 | @Service
|
---|
| 14 | public class ServiceDtoMapper extends ModelMapper {
|
---|
| 15 |
|
---|
| 16 | public ServiceDtoMapper() {
|
---|
| 17 | this.getConfiguration().setFieldMatchingEnabled(true).setFieldAccessLevel(Configuration.AccessLevel.PRIVATE);
|
---|
| 18 | TypeMap<edu.gjoko.schedlr.entity.Service, ServiceDto> propertyMapper = this.createTypeMap(edu.gjoko.schedlr.entity.Service.class, ServiceDto.class);
|
---|
| 19 | propertyMapper.addMappings(
|
---|
| 20 | mapper -> mapper.map(service -> service.getBusiness().getCompanyName(), ServiceDto::setBusinessName)
|
---|
| 21 | );
|
---|
| 22 | propertyMapper.addMappings(
|
---|
| 23 | mapper -> mapper.map(service -> service.getServiceType().getName(), ServiceDto::setServiceName)
|
---|
| 24 | );
|
---|
| 25 | propertyMapper.addMappings(
|
---|
| 26 | mapper -> mapper.map(service -> service.getBusiness().getId(), ServiceDto::setBusinessId)
|
---|
| 27 | );
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | public ServiceDto serviceToServiceDto(edu.gjoko.schedlr.entity.Service service) {
|
---|
| 31 | return this.map(service, ServiceDto.class);
|
---|
| 32 | }
|
---|
| 33 | }
|
---|