| 1 | package com.finki.icare.mapper;
|
|---|
| 2 |
|
|---|
| 3 | import com.finki.icare.dto.TherapistDTO;
|
|---|
| 4 | import com.finki.icare.model.Therapist;
|
|---|
| 5 | import org.mapstruct.*;
|
|---|
| 6 |
|
|---|
| 7 | import java.time.LocalDate;
|
|---|
| 8 | import java.util.ArrayList;
|
|---|
| 9 | import java.util.Arrays;
|
|---|
| 10 | import java.util.List;
|
|---|
| 11 |
|
|---|
| 12 | @Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
|
|---|
| 13 | public interface TherapistMapper {
|
|---|
| 14 |
|
|---|
| 15 | @Mapping(target = "idUser", source = "idUser")
|
|---|
| 16 | @Mapping(target = "name", source = "name")
|
|---|
| 17 | @Mapping(target = "surname", source = "surname")
|
|---|
| 18 | @Mapping(target = "email", source = "email")
|
|---|
| 19 | @Mapping(target = "officeLocation", source = "officeLocation")
|
|---|
| 20 | @Mapping(target = "degree", source = "degree")
|
|---|
| 21 | @Mapping(target = "yearsExp", source = "yearsExp")
|
|---|
| 22 | @Mapping(target = "phoneNumber", source = "phoneNumber")
|
|---|
| 23 | @Mapping(target = "freeConsultationSlots", source = "consultationSlots", qualifiedByName = "filterFutureSlots")
|
|---|
| 24 | TherapistDTO toDTO(Therapist therapist);
|
|---|
| 25 |
|
|---|
| 26 | @Named("filterFutureSlots")
|
|---|
| 27 | default List<LocalDate> filterFutureSlots(LocalDate[] slots) {
|
|---|
| 28 | if (slots == null) {
|
|---|
| 29 | return new ArrayList<>();
|
|---|
| 30 | }
|
|---|
| 31 | return Arrays.stream(slots)
|
|---|
| 32 | .filter(slot -> !slot.isBefore(LocalDate.now()))
|
|---|
| 33 | .sorted()
|
|---|
| 34 | .toList();
|
|---|
| 35 | }
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|