source: src/main/java/edu/gjoko/schedlr/mappers/AppointmentDtoMapper.java@ 77205be

Last change on this file since 77205be was 77205be, checked in by gjoko kostadinov <gjokokostadinov@…>, 6 months ago

Add entire code

  • Property mode set to 100644
File size: 1.1 KB
Line 
1package edu.gjoko.schedlr.mappers;
2
3import edu.gjoko.schedlr.dto.AppointmentDto;
4import edu.gjoko.schedlr.entity.Appointment;
5import org.modelmapper.Condition;
6import org.modelmapper.ModelMapper;
7import org.modelmapper.TypeMap;
8import org.modelmapper.config.Configuration;
9import org.springframework.stereotype.Service;
10
11@Service
12public class AppointmentDtoMapper extends ModelMapper {
13
14 public AppointmentDtoMapper() {
15 this.getConfiguration().setFieldMatchingEnabled(true).setFieldAccessLevel(Configuration.AccessLevel.PRIVATE);
16 TypeMap<Appointment, AppointmentDto> propertyMapper = this.createTypeMap(Appointment.class, AppointmentDto.class);
17 Condition<String, String> hasTitle = ctx -> ctx.getSource() != null;
18 propertyMapper.addMappings(
19 mapper -> mapper.when(hasTitle).map(appointment -> appointment.getService().getServiceType().getName(), AppointmentDto::setTitle)
20 );
21 }
22 public AppointmentDto appointmentToAppointmentDto(Appointment appointment) {
23 return this.map(appointment, AppointmentDto.class);
24 }
25}
Note: See TracBrowser for help on using the repository browser.