File tree Expand file tree Collapse file tree 5 files changed +15
-7
lines changed Expand file tree Collapse file tree 5 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ class ApiBaseModel(BaseModel, ABC):
2121 validate_default = True ,
2222 validate_all_in_root = True ,
2323 validate_assignment = True ,
24+ ser_json_exclude_none = True ,
2425 )
2526
2627 def set_id (self , value ):
Original file line number Diff line number Diff line change @@ -19,15 +19,17 @@ def __init__(self):
1919
2020 @repository_exception_handler
2121 async def create_flight (self , flight : FlightModel ) -> str :
22- return await self .insert (flight .model_dump ())
22+ return await self .insert (flight .model_dump (exclude_none = True ))
2323
2424 @repository_exception_handler
2525 async def read_flight_by_id (self , flight_id : str ) -> Optional [FlightModel ]:
2626 return await self .find_by_id (data_id = flight_id )
2727
2828 @repository_exception_handler
2929 async def update_flight_by_id (self , flight_id : str , flight : FlightModel ):
30- await self .update_by_id (flight .model_dump (), data_id = flight_id )
30+ await self .update_by_id (
31+ flight .model_dump (exclude_none = True ), data_id = flight_id
32+ )
3133
3234 @repository_exception_handler
3335 async def delete_flight_by_id (self , flight_id : str ):
Original file line number Diff line number Diff line change @@ -19,15 +19,17 @@ def __init__(self):
1919
2020 @repository_exception_handler
2121 async def create_motor (self , motor : MotorModel ) -> str :
22- return await self .insert (motor .model_dump ())
22+ return await self .insert (motor .model_dump (exclude_none = True ))
2323
2424 @repository_exception_handler
2525 async def read_motor_by_id (self , motor_id : str ) -> Optional [MotorModel ]:
2626 return await self .find_by_id (data_id = motor_id )
2727
2828 @repository_exception_handler
2929 async def update_motor_by_id (self , motor_id : str , motor : MotorModel ):
30- await self .update_by_id (motor .model_dump (), data_id = motor_id )
30+ await self .update_by_id (
31+ motor .model_dump (exclude_none = True ), data_id = motor_id
32+ )
3133
3234 @repository_exception_handler
3335 async def delete_motor_by_id (self , motor_id : str ):
Original file line number Diff line number Diff line change @@ -19,15 +19,17 @@ def __init__(self):
1919
2020 @repository_exception_handler
2121 async def create_rocket (self , rocket : RocketModel ) -> str :
22- return await self .insert (rocket .model_dump ())
22+ return await self .insert (rocket .model_dump (exclude_none = True ))
2323
2424 @repository_exception_handler
2525 async def read_rocket_by_id (self , rocket_id : str ) -> Optional [RocketModel ]:
2626 return await self .find_by_id (data_id = rocket_id )
2727
2828 @repository_exception_handler
2929 async def update_rocket_by_id (self , rocket_id : str , rocket : RocketModel ):
30- await self .update_by_id (rocket .model_dump (), data_id = rocket_id )
30+ await self .update_by_id (
31+ rocket .model_dump (exclude_none = True ), data_id = rocket_id
32+ )
3133
3234 @repository_exception_handler
3335 async def delete_rocket_by_id (self , rocket_id : str ):
Original file line number Diff line number Diff line change 1- from pydantic import BaseModel
1+ from pydantic import BaseModel , ConfigDict
22
33
44class ApiBaseView (BaseModel ):
55 message : str = 'View not implemented'
6+ model_config = ConfigDict (ser_json_exclude_none = True )
You can’t perform that action at this time.
0 commit comments