-
Notifications
You must be signed in to change notification settings - Fork 0
fix/US17 - Adiciona rota para filtrar horarios disponiveis por interprete e datas #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a new functionality to filter available time slots for interpreters based on date ranges. The feature allows querying which time slots are available by cross-referencing schedule and appointment data to identify free periods.
Key changes:
- Added complex native SQL query to calculate available time slots considering existing appointments
- Created new DTOs and mapper for handling time slot data transformation
- Exposed new REST endpoint
/available
to retrieve filtered available schedules
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
File | Description |
---|---|
ScheduleRepository.java | Added complex native SQL query with CTEs to find available time slots by filtering out booked appointments |
ScheduleService.java | Implemented business logic to process time slot data and convert Object[] results to DTOs |
TimeSlotMapper.java | Created mapper component to group time slots by date and interpreter ID |
TimeSlotResponseDTO.java | New response DTO for individual time slot periods |
AvailableTimeSlotsResponseDTO.java | New response DTO for grouped available time slots |
TimeSlotDTO.java | Internal DTO for time slot data transfer |
ScheduleController.java | Added new GET endpoint to expose available time slots functionality |
public List<AvailableTimeSlotsResponseDTO> findAvailableSchedules(UUID interpreterId, LocalDate dateFrom, LocalDate dateTo) { | ||
List<Object[]> timeSlots = scheduleRepository.findAvailableTimeSlots(interpreterId, dateFrom, dateTo); | ||
|
||
List<TimeSlotDTO> foundTimeSlots = timeSlots.stream() | ||
.map(timeSlot -> new TimeSlotDTO( | ||
(Date) timeSlot[1], | ||
(UUID) timeSlot[0], | ||
((Time) timeSlot[2]).toLocalTime(), | ||
((Time) timeSlot[3]).toLocalTime() | ||
)) | ||
.toList(); | ||
return timeSlotMapper.toAvailableTimeSlotsResponse(foundTimeSlots); | ||
} |
Copilot
AI
Sep 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing input validation for the method parameters. Add validation to ensure interpreterId is not null, and dateFrom/dateTo are not null and dateFrom is not after dateTo.
Copilot uses AI. Check for mistakes.
.map(timeSlot -> new TimeSlotDTO( | ||
(Date) timeSlot[1], | ||
(UUID) timeSlot[0], | ||
((Time) timeSlot[2]).toLocalTime(), | ||
((Time) timeSlot[3]).toLocalTime() | ||
)) |
Copilot
AI
Sep 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsafe casting of Object[] elements without null checks. If the query returns null values, these casts will throw ClassCastException. Add null checks and handle potential casting errors.
.map(timeSlot -> new TimeSlotDTO( | |
(Date) timeSlot[1], | |
(UUID) timeSlot[0], | |
((Time) timeSlot[2]).toLocalTime(), | |
((Time) timeSlot[3]).toLocalTime() | |
)) | |
.map(timeSlot -> { | |
// Defensive: check for nulls and types before casting | |
if (timeSlot == null || timeSlot.length < 4) { | |
return null; | |
} | |
Object dateObj = timeSlot[1]; | |
Object uuidObj = timeSlot[0]; | |
Object startTimeObj = timeSlot[2]; | |
Object endTimeObj = timeSlot[3]; | |
if (dateObj == null || uuidObj == null || startTimeObj == null || endTimeObj == null) { | |
return null; | |
} | |
try { | |
Date date = (Date) dateObj; | |
UUID uuid = (UUID) uuidObj; | |
Time startTime = (Time) startTimeObj; | |
Time endTime = (Time) endTimeObj; | |
return new TimeSlotDTO( | |
date, | |
uuid, | |
startTime.toLocalTime(), | |
endTime.toLocalTime() | |
); | |
} catch (ClassCastException e) { | |
// Optionally log the error here | |
return null; | |
} | |
}) | |
.filter(java.util.Objects::nonNull) |
Copilot uses AI. Check for mistakes.
@AllArgsConstructor | ||
public class TimeSlotDTO { | ||
|
||
private Date date; |
Copilot
AI
Sep 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using legacy java.util.Date instead of modern java.time.LocalDate. Since other fields use LocalTime, consider using LocalDate for consistency and better type safety.
Copilot uses AI. Check for mistakes.
@AllArgsConstructor | ||
public class AvailableTimeSlotsResponseDTO { | ||
|
||
private Date date; |
Copilot
AI
Sep 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using legacy java.util.Date instead of modern java.time.LocalDate. For consistency with the application's use of LocalDate in controller parameters, consider using LocalDate here as well.
Copilot uses AI. Check for mistakes.
public ResponseEntity<ApiResponse<List<AvailableTimeSlotsResponseDTO>>> listAvailableSchedules(@RequestParam UUID interpreterId, | ||
@RequestParam LocalDate dateFrom, | ||
@RequestParam LocalDate dateTo) { |
Copilot
AI
Sep 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing validation annotations on request parameters. Add @NotNull validation to ensure required parameters are provided, preventing NullPointerException in the service layer.
Copilot uses AI. Check for mistakes.
public List<AvailableTimeSlotsResponseDTO> toAvailableTimeSlotsResponse(List<TimeSlotDTO> timeSlots) { | ||
Map<String, AvailableTimeSlotsResponseDTO> availableTimeSlots = new HashMap<>(); | ||
timeSlots.forEach(timeSlot -> { | ||
String key = timeSlot.getDate().toString() + timeSlot.getInterpreterId().toString(); |
Copilot
AI
Sep 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String concatenation for map key creation is fragile and could lead to collisions. Use a proper composite key or delimiter, such as timeSlot.getDate().toString() + \"|\" + timeSlot.getInterpreterId().toString()
to avoid potential key conflicts.
String key = timeSlot.getDate().toString() + timeSlot.getInterpreterId().toString(); | |
String key = timeSlot.getDate().toString() + "|" + timeSlot.getInterpreterId().toString(); |
Copilot uses AI. Check for mistakes.
|
📍 Título
Permite filtrar por intervalos de horário disponíveis de intérprete a partir de tabelas Schedule e Appointment
🛠️ O que foi feito?
🧪 Testes realizados:
✅ Checklist