1 | package edu.gjoko.schedlr.mappers;
|
---|
2 |
|
---|
3 | import edu.gjoko.schedlr.dto.AppointmentInfoDto;
|
---|
4 | import edu.gjoko.schedlr.entity.Appointment;
|
---|
5 | import org.modelmapper.ModelMapper;
|
---|
6 | import org.modelmapper.TypeMap;
|
---|
7 | import org.modelmapper.config.Configuration;
|
---|
8 | import org.springframework.stereotype.Service;
|
---|
9 |
|
---|
10 | @Service
|
---|
11 | public class AppointmentInfoDtoBusinessMapper extends ModelMapper {
|
---|
12 |
|
---|
13 | public AppointmentInfoDtoBusinessMapper() {
|
---|
14 | this.getConfiguration().setFieldMatchingEnabled(true).setFieldAccessLevel(Configuration.AccessLevel.PRIVATE);
|
---|
15 | TypeMap<Appointment, AppointmentInfoDto> propertyMapper = this.createTypeMap(Appointment.class, AppointmentInfoDto.class);
|
---|
16 | propertyMapper.addMappings(
|
---|
17 | mapper -> {
|
---|
18 | mapper.map(Appointment::getId, AppointmentInfoDto::setAppointmentId);
|
---|
19 | mapper.map(appointment -> appointment.getCustomer().getFullName(), AppointmentInfoDto::setFullName);
|
---|
20 | mapper.map(appointment -> appointment.getCustomer().getEmail(), AppointmentInfoDto::setEmail);
|
---|
21 | mapper.map(appointment -> appointment.getCustomer().getPhoneNumber(),AppointmentInfoDto::setPhoneNumber);
|
---|
22 | mapper.map(Appointment::getTimePeriod, AppointmentInfoDto::setTimePeriod);
|
---|
23 | mapper.map(appointment -> appointment.getService().getServiceType().getName(), AppointmentInfoDto::setServiceName);
|
---|
24 | mapper.map(Appointment::getAppointmentStatus, AppointmentInfoDto::setStatus);
|
---|
25 | }
|
---|
26 | );
|
---|
27 | }
|
---|
28 |
|
---|
29 | public AppointmentInfoDto appointmentToAppointmentInfoDto(Appointment appointment) {
|
---|
30 | return this.map(appointment, AppointmentInfoDto.class);
|
---|
31 | }
|
---|
32 | }
|
---|