main #8
@@ -65,6 +65,11 @@ public class BookingController {
|
|||||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Unexpected error");
|
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;
|
package com.example.nto.excepation;
|
||||||
|
|
||||||
public class EmployeeNotFoundException extends RuntimeException{
|
public class EmployeeNotFoundException extends RuntimeException{
|
||||||
public EmployeeNotFoundException(String msg) {
|
public EmployeeNotFoundException(String message) {super(message);}
|
||||||
super(msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,4 @@ import java.util.Optional;
|
|||||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||||
*/
|
*/
|
||||||
@Repository
|
@Repository
|
||||||
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
|
public interface EmployeeRepository extends JpaRepository<Employee, Long> {Optional<Employee> findByCode(String code);}
|
||||||
Optional<Employee> findByCode(String code);
|
|
||||||
}
|
|
||||||
@@ -7,4 +7,5 @@ import java.util.Map;
|
|||||||
public interface BookingService {
|
public interface BookingService {
|
||||||
Map<String, Object> findAvailableBookings(String employeeCode);
|
Map<String, Object> findAvailableBookings(String employeeCode);
|
||||||
String createBooking(String code, Long placeId, String date);
|
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());
|
result.put("employeeId", employee.getId());
|
||||||
return "the booking was created successfully";
|
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