Skip to content

Commit 057a0e8

Browse files
committed
added remove rooms views
1 parent 58e4975 commit 057a0e8

File tree

95 files changed

+43
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+43
-0
lines changed
-11 Bytes
Binary file not shown.
-11 Bytes
Binary file not shown.

base/__pycache__/apps.cpython-312.pyc

-11 Bytes
Binary file not shown.
-11 Bytes
Binary file not shown.
-11 Bytes
Binary file not shown.

base/__pycache__/urls.cpython-312.pyc

181 Bytes
Binary file not shown.
2.31 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

base/urls.py

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
path('roomdetails/', room_details, name='roomDetails'),
4242
path('roomdetail/', room_detail, name='roomDetail'),
4343
path('addrooms/', add_rooms, name='addRoom'),
44+
path('removerooms/<int:room_id>/', remove_room, name='removeRoom'),
45+
path('removebookedroom/<int:room_id>/', remove_booked_room, name='removebookedroom'),
4446
path('handle-rent/', handle_rent, name='handle_rent'),
4547

4648
# Payment Verify

base/views.py

+41
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,44 @@ def create_payment(request):
401401
return Response({"message": "Payment created successfully.", "payment": serializer.data}, status=status.HTTP_201_CREATED)
402402
else:
403403
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
404+
405+
406+
@api_view(["DELETE"])
407+
@permission_classes([IsAuthenticated])
408+
def remove_room(request, room_id):
409+
"""
410+
Remove a room from the system if the requesting user is the owner.
411+
"""
412+
try:
413+
room = RoomDetails.objects.get(id=room_id, user=request.user)
414+
room.delete()
415+
return Response({"success": True, "message": "Room removed successfully."}, status=status.HTTP_200_OK)
416+
except RoomDetails.DoesNotExist:
417+
return Response({"success": False, "message": "Room not found or unauthorized."}, status=status.HTTP_404_NOT_FOUND)
418+
419+
@api_view(["DELETE"])
420+
@permission_classes([IsAuthenticated])
421+
def remove_booked_room(request, room_id):
422+
"""
423+
Remove a booked room and update its rental status.
424+
"""
425+
try:
426+
booked_room = RentedRooms.objects.get(roomId=room_id)
427+
room = RoomDetails.objects.get(id=room_id)
428+
429+
if booked_room:
430+
booked_room.delete()
431+
room.rented = False
432+
room.rent_from = None
433+
room.rent_to = None
434+
room.save()
435+
return Response({"success": True, "message": "Booked room removed successfully."}, status=status.HTTP_200_OK)
436+
437+
return Response({"success": False, "message": "No booking found for this room."}, status=status.HTTP_404_NOT_FOUND)
438+
439+
except RentedRooms.DoesNotExist:
440+
return Response({"success": False, "message": "Booked room not found."}, status=status.HTTP_404_NOT_FOUND)
441+
except RoomDetails.DoesNotExist:
442+
return Response({"success": False, "message": "Room not found."}, status=status.HTTP_404_NOT_FOUND)
443+
except Exception as e:
444+
return Response({"success": False, "message": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

media/images/1_HWplhCz.jpg

8.94 KB

media/images/rooms/1_Eyayfm4.jpg

8.94 KB

media/images/rooms/1_JUwEd5y.jpg

8.94 KB

media/images/rooms/1_QL3NaG4.jpg

8.94 KB

media/images/rooms/1_Us3yOJG.jpg

8.94 KB

media/images/rooms/2_DHHCAKu.jpg

8.46 KB

media/images/rooms/2_OfrGvon.jpg

8.46 KB

media/images/rooms/2_mx1EpK2.jpg

8.46 KB

media/images/rooms/2_r6cz1Vi.jpg

8.46 KB

media/images/rooms/3_gUhLrrf.jpg

6.62 KB

media/images/rooms/4.jpg

7.32 KB

media/images/rooms/4_2uiBp4c.jpg

7.32 KB

media/images/rooms/4_8GtZCMa.jpg

7.32 KB

media/images/rooms/4_KgNdgow.jpg

7.32 KB

media/images/rooms/4_T4SJHGE.jpg

7.32 KB

media/images/rooms/4_grYw3zV.jpg

7.32 KB

media/images/rooms/5.jpg

6.38 KB

media/images/rooms/5_5IYOjWc.jpg

6.38 KB

media/images/rooms/5_BrGH9Yd.jpg

6.38 KB

media/images/rooms/5_IdtKTi7.jpg

6.38 KB

media/images/rooms/7.jpg

5.82 KB

media/images/rooms/7_Z7BaUwX.jpg

5.82 KB

media/images/rooms/7_liiBuEa.jpg

5.82 KB

media/images/rooms/8.jpg

6.97 KB

media/images/rooms/8_5V3k1e0.jpg

6.97 KB

media/images/rooms/8_czDkYQA.jpg

6.97 KB

media/images/rooms/8_tE44Mjq.jpg

6.97 KB

media/images/rooms/9.jpg

6.4 KB
-11 Bytes
Binary file not shown.
-11 Bytes
Binary file not shown.
-11 Bytes
Binary file not shown.
-11 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)