Last change
on this file was 77205be, checked in by gjoko kostadinov <gjokokostadinov@…>, 9 months ago |
Add entire code
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | package edu.gjoko.schedlr.mappers;
|
---|
2 |
|
---|
3 | import edu.gjoko.schedlr.dto.AppointmentDto;
|
---|
4 | import edu.gjoko.schedlr.entity.Appointment;
|
---|
5 | import org.modelmapper.Condition;
|
---|
6 | import org.modelmapper.ModelMapper;
|
---|
7 | import org.modelmapper.TypeMap;
|
---|
8 | import org.modelmapper.config.Configuration;
|
---|
9 | import org.springframework.stereotype.Service;
|
---|
10 |
|
---|
11 | @Service
|
---|
12 | public 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.