Compare commits

...

4 Commits

Author SHA1 Message Date
Bhumi Shah
c43e4b18fb delet123 2025-12-08 18:36:42 +03:00
Bhumi Shah
3c3ef45d78 delet12 2025-12-08 18:34:44 +03:00
Bhumi Shah
3f1c5dbca8 delet1 2025-12-07 18:51:18 +03:00
Bhumi Shah
46068ca46d delet 2025-12-07 12:19:53 +03:00
6 changed files with 18 additions and 5 deletions

View File

@@ -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();
}
} }

View File

@@ -67,4 +67,4 @@ public class EmployeeController {
.body("Unexpected error"); .body("Unexpected error");
} }
} }
} }

View File

@@ -41,5 +41,4 @@ public class Employee {
public String getName() { return name; } public String getName() { return name; }
public String getCode() { return code; } public String getCode() { return code; }
public String getPhotoUrl() { return photoUrl; } public String getPhotoUrl() { return photoUrl; }
public List<Booking> getBookings() { return bookings; }
} }

View File

@@ -1,7 +1,7 @@
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(msg); super(message);
} }
} }

View File

@@ -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);
} }

View File

@@ -71,7 +71,9 @@ public class BookingServiceImpl implements BookingService {
} catch (Exception e) { } catch (Exception e) {
throw new IllegalArgumentException("Invalid date format. Use yyyy-MM-dd"); 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) { if (exists) {
throw new IllegalArgumentException("Place already booked for this date"); throw new IllegalArgumentException("Place already booked for this date");
} }
@@ -87,6 +89,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);
}
} }