11from typing import Literal , Tuple
22from uuid import UUID
33from django .http import HttpRequest
4+ from ninja import File , UploadedFile
45from registration .schema import OperationInformationIn , OperationUpdateOut , OperationRegistrationOut , Message
5- from service .operation_service import OperationService
6+ from service .operation_service import OperationData , OperationService , MultipleOperatorData
67from registration .constants import OPERATION_TAGS
78from common .permissions import authorize
89from common .api .utils import get_current_user_guid
@@ -25,10 +26,7 @@ def register_get_operation_information(request: HttpRequest, operation_id: UUID)
2526 return 200 , OperationService .get_if_authorized (get_current_user_guid (request ), operation_id )
2627
2728
28- ##### PUT #####
29-
30-
31- @router .put (
29+ @router .post (
3230 "/operations/{uuid:operation_id}/registration/operation" ,
3331 response = {200 : OperationUpdateOut , custom_codes_4xx : Message },
3432 tags = OPERATION_TAGS ,
@@ -37,6 +35,29 @@ def register_get_operation_information(request: HttpRequest, operation_id: UUID)
3735 auth = authorize ('approved_industry_user' ),
3836)
3937def register_edit_operation_information (
40- request : HttpRequest , operation_id : UUID , payload : OperationInformationIn
38+ request : HttpRequest ,
39+ operation_id : UUID ,
40+ payload : OperationInformationIn ,
41+ # django-ninja doesn't parse multipart requests properly if the type is marked Optional
42+ boundary_map : File [UploadedFile ] = None , # type: ignore
43+ process_flow_diagram : File [UploadedFile ] = None , # type: ignore
44+ new_entrant_application : File [UploadedFile ] = None , # type: ignore
4145) -> Tuple [Literal [200 ], Operation ]:
42- return 200 , OperationService .register_operation_information (get_current_user_guid (request ), operation_id , payload )
46+
47+ data = OperationData (
48+ boundary_map = boundary_map ,
49+ process_flow_diagram = process_flow_diagram ,
50+ new_entrant_application = new_entrant_application ,
51+ ** payload .model_dump (exclude = {'multiple_operators_array' }),
52+ multiple_operators_array = (
53+ [
54+ MultipleOperatorData (
55+ ** op .model_dump (exclude = {'business_structure' }), business_structure_id = op .business_structure .name # type: ignore
56+ )
57+ for op in payload .multiple_operators_array or []
58+ ]
59+ ),
60+ )
61+ operation = OperationService .register_operation_information (get_current_user_guid (request ), operation_id , data )
62+
63+ return 200 , operation
0 commit comments