forked from Olympic/NTO-2025-Backend-TeamTask
Compare commits
4 Commits
65d3dd56cd
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c43e4b18fb | ||
|
|
3c3ef45d78 | ||
|
|
3f1c5dbca8 | ||
|
|
46068ca46d |
@@ -65,6 +65,11 @@ public class BookingController {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Unexpected error");
|
||||
}
|
||||
}
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteBooking(@PathVariable Long id) {
|
||||
bookingService.deleteBooking(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -67,4 +67,4 @@ public class EmployeeController {
|
||||
.body("Unexpected error");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,5 +41,4 @@ public class Employee {
|
||||
public String getName() { return name; }
|
||||
public String getCode() { return code; }
|
||||
public String getPhotoUrl() { return photoUrl; }
|
||||
public List<Booking> getBookings() { return bookings; }
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.example.nto.excepation;
|
||||
|
||||
public class EmployeeNotFoundException extends RuntimeException{
|
||||
public EmployeeNotFoundException(String msg) {
|
||||
super(msg);
|
||||
public EmployeeNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@ import java.util.Map;
|
||||
public interface BookingService {
|
||||
Map<String, Object> findAvailableBookings(String employeeCode);
|
||||
String createBooking(String code, Long placeId, String date);
|
||||
void deleteBooking(long id);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,9 @@ public class BookingServiceImpl implements BookingService {
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Invalid date format. Use yyyy-MM-dd");
|
||||
}
|
||||
boolean exists = bookingRepository.findByDateBetween(bookingDate, bookingDate).stream().anyMatch(b -> b.getPlace().getId() == placeId);
|
||||
boolean exists = bookingRepository.findByDateBetween(bookingDate, bookingDate).stream().anyMatch(
|
||||
b -> b.getPlace()
|
||||
.getId() == placeId);
|
||||
if (exists) {
|
||||
throw new IllegalArgumentException("Place already booked for this date");
|
||||
}
|
||||
@@ -87,6 +89,12 @@ public class BookingServiceImpl implements BookingService {
|
||||
result.put("employeeId", employee.getId());
|
||||
return "the booking was created successfully";
|
||||
}
|
||||
public void deleteBooking(long id) {
|
||||
if (!bookingRepository.existsById(id)) {
|
||||
throw new IllegalArgumentException("Booking not found with id: " + id);
|
||||
}
|
||||
bookingRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user