Skip to content

Conversation

femelloffm
Copy link
Contributor

📍 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?

  • Implementação de nova funcionalidade
  • Correção de bug
  • Refatoração de código
  • Atualização de documentação

🧪 Testes realizados:

image

✅ Checklist

  • Testes foram adicionados/atualizados
  • Documentação foi atualizada (se necessário)
  • O código segue os padrões do projeto

@femelloffm femelloffm requested a review from a team as a code owner September 29, 2025 03:28
@Copilot Copilot AI review requested due to automatic review settings September 29, 2025 03:28
@femelloffm femelloffm self-assigned this Sep 29, 2025
@femelloffm femelloffm added the feature New feature or request label Sep 29, 2025
@femelloffm femelloffm added this to the Sprint 2 milestone Sep 29, 2025
@femelloffm femelloffm linked an issue Sep 29, 2025 that may be closed by this pull request
Copy link
Contributor

@Copilot Copilot AI left a 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

Comment on lines +108 to 120
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);
}
Copy link

Copilot AI Sep 29, 2025

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.

Comment on lines +112 to +117
.map(timeSlot -> new TimeSlotDTO(
(Date) timeSlot[1],
(UUID) timeSlot[0],
((Time) timeSlot[2]).toLocalTime(),
((Time) timeSlot[3]).toLocalTime()
))
Copy link

Copilot AI Sep 29, 2025

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.

Suggested change
.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;
Copy link

Copilot AI Sep 29, 2025

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;
Copy link

Copilot AI Sep 29, 2025

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.

Comment on lines +86 to +88
public ResponseEntity<ApiResponse<List<AvailableTimeSlotsResponseDTO>>> listAvailableSchedules(@RequestParam UUID interpreterId,
@RequestParam LocalDate dateFrom,
@RequestParam LocalDate dateTo) {
Copy link

Copilot AI Sep 29, 2025

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();
Copy link

Copilot AI Sep 29, 2025

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.

Suggested change
String key = timeSlot.getDate().toString() + timeSlot.getInterpreterId().toString();
String key = timeSlot.getDate().toString() + "|" + timeSlot.getInterpreterId().toString();

Copilot uses AI. Check for mistakes.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
3.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@femelloffm femelloffm merged commit 2cdc54f into dev Sep 29, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

US17 - Criar endpoints para Schedule

1 participant