32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
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
|
||
)
|