source: src/main/java/edu/gjoko/schedlr/mappers/ReviewDtoMapper.java

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

Add entire code

  • Property mode set to 100644
File size: 1.4 KB
Line 
1package edu.gjoko.schedlr.mappers;
2
3import edu.gjoko.schedlr.dto.AppointmentDto;
4import edu.gjoko.schedlr.dto.ReviewDto;
5import edu.gjoko.schedlr.entity.Appointment;
6import edu.gjoko.schedlr.entity.Review;
7import org.modelmapper.ModelMapper;
8import org.modelmapper.TypeMap;
9import org.modelmapper.config.Configuration;
10import org.springframework.stereotype.Service;
11
12@Service
13public class ReviewDtoMapper extends ModelMapper {
14
15 public ReviewDtoMapper() {
16 this.getConfiguration().setFieldMatchingEnabled(true).setFieldAccessLevel(Configuration.AccessLevel.PRIVATE);
17 TypeMap<Review, ReviewDto> propertyMapper = this.createTypeMap(Review.class, ReviewDto.class);
18 propertyMapper.addMappings(mapper -> {
19 mapper.map(review -> review.getAppointment().getService().getBusiness().getCompanyName(), ReviewDto::setBusinessName);
20 mapper.map(review -> review.getAppointment().getCustomer().getFullName(), ReviewDto::setCustomerName);
21 mapper.map(review -> review.getAppointment().getService().getServiceType().getName(), ReviewDto::setServiceName);
22 mapper.map(Review::getComment, ReviewDto::setComment);
23 mapper.map(Review::getRating, ReviewDto::setRating);
24 mapper.map(Review::getCreated, ReviewDto::setCreated);
25 }
26 );
27 }
28
29 public ReviewDto mapToReviewDto(Review review) {
30 return this.map(review, ReviewDto.class);
31 }
32}
Note: See TracBrowser for help on using the repository browser.