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 { ...@@ -78,7 +78,6 @@ export class UserBookingListComponent {
deleteBooking(bookingId: number) { deleteBooking(bookingId: number) {
this.bookingClient.deleteBooking(bookingId).subscribe({ this.bookingClient.deleteBooking(bookingId).subscribe({
next: () => { next: () => {
console.log('Actualizadas');
this.updateBookings(); this.updateBookings();
}, },
error: (err) => { error: (err) => {
......
...@@ -33,7 +33,7 @@ export class BookingService { ...@@ -33,7 +33,7 @@ export class BookingService {
} }
// Método para eliminar una reserva // Método para eliminar una reserva
deleteBooking(id: number): Observable<void> { deleteBooking(id: number) {
return this.http.delete<void>(`${this.apiUrl}/${id}`); return this.http.delete(`${this.apiUrl}/${id}`);
} }
} }
...@@ -11,6 +11,7 @@ import com.uva.roomBooking.Repositories.UserRepository; ...@@ -11,6 +11,7 @@ import com.uva.roomBooking.Repositories.UserRepository;
import jakarta.transaction.Transactional; import jakarta.transaction.Transactional;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -63,26 +64,17 @@ public class BookingController { ...@@ -63,26 +64,17 @@ public class BookingController {
.orElseThrow(() -> new RuntimeException("Booking not found")); .orElseThrow(() -> new RuntimeException("Booking not found"));
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
@Transactional @Transactional
public ResponseEntity<String> deleteBooking(@PathVariable Integer id) { public ResponseEntity<Void> deleteBooking(@PathVariable Integer id) {
try { try {
if (!bookingRepository.existsById(id)) { if (!bookingRepository.existsById(id))
return ResponseEntity.status(HttpStatus.NOT_FOUND) return new ResponseEntity<>(HttpStatus.NOT_FOUND);
.body("Booking not found with id: " + id);
}
bookingRepository.deleteBookingById(id); bookingRepository.deleteBookingById(id);
return new ResponseEntity<>(HttpStatus.ACCEPTED);
return ResponseEntity.ok("Booking deleted successfully");
} catch (Exception e) { } catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
.body("Error deleting booking: " + e.getMessage());
} }
} }
} }
...@@ -18,8 +18,7 @@ public interface BookingRepository extends JpaRepository<Booking, Integer> { ...@@ -18,8 +18,7 @@ public interface BookingRepository extends JpaRepository<Booking, Integer> {
@Param("endDate") LocalDate endDate); @Param("endDate") LocalDate endDate);
@Modifying @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); void deleteBookingById(@Param("id") Integer id);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment