Files
tripwithbonus/backend/routes/views.py
2025-05-29 12:35:24 +03:00

32 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from django.utils import timezone
from datetime import timedelta
from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework import status
from .models import Route
@api_view(['PATCH'])
@permission_classes([IsAuthenticated])
def highlight_route(request):
try:
route_id = request.data.get('route_id')
route = Route.objects.get(id=route_id, owner=request.user)
# подсвечиваем объявление на 24 часа
route.highlight_end_DT = timezone.now() + timedelta(days=1)
route.is_highlighted = True
route.save()
return Response({'status': 'success'})
except Route.DoesNotExist:
return Response(
{'error': 'Маршрут не найден или у вас нет прав для его изменения'},
status=status.HTTP_404_NOT_FOUND
)
except Exception as e:
return Response(
{'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR
)