This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.example.nto.excepation;
|
||||
|
||||
public class EmployeeNotFoundException extends RuntimeException{
|
||||
public EmployeeNotFoundException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
public EmployeeNotFoundException(String message) {super(message);}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,4 @@ import java.util.Optional;
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@Repository
|
||||
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
|
||||
Optional<Employee> findByCode(String code);
|
||||
}
|
||||
public interface EmployeeRepository extends JpaRepository<Employee, Long> {Optional<Employee> findByCode(String code);}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -87,6 +87,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