forked from Olympic/NTO-2025-Backend-TeamTask
complet
This commit is contained in:
40
src/main/java/com/example/nto/utils/MapperEnToDTO.java
Normal file
40
src/main/java/com/example/nto/utils/MapperEnToDTO.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package com.example.nto.utils;
|
||||
|
||||
import com.example.nto.DTO.BookingDTO;
|
||||
import com.example.nto.DTO.EmployeeDTO;
|
||||
import com.example.nto.DTO.PlaceDTO;
|
||||
import com.example.nto.entity.Booking;
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.entity.Place;
|
||||
|
||||
public class MapperEnToDTO {
|
||||
public static EmployeeDTO toEmployeeInfoDto(Employee employee) {
|
||||
EmployeeDTO dto = new EmployeeDTO();
|
||||
dto.setName(employee.getName());
|
||||
dto.setPhotoUrl(employee.getPhotoUrl());
|
||||
|
||||
if (employee.getBookingList() != null) {
|
||||
for (Booking booking : employee.getBookingList()) {
|
||||
BookingDTO bookingDto = toBookingInfoDto(booking);
|
||||
dto.getBookings().put(booking.getDate().toString(), bookingDto);
|
||||
}
|
||||
}
|
||||
|
||||
return dto;
|
||||
}
|
||||
public static BookingDTO toBookingInfoDto(Booking booking) {
|
||||
BookingDTO dto = new BookingDTO();
|
||||
dto.setId(booking.getId());
|
||||
dto.setPlace(toPlaceDto(booking.getPlace()));
|
||||
return dto;
|
||||
}
|
||||
|
||||
public static PlaceDTO toPlaceDto(Place place) {
|
||||
if (place == null) return null;
|
||||
|
||||
PlaceDTO dto = new PlaceDTO();
|
||||
dto.setId(place.getId());
|
||||
dto.setName(place.getPlace());
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user