|
2 | 2 |
|
3 | 3 | import polars as pl |
4 | 4 | from asgiref.sync import async_to_sync |
5 | | -from drf_spectacular.utils import PolymorphicProxySerializer, extend_schema |
| 5 | +from drf_spectacular.utils import ( |
| 6 | + PolymorphicProxySerializer, |
| 7 | + extend_schema, |
| 8 | + extend_schema_view, |
| 9 | + inline_serializer, |
| 10 | +) |
6 | 11 | from pydantic import ValidationError |
| 12 | +from rest_framework import serializers as drf_serializers |
7 | 13 | from rest_framework import status |
8 | 14 | from rest_framework.parsers import FormParser, MultiPartParser |
9 | 15 | from rest_framework.response import Response |
10 | 16 | from rest_framework.views import APIView |
| 17 | +from rest_framework_simplejwt.authentication import JWTAuthentication |
11 | 18 |
|
12 | 19 | from application.ingestion.interfaces.list_offers_input import GetFilteredOffersInput |
13 | 20 | from application.ingestion.interfaces.load_documents_input import LoadDocumentsInput |
14 | 21 | from application.ingestion.interfaces.load_operation_type import LoadOperationType |
15 | 22 | from domain.entities.document import Document, DocumentType |
| 23 | +from domain.exceptions.offer_errors import OfferDoesNotExist |
| 24 | +from infrastructure.authentication.api_key_authentication import ( |
| 25 | + ApiKeyAuthentication, |
| 26 | + UserRateThrottleExceptApiKey, |
| 27 | +) |
16 | 28 | from infrastructure.di.ingestion.ingestion_factory import create_ingestion_container |
17 | 29 | from presentation.ingestion.openapi import ( |
18 | 30 | CONCOURS_UPLOAD_DESCRIPTION, |
|
23 | 35 | from presentation.ingestion.pagination import IngestionPagination |
24 | 36 | from presentation.ingestion.schemas import ConcoursRowSchema |
25 | 37 | from presentation.ingestion.serializers import ( |
| 38 | + ArchiveOfferSuccessSerializer, |
26 | 39 | ConcoursUploadResponseSerializer, |
27 | 40 | FileErrorSerializer, |
28 | 41 | ListOffersErrorSerializer, |
@@ -353,3 +366,48 @@ def get(self, request): |
353 | 366 | return Response( |
354 | 367 | serializer.data, status=status.HTTP_500_INTERNAL_SERVER_ERROR |
355 | 368 | ) |
| 369 | + |
| 370 | + |
| 371 | +@extend_schema_view( |
| 372 | + post=extend_schema( |
| 373 | + request=None, |
| 374 | + summary="Archiver une offre par référence", |
| 375 | + description=( |
| 376 | + "Archive une offre selon sa référence. " |
| 377 | + "Accepte une authentification JWT ou par clé d'API." |
| 378 | + ), |
| 379 | + tags=["offres"], |
| 380 | + responses={ |
| 381 | + 200: ArchiveOfferSuccessSerializer, |
| 382 | + 401: PolymorphicProxySerializer( |
| 383 | + component_name="ArchiveOffer401Error", |
| 384 | + serializers=[ |
| 385 | + TokenErrorSerializer, |
| 386 | + inline_serializer( |
| 387 | + name="ArchiveOfferUnauthorized", |
| 388 | + fields={"detail": drf_serializers.CharField()}, |
| 389 | + ), |
| 390 | + ], |
| 391 | + resource_type_field_name=None, |
| 392 | + ), |
| 393 | + 404: inline_serializer( |
| 394 | + name="ArchiveOfferNotFound", |
| 395 | + fields={"detail": drf_serializers.CharField()}, |
| 396 | + ), |
| 397 | + }, |
| 398 | + ) |
| 399 | +) |
| 400 | +class ArchiveOffersView(APIView): |
| 401 | + authentication_classes = [JWTAuthentication, ApiKeyAuthentication] |
| 402 | + throttle_classes = [UserRateThrottleExceptApiKey] |
| 403 | + |
| 404 | + serializer_class = ArchiveOfferSuccessSerializer |
| 405 | + |
| 406 | + def post(self, request, reference: str): |
| 407 | + container = create_ingestion_container() |
| 408 | + use_case = container.archive_offer_by_reference_usecase() |
| 409 | + try: |
| 410 | + use_case.execute(reference) |
| 411 | + except OfferDoesNotExist: |
| 412 | + return Response({"detail": "Not found."}, status=status.HTTP_404_NOT_FOUND) |
| 413 | + return Response({"status": "ok"}, status=status.HTTP_200_OK) |
0 commit comments