auth service up running

This commit is contained in:
2025-01-10 14:17:22 +03:00
parent 03accfed1b
commit 79aa3a1bc5
41 changed files with 480 additions and 340 deletions

View File

@@ -138,16 +138,19 @@ class AddressCreateEventMethods(MethodToEvent):
address.update(is_confirmed=True)
address.save()
return AlchemyJsonResponse(
completed=True, message="Address created successfully", result=address.get_dict()
completed=True,
message="Address created successfully",
result=address.get_dict(),
)
class AddressSearchEventMethods(MethodToEvent):
"""Event methods for searching addresses.
This class handles address search functionality including text search
and filtering.
"""
event_type = "SEARCH"
event_description = "Search for addresses using text and filters"
event_category = "Address"
@@ -161,18 +164,15 @@ class AddressSearchEventMethods(MethodToEvent):
@classmethod
def _build_order_clause(
cls,
filter_list: Dict[str, Any],
schemas: List[str],
filter_table: Any
cls, filter_list: Dict[str, Any], schemas: List[str], filter_table: Any
) -> Any:
"""Build the ORDER BY clause for the query.
Args:
filter_list: Dictionary of filter options
schemas: List of available schema fields
filter_table: SQLAlchemy table to query
Returns:
SQLAlchemy order_by clause
"""
@@ -187,16 +187,20 @@ class AddressSearchEventMethods(MethodToEvent):
# Build order clause
field = getattr(filter_table, filter_list.get("order_field"))
return field.desc() if str(filter_list.get("order_type"))[0] == "d" else field.asc()
return (
field.desc()
if str(filter_list.get("order_type"))[0] == "d"
else field.asc()
)
@classmethod
def _format_record(cls, record: Any, schemas: List[str]) -> Dict[str, str]:
"""Format a database record into a dictionary.
Args:
record: Database record to format
schemas: List of schema fields
Returns:
Formatted record dictionary
"""
@@ -216,14 +220,14 @@ class AddressSearchEventMethods(MethodToEvent):
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
) -> JSONResponse:
"""Search for addresses using text search and filters.
Args:
data: Search parameters including text and filters
token_dict: Authentication token
Returns:
JSON response with search results
Raises:
HTTPException: If search fails
"""
@@ -236,23 +240,23 @@ class AddressSearchEventMethods(MethodToEvent):
if not search_result:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="No addresses found matching search criteria"
detail="No addresses found matching search criteria",
)
query = search_result.get("query")
schemas = search_result.get("schema")
# Apply filters
filter_list = data.list_options.dump()
filter_table = AddressStreet
# Build and apply order clause
order = cls._build_order_clause(filter_list, schemas, filter_table)
# Apply pagination
page_size = int(filter_list.get("size"))
offset = (int(filter_list.get("page")) - 1) * page_size
# Execute query
query = (
query.order_by(order)
@@ -270,9 +274,7 @@ class AddressSearchEventMethods(MethodToEvent):
print(f"Address search completed in {duration:.3f}s")
return AlchemyJsonResponse(
completed=True,
message="Address search results",
result=results
completed=True, message="Address search results", result=results
)
except HTTPException as e:
@@ -283,7 +285,7 @@ class AddressSearchEventMethods(MethodToEvent):
print(f"Address search error: {str(e)}")
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Failed to search addresses"
detail="Failed to search addresses",
) from e
@@ -321,7 +323,9 @@ class AddressUpdateEventMethods(MethodToEvent):
updated_address = address.update(**data_dict)
updated_address.save()
return AlchemyJsonResponse(
completed=True, message="Address updated successfully", result=updated_address.get_dict()
completed=True,
message="Address updated successfully",
result=updated_address.get_dict(),
)
elif isinstance(token_dict, OccupantTokenObject):
raise HTTPException(
@@ -368,7 +372,9 @@ class AddressPatchEventMethods(MethodToEvent):
patched_address = address.patch(**data_dict)
return AlchemyJsonResponse(
completed=True, message="Address patched successfully", result=patched_address.get_dict()
completed=True,
message="Address patched successfully",
result=patched_address.get_dict(),
)
@@ -416,7 +422,9 @@ class AddressPostCodeCreateEventMethods(MethodToEvent):
relation_table.update(is_confirmed=True)
relation_table.save()
return AlchemyJsonResponse(
completed=True, message="Post code created successfully", result=post_code.get_dict()
completed=True,
message="Post code created successfully",
result=post_code.get_dict(),
)
@@ -457,7 +465,9 @@ class AddressPostCodeUpdateEventMethods(MethodToEvent):
updated_post_code = post_code.update(**data_dict)
updated_post_code.save()
return AlchemyJsonResponse(
completed=True, message="Post code updated successfully", result=updated_post_code.get_dict()
completed=True,
message="Post code updated successfully",
result=updated_post_code.get_dict(),
)
elif isinstance(token_dict, OccupantTokenObject):
raise HTTPException(