Skip to content
Snippets Groups Projects
Commit aba72008 authored by migudel's avatar migudel :speech_balloon:
Browse files

Agregada función de eliminación de reservas

parent 8860f6d5
No related branches found
No related tags found
1 merge request!10Add ts types and json mocks, remove poblate scripts and fix the cascade...
......@@ -78,7 +78,6 @@ export class UserBookingListComponent {
deleteBooking(bookingId: number) {
this.bookingClient.deleteBooking(bookingId).subscribe({
next: () => {
console.log('Actualizadas');
this.updateBookings();
},
error: (err) => {
......
......@@ -33,7 +33,7 @@ export class BookingService {
}
// Método para eliminar una reserva
deleteBooking(id: number): Observable<void> {
return this.http.delete<void>(`${this.apiUrl}/${id}`);
deleteBooking(id: number) {
return this.http.delete(`${this.apiUrl}/${id}`);
}
}
......@@ -11,6 +11,7 @@ import com.uva.roomBooking.Repositories.UserRepository;
import jakarta.transaction.Transactional;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
......@@ -63,26 +64,17 @@ public class BookingController {
.orElseThrow(() -> new RuntimeException("Booking not found"));
}
@DeleteMapping("/{id}")
@Transactional
public ResponseEntity<String> deleteBooking(@PathVariable Integer id) {
public ResponseEntity<Void> deleteBooking(@PathVariable Integer id) {
try {
if (!bookingRepository.existsById(id)) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body("Booking not found with id: " + id);
}
bookingRepository.deleteBookingById(id);
return ResponseEntity.ok("Booking deleted successfully");
if (!bookingRepository.existsById(id))
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
bookingRepository.deleteBookingById(id);
return new ResponseEntity<>(HttpStatus.ACCEPTED);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body("Error deleting booking: " + e.getMessage());
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
......@@ -18,8 +18,7 @@ public interface BookingRepository extends JpaRepository<Booking, Integer> {
@Param("endDate") LocalDate endDate);
@Modifying
@Query("DELETE FROM Booking b WHERE b.id = :id")
@Query("DELETE FROM Booking b WHERE b.id = ?1")
void deleteBookingById(@Param("id") Integer id);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment