Add appointment scheduling feature
Problem Context
Users from different timezones need to schedule appointments. The system should correctly display appointment times.
Advanced
200 points
File Changes (1)
src/main/java/com/example/service/AppointmentService.java
MODIFIED
@@ -15 +15 @@
| 15 | 15 | @Service |
| 16 | 16 | public class AppointmentService { |
| 17 | + |
|
| 18 | + private static final DateTimeFormatter FORMATTER = |
|
| 19 | + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); |
|
| 20 | + |
|
| 21 | + public Appointment scheduleAppointment(Long userId, String dateTimeStr) { |
|
| 22 | + LocalDateTime appointmentTime = LocalDateTime.parse(dateTimeStr, FORMATTER); |
|
| 23 | + |
|
| 24 | + Appointment appointment = new Appointment(); |
|
| 25 | + appointment.setUserId(userId); |
|
| 26 | + appointment.setScheduledAt(appointmentTime); |
|
| 27 | + |
|
| 28 | + return appointmentRepository.save(appointment); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + public List<Appointment> getTodaysAppointments() { |
|
| 32 | + LocalDateTime startOfDay = LocalDate.now().atStartOfDay(); |
|
| 33 | + LocalDateTime endOfDay = startOfDay.plusDays(1); |
|
| 34 | + |
|
| 35 | + return appointmentRepository.findByScheduledAtBetween(startOfDay, endOfDay); |
|
| 36 | + } |
|
| 17 | 37 | } |
Login Required: You must be registered to submit reviews and receive AI feedback.
Register or
login to start reviewing!
Your Review
Review Tips
- Look for security vulnerabilities (SQL injection, XSS, etc.)
- Check for null pointer exceptions and error handling
- Consider performance implications
- Evaluate code maintainability and readability
- Check for proper resource management
- Look for logic errors or edge cases