1 | package edu.gjoko.schedlr.mappers;
|
---|
2 |
|
---|
3 | import edu.gjoko.schedlr.dto.AppointmentDto;
|
---|
4 | import edu.gjoko.schedlr.dto.ReviewDto;
|
---|
5 | import edu.gjoko.schedlr.entity.Appointment;
|
---|
6 | import edu.gjoko.schedlr.entity.Review;
|
---|
7 | import org.modelmapper.ModelMapper;
|
---|
8 | import org.modelmapper.TypeMap;
|
---|
9 | import org.modelmapper.config.Configuration;
|
---|
10 | import org.springframework.stereotype.Service;
|
---|
11 |
|
---|
12 | @Service
|
---|
13 | public 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 | }
|
---|