77
88from fastapi_jsonapi import RoutersJSONAPI
99from fastapi_jsonapi .atomic .schemas import AtomicOperationAction , AtomicOperationRef , OperationDataType
10+ from fastapi_jsonapi .views .utils import HTTPMethod
1011
1112if TYPE_CHECKING :
1213 from fastapi_jsonapi .data_layers .base import BaseDataLayer
@@ -27,14 +28,13 @@ class OperationBase:
2728 op_type : str
2829
2930 @classmethod
30- def prepare (
31+ async def prepare (
3132 cls ,
3233 action : str ,
3334 request : Request ,
3435 jsonapi : RoutersJSONAPI ,
3536 ref : Optional [AtomicOperationRef ],
3637 data : OperationDataType ,
37- data_layer_view_dependencies : Dict [str , Any ],
3838 ) -> "OperationBase" :
3939 view_cls : Type [ViewBase ] = jsonapi .detail_view_resource
4040
@@ -55,6 +55,11 @@ def prepare(
5555
5656 view = view_cls (request = request , jsonapi = jsonapi )
5757
58+ data_layer_view_dependencies : Dict [str , Any ] = await jsonapi .handle_view_dependencies (
59+ request = request ,
60+ view_cls = view_cls ,
61+ method = operation_cls .http_method ,
62+ )
5863 return operation_cls (
5964 jsonapi = jsonapi ,
6065 view = view ,
@@ -127,6 +132,8 @@ class DetailOperationBase(OperationBase):
127132
128133
129134class OperationAdd (ListOperationBase ):
135+ http_method = HTTPMethod .POST
136+
130137 async def handle (self , dl : BaseDataLayer ):
131138 data_in = self .jsonapi .schema_in_post (data = self .data )
132139 response = await self .view .process_create_object (
@@ -137,6 +144,8 @@ async def handle(self, dl: BaseDataLayer):
137144
138145
139146class OperationUpdate (DetailOperationBase ):
147+ http_method = HTTPMethod .PATCH
148+
140149 async def handle (self , dl : BaseDataLayer ):
141150 if self .data is None :
142151 # TODO: clear to-one relationships
@@ -153,6 +162,8 @@ async def handle(self, dl: BaseDataLayer):
153162
154163
155164class OperationRemove (DetailOperationBase ):
165+ http_method = HTTPMethod .DELETE
166+
156167 async def handle (
157168 self ,
158169 dl : BaseDataLayer ,
0 commit comments