package com.pollex.pam.service.mapper; import static java.util.stream.Collectors.toList; import java.util.List; import com.pollex.pam.enums.SatisfactionTypeEnum; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.pollex.pam.domain.Appointment; import com.pollex.pam.domain.Satisfaction; import com.pollex.pam.enums.SatisfactionStatusEnum; import com.pollex.pam.repository.AppointmentRepository; import com.pollex.pam.service.dto.AppointmentDTO; @Service public class AppointmentMapper { @Autowired AppointmentRepository appointmentRepository; public AppointmentDTO toAppointmentDTO(Appointment source) { AppointmentDTO target = new AppointmentDTO(); BeanUtils.copyProperties(source, target); return target; } public List toAppointmentDTO(List source) { return source.stream() .map(s -> toAppointmentDTO(s)).collect(toList()); } public Satisfaction toAppointmentSatisfaction(Appointment appointment) { Satisfaction target = new Satisfaction(); target.setAppointmentId(appointment.getId()); target.setAgentNo(appointment.getAgentNo()); target.setCustomerId(appointment.getCustomerId()); target.setType(SatisfactionTypeEnum.APPOINTMENT); target.setStatus(SatisfactionStatusEnum.UNFILLED); return target; } public Satisfaction toAppointmentSatisfaction(Long appointmentId) { Appointment appointment = appointmentRepository.findById(appointmentId).get(); return toAppointmentSatisfaction(appointment); } }