Skip to content

Commit

Permalink
chore fastapp
Browse files Browse the repository at this point in the history
  • Loading branch information
goFrendiAsgard committed Jan 22, 2024
1 parent 75b257a commit e5f0496
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(
serializer: Optional[MessageSerializer] = None,
kafka_admin: Optional[KafkaAdmin] = None,
retry: int = 3,
retry_interval: int = 3,
retry_interval: int = 10,
identifier='kafka-consumer'
):
self.logger = logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(
serializer: Optional[MessageSerializer] = None,
kafka_admin: Optional[KafkaAdmin] = None,
retry: int = 3,
retry_interval: int = 3,
retry_interval: int = 10,
identifier='kafka-publisher'
):
self.logger = logger
Expand Down Expand Up @@ -100,7 +100,7 @@ async def publish(self, event_name: str, message: Any):
await self.kafka_admin.create_events([event_name])
topic_name = self.kafka_admin.get_topic_name(event_name)
if isinstance(message, BaseModel):
message = message.dict()
message = message.model_dump()
for attempt in range(self.retry):
try:
await self._connect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(
serializer: Optional[MessageSerializer] = None,
rmq_admin: Optional[RMQAdmin] = None,
retry: int = 5,
retry_interval: int = 5,
retry_interval: int = 10,
prefetch_count: int = 20,
identifier='rmq-consumer'
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(
serializer: Optional[MessageSerializer] = None,
rmq_admin: Optional[RMQAdmin] = None,
retry: int = 5,
retry_interval: int = 5,
retry_interval: int = 10,
identifier='rmq-publisher'
):
self.logger = logger
Expand All @@ -41,7 +41,7 @@ async def publish(self, event_name: str, message: Any):
queue_name = self.rmq_admin.get_queue_name(event_name)
exchange_name = self.rmq_admin.get_exchange_name(event_name)
if isinstance(message, BaseModel):
message = message.dict()
message = message.model_dump()
for attempt in range(self.retry):
try:
await self._connect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _schema_data_to_db_entity_map(
Convert entity_data into dictionary
The result of this convertion is used for inserting/updating db_entity.
'''
entity_dict = schema_data.dict()
entity_dict = schema_data.model_dump()
return {
field: value
for field, value in entity_dict.items()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def event_handler(message_dict: Mapping[str, Any]):
try:
result = await self._run_handler(handler, *args, **kwargs)
if isinstance(result, BaseModel):
result = result.dict()
result = result.model_dump()
# publish result
await self.publisher.publish(
reply_event, Result(result=result).to_dict()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def encode(self, data: AccessTokenData) -> str:
expire_time = datetime.utcnow() + timedelta(
seconds=data.expire_seconds
)
sub = jsons.dumps(data.dict())
sub = jsons.dumps(data.model_dump())
data_dict = {'sub': sub, 'exp': expire_time}
encoded_jwt = jwt.encode(
data_dict, self.secret_key, algorithm=self.algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def encode(self, data: RefreshTokenData) -> str:
expire_time = datetime.utcnow() + timedelta(
seconds=data.expire_seconds
)
sub = jsons.dumps(data.dict())
sub = jsons.dumps(data.model_dump())
data_dict = {'sub': sub, 'exp': expire_time}
encoded_jwt = jwt.encode(
data_dict, self.secret_key, algorithm=self.algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def get_groups(
criterion={},
limit=limit,
offset=offset,
user_token_data=user_token_data.dict()
user_token_data=user_token_data.model_dump()
)
return GroupResult(**result_dict)
except Exception as e:
Expand All @@ -57,7 +57,7 @@ async def get_group_by_id(
try:
result_dict = await rpc_caller.call(
'auth_get_group_by_id',
id=id, user_token_data=user_token_data.dict()
id=id, user_token_data=user_token_data.model_dump()
)
return Group(**result_dict)
except Exception as e:
Expand All @@ -77,7 +77,7 @@ async def insert_group(
try:
result_dict = await rpc_caller.call(
'auth_insert_group',
data=data.dict(), user_token_data=user_token_data.dict()
data=data.model_dump(), user_token_data=user_token_data.model_dump()
)
return Group(**result_dict)
except Exception as e:
Expand All @@ -97,7 +97,7 @@ async def update_group(
try:
result_dict = await rpc_caller.call(
'auth_update_group',
id=id, data=data.dict(), user_token_data=user_token_data.dict()
id=id, data=data.model_dump(), user_token_data=user_token_data.model_dump()
)
return Group(**result_dict)
except Exception as e:
Expand All @@ -117,7 +117,7 @@ async def delete_group(
try:
result_dict = await rpc_caller.call(
'auth_delete_group',
id=id, user_token_data=user_token_data.dict()
id=id, user_token_data=user_token_data.model_dump()
)
return Group(**result_dict)
except Exception as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ async def get(
limit=limit,
offset=offset
)
return result.dict()
return result.model_dump()

@rpc_server.register('auth_get_group_by_id')
async def get_by_id(
id: str,
user_token_data: Mapping[str, Any] = {}
) -> Mapping[str, Any]:
row = await group_model.get_by_id(id)
return row.dict()
return row.model_dump()

@rpc_server.register('auth_insert_group')
async def insert(
Expand All @@ -52,7 +52,7 @@ async def insert(
row = await group_model.insert(
data=GroupData(**data)
)
return row.dict()
return row.model_dump()

@rpc_server.register('auth_update_group')
async def update(
Expand All @@ -65,7 +65,7 @@ async def update(
row = await group_model.update(
id=id, data=GroupData(**data)
)
return row.dict()
return row.model_dump()

@rpc_server.register('auth_delete_group')
async def delete(
Expand All @@ -74,4 +74,4 @@ async def delete(
) -> Mapping[str, Any]:
user_token_data = AccessTokenData(**user_token_data)
row = await group_model.delete(id=id)
return row.dict()
return row.model_dump()
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def get_permissions(
criterion={},
limit=limit,
offset=offset,
user_token_data=user_token_data.dict()
user_token_data=user_token_data.model_dump()
)
return PermissionResult(**result_dict)
except Exception as e:
Expand All @@ -58,7 +58,7 @@ async def get_permission_by_id(
try:
result_dict = await rpc_caller.call(
'auth_get_permission_by_id',
id=id, user_token_data=user_token_data.dict()
id=id, user_token_data=user_token_data.model_dump()
)
return Permission(**result_dict)
except Exception as e:
Expand All @@ -78,7 +78,7 @@ async def insert_permission(
try:
result_dict = await rpc_caller.call(
'auth_insert_permission',
data=data.dict(), user_token_data=user_token_data.dict()
data=data.model_dump(), user_token_data=user_token_data.model_dump()
)
return Permission(**result_dict)
except Exception as e:
Expand All @@ -98,7 +98,7 @@ async def update_permission(
try:
result_dict = await rpc_caller.call(
'auth_update_permission',
id=id, data=data.dict(), user_token_data=user_token_data.dict()
id=id, data=data.model_dump(), user_token_data=user_token_data.model_dump()
)
return Permission(**result_dict)
except Exception as e:
Expand All @@ -118,7 +118,7 @@ async def delete_permission(
try:
result_dict = await rpc_caller.call(
'auth_delete_permission',
id=id, user_token_data=user_token_data.dict()
id=id, user_token_data=user_token_data.model_dump()
)
return Permission(**result_dict)
except Exception as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ async def get(
limit=limit,
offset=offset
)
return result.dict()
return result.model_dump()

@rpc_server.register('auth_get_permission_by_id')
async def get_by_id(
id: str,
user_token_data: Mapping[str, Any] = {}
) -> Mapping[str, Any]:
row = await permission_model.get_by_id(id)
return row.dict()
return row.model_dump()

@rpc_server.register('auth_insert_permission')
async def insert(
Expand All @@ -58,7 +58,7 @@ async def insert(
row = await permission_model.insert(
data=PermissionData(**data)
)
return row.dict()
return row.model_dump()

@rpc_server.register('auth_update_permission')
async def update(
Expand All @@ -71,7 +71,7 @@ async def update(
row = await permission_model.update(
id=id, data=PermissionData(**data)
)
return row.dict()
return row.model_dump()

@rpc_server.register('auth_delete_permission')
async def delete(
Expand All @@ -80,4 +80,4 @@ async def delete(
) -> Mapping[str, Any]:
user_token_data = AccessTokenData(**user_token_data)
row = await permission_model.delete(id=id)
return row.dict()
return row.model_dump()
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def login(data: UserLogin) -> TokenResponse:
async def _create_token(data: UserLogin) -> TokenResponse:
try:
token_response_dict = await rpc_caller.call(
'auth_create_token', login_data=data.dict()
'auth_create_token', login_data=data.model_dump()
)
return TokenResponse(**token_response_dict)
except Exception as e:
Expand Down Expand Up @@ -104,7 +104,7 @@ async def get_users(
criterion={},
limit=limit,
offset=offset,
user_token_data=user_token_data.dict()
user_token_data=user_token_data.model_dump()
)
return UserResult(**result_dict)
except Exception as e:
Expand All @@ -124,7 +124,7 @@ async def get_user_by_id(
try:
result_dict = await rpc_caller.call(
'auth_get_user_by_id',
id=id, user_token_data=user_token_data.dict()
id=id, user_token_data=user_token_data.model_dump()
)
return User(**result_dict)
except Exception as e:
Expand All @@ -144,7 +144,7 @@ async def insert_user(
try:
result_dict = await rpc_caller.call(
'auth_insert_user',
data=data.dict(), user_token_data=user_token_data.dict()
data=data.model_dump(), user_token_data=user_token_data.model_dump()
)
return User(**result_dict)
except Exception as e:
Expand All @@ -164,7 +164,7 @@ async def update_user(
try:
result_dict = await rpc_caller.call(
'auth_update_user',
id=id, data=data.dict(), user_token_data=user_token_data.dict()
id=id, data=data.model_dump(), user_token_data=user_token_data.model_dump()
)
return User(**result_dict)
except Exception as e:
Expand All @@ -184,7 +184,7 @@ async def delete_user(
try:
result_dict = await rpc_caller.call(
'auth_delete_user',
id=id, user_token_data=user_token_data.dict()
id=id, user_token_data=user_token_data.model_dump()
)
return User(**result_dict)
except Exception as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def is_user_having_permission(
@rpc_server.register('auth_create_token')
async def create_token(login_data: Mapping[str, str]) -> Mapping[str, str]:
result = await user_model.create_auth_token(UserLogin(**login_data))
return result.dict()
return result.model_dump()

@rpc_server.register('auth_refresh_token')
async def refresh_token(
Expand All @@ -53,7 +53,7 @@ async def refresh_token(
result = await user_model.refresh_auth_token(
refresh_token, access_token
)
return result.dict()
return result.model_dump()

@rpc_server.register('auth_get_user')
async def get(
Expand All @@ -70,15 +70,15 @@ async def get(
limit=limit,
offset=offset
)
return result.dict()
return result.model_dump()

@rpc_server.register('auth_get_user_by_id')
async def get_by_id(
id: str,
user_token_data: Mapping[str, Any] = {}
) -> Mapping[str, Any]:
row = await user_model.get_by_id(id)
return row.dict()
return row.model_dump()

@rpc_server.register('auth_insert_user')
async def insert(
Expand All @@ -91,7 +91,7 @@ async def insert(
row = await user_model.insert(
data=UserData(**data)
)
return row.dict()
return row.model_dump()

@rpc_server.register('auth_update_user')
async def update(
Expand All @@ -104,7 +104,7 @@ async def update(
row = await user_model.update(
id=id, data=UserData(**data)
)
return row.dict()
return row.model_dump()

@rpc_server.register('auth_delete_user')
async def delete(
Expand All @@ -113,4 +113,4 @@ async def delete(
) -> Mapping[str, Any]:
user_token_data = AccessTokenData(**user_token_data)
row = await user_model.delete(id=id)
return row.dict()
return row.model_dump()
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ async def _publish_activity(self, action: str, result: Schema):
activity_data = ActivityData(
action=action,
entity=self.log_entity_name,
data=jsons.dumps(result.dict())
data=jsons.dumps(result.model_dump())
)
await self.publisher.publish('log_new_activity', activity_data.dict())
await self.publisher.publish('log_new_activity', activity_data.model_dump())
Loading

0 comments on commit e5f0496

Please sign in to comment.