预约会议 entity,service,controller

public class Reservation { private Long id; private Room room; private User user; private LocalDateTime startTime; private LocalDateTime endTime; private String topic; // Getters and Setters } 

 

 

 

 

 

 

s

public class ReservationService { @Autowired private ReservationMapper reservationMapper; public List<Reservation> getAllReservations() { return reservationMapper.findAll(); } public Reservation getReservationById(Long id) { return reservationMapper.findById(id); } public boolean createReservation(Reservation reservation) { // Check for overlapping reservations List<Reservation> overlappingReservations = reservationMapper.findOverlappingReservations( reservation.getRoom().getId(), reservation.getStartTime(), reservation.getEndTime()); if (overlappingReservations.isEmpty()) { reservationMapper.insert(reservation); return true; } else { return false; } } public void updateReservation(Reservation reservation) { reservationMapper.update(reservation); } public void deleteReservation(Long id) { reservationMapper.delete(id); } }

 

 

@RequestMapping("/reservations") public class ReservationController { @Autowired private ReservationService reservationService; @GetMapping public List<Reservation> getAllReservations() { return reservationService.getAllReservations(); } @GetMapping("/{id}") public Reservation getReservationById(@PathVariable Long id) { return reservationService.getReservationById(id); } @PostMapping public String createReservation(@RequestBody Reservation reservation) { boolean success = reservationService.createReservation(reservation); return success ? "Reservation created successfully" : "Time slot is already booked"; } @PutMapping("/{id}") public String updateReservation(@PathVariable Long id, @RequestBody Reservation reservation) { reservation.setId(id); reservationService.updateReservation(reservation); return "Reservation updated successfully"; } @DeleteMapping("/{id}") public String deleteReservation(@PathVariable Long id) { reservationService.deleteReservation(id); return "Reservation deleted successfully"; } }

posted @ 2024-07-25 07:52  佬zz  阅读(36)  评论(0)    收藏  举报