From 7997e561f7b7afa3ac7ab510787860143ebcb87e Mon Sep 17 00:00:00 2001 From: berkay Date: Sun, 29 Dec 2024 19:16:26 +0300 Subject: [PATCH] events updated --- api_configs/configs.py | 6 +- api_events/events/__init__.py | 13 ++-- .../events/application/authentication.py | 12 ++-- .../events/building/building_build_parts.py | 6 +- .../events/building/building_living_spaces.py | 10 +++- .../decision_book_decision_book_person.py | 4 +- api_events/events/identity/people.py | 6 +- api_validations/core_response.py | 55 ++++++++++++----- .../validations_response/living_space.py | 54 +++++++++++++++++ api_validations/validations_response/parts.py | 55 +++++++++++++++++ .../validations_response/people.py | 59 +++++++++++++++++++ databases/sql_models/sql_operations.py | 1 + 12 files changed, 250 insertions(+), 31 deletions(-) create mode 100644 api_validations/validations_response/living_space.py create mode 100644 api_validations/validations_response/parts.py create mode 100644 api_validations/validations_response/people.py diff --git a/api_configs/configs.py b/api_configs/configs.py index 1df9fd0..884ab5e 100644 --- a/api_configs/configs.py +++ b/api_configs/configs.py @@ -31,7 +31,11 @@ class Config: "/authentication/valid", "/api/Contact/Us/current_date", ] - NOT_SECURE_PATHS = ["/access/endpoints/available", "/validations/endpoint", "/authentication/avatar"] + NOT_SECURE_PATHS = [ + "/access/endpoints/available", + "/validations/endpoint", + "/authentication/avatar", + ] APP_NAME = "evyos-web-api-gateway" TITLE = "WAG API Web Api Gateway" diff --git a/api_events/events/__init__.py b/api_events/events/__init__.py index 744f89d..415a028 100644 --- a/api_events/events/__init__.py +++ b/api_events/events/__init__.py @@ -143,10 +143,11 @@ from api_events.events.decision_book.project_decision_book_items import ( BuildDecisionBookProjectItemsCreateEventMethod, BuildDecisionBookProjectItemsListEventMethod, ) -from a_project_files.later_use_codes.events_bind_events import ( - EventBindOccupantEventMethod, - EventBindEmployeeEventMethod, -) + +# from api_events.events.events.events_ import ( +# EventBindOccupantEventMethod, +# EventBindEmployeeEventMethod, +# ) from api_events.events.events.events_bind_services import ( ServiceBindOccupantEventMethod, ServiceBindEmployeeEventMethod, @@ -275,8 +276,8 @@ __all__ = [ "StaffGetByUUIDEventMethod", "StaffUpdateEventMethod", "StaffPatchEventMethod", - "EventBindOccupantEventMethod", - "EventBindEmployeeEventMethod", + # "EventBindOccupantEventMethod", + # "EventBindEmployeeEventMethod", "ServiceBindOccupantEventMethod", "ServiceBindEmployeeEventMethod", "BuildDecisionBookInvitationsListEventMethod", diff --git a/api_events/events/application/authentication.py b/api_events/events/application/authentication.py index 9439f80..f7d3ffa 100644 --- a/api_events/events/application/authentication.py +++ b/api_events/events/application/authentication.py @@ -270,7 +270,6 @@ class AuthenticationSelectEventMethods(MethodToEvent): ) - class AuthenticationCheckTokenEventMethods(MethodToEvent): event_type = "LOGIN" @@ -286,8 +285,8 @@ class AuthenticationCheckTokenEventMethods(MethodToEvent): @classmethod def authentication_check_token_is_valid( - cls, - request, + cls, + request, ): if get_object_via_access_key(request=request): return JSONResponse( @@ -712,9 +711,9 @@ class AuthenticationDownloadAvatarEventMethods(MethodToEvent): } @classmethod - def authentication_download_avatar(cls, token_dict: Union[ - EmployeeTokenObject, OccupantTokenObject - ]): + def authentication_download_avatar( + cls, token_dict: Union[EmployeeTokenObject, OccupantTokenObject] + ): if found_user := Users.filter_one(Users.id == token_dict.user_id).data: expired_starts = str( system_arrow.now() - system_arrow.get(str(found_user.expiry_ends)) @@ -728,6 +727,7 @@ class AuthenticationDownloadAvatarEventMethods(MethodToEvent): "completed": True, "message": "Avatar and profile is shared via user credentials", "data": { + "lang": token_dict.lang, "full_name": found_user.person.full_name, "avatar": found_user.avatar, "remember_me": found_user.remember_me, diff --git a/api_events/events/building/building_build_parts.py b/api_events/events/building/building_build_parts.py index 11e4152..0ead676 100644 --- a/api_events/events/building/building_build_parts.py +++ b/api_events/events/building/building_build_parts.py @@ -3,6 +3,7 @@ from typing import Union from fastapi.responses import JSONResponse from fastapi import status +from api_validations.validations_response.parts import BuildPartsListResponse from databases import ( Build, BuildParts, @@ -24,7 +25,7 @@ class BuildingBuildPartsListEventMethods(MethodToEvent): __event_keys__ = { "b860e37a-e19b-4c45-9543-461241f7587c": "building_build_parts_list" } - __event_validation__ = {"b860e37a-e19b-4c45-9543-461241f7587c": None} + __event_validation__ = {"b860e37a-e19b-4c45-9543-461241f7587c": BuildPartsListResponse} @classmethod def building_build_parts_list( @@ -45,6 +46,9 @@ class BuildingBuildPartsListEventMethods(MethodToEvent): completed=True, message="Building Parts Records are listed", result=records, + cls_object=BuildParts, + response_model=BuildPartsListResponse, + filter_attributes=list_options, ) diff --git a/api_events/events/building/building_living_spaces.py b/api_events/events/building/building_living_spaces.py index addc591..5d5602a 100644 --- a/api_events/events/building/building_living_spaces.py +++ b/api_events/events/building/building_living_spaces.py @@ -20,16 +20,21 @@ from api_validations.validations_request import ( UpdateBuildLivingSpace, ListOptions, ) +from api_validations.validations_response.living_space import LivingSpaceListResponse from databases.sql_models.event.event import Services class BuildingLivingSpacesListEventMethods(MethodToEvent): event_type = "SELECT" + event_description = "" + event_category = "" __event_keys__ = { "36961d8a-cefa-46cc-9f7c-9d841d6351b6": "building_live_space_list", } - __event_validation__ = {"36961d8a-cefa-46cc-9f7c-9d841d6351b6": None} + __event_validation__ = { + "36961d8a-cefa-46cc-9f7c-9d841d6351b6": LivingSpaceListResponse + } @classmethod def building_live_space_list( @@ -100,6 +105,9 @@ class BuildingLivingSpacesListEventMethods(MethodToEvent): completed=True, message="Building Living Spaces are listed successfully", result=records, + response_model=LivingSpaceListResponse, + cls_object=BuildLivingSpace, + filter_attributes=list_options, ) diff --git a/api_events/events/decision_book/decision_book_decision_book_person.py b/api_events/events/decision_book/decision_book_decision_book_person.py index adc80e3..3755a87 100644 --- a/api_events/events/decision_book/decision_book_decision_book_person.py +++ b/api_events/events/decision_book/decision_book_decision_book_person.py @@ -38,7 +38,9 @@ class DecisionBookPersonListEventMethods(MethodToEvent): @classmethod def building_decision_book_person_list( - cls, data: ListOptions, token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject], + cls, + data: ListOptions, + token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject], ): return diff --git a/api_events/events/identity/people.py b/api_events/events/identity/people.py index 3486191..cb2c2f3 100644 --- a/api_events/events/identity/people.py +++ b/api_events/events/identity/people.py @@ -3,6 +3,7 @@ from typing import Union from fastapi import status from fastapi.responses import JSONResponse +from api_validations.validations_response.people import PeopleListResponse from databases import ( Build, People, @@ -26,7 +27,7 @@ class PeopleListEventMethods(MethodToEvent): "cdf62f06-ec50-40de-b19e-adb3dd34bb95": "people_list_only_occupant_tenant_or_owner", } __event_validation__ = { - "0a05f03c-6ed8-4230-a4ff-6e7cf886909b": None, + "0a05f03c-6ed8-4230-a4ff-6e7cf886909b": PeopleListResponse, "b5612538-0445-4a4a-ab13-d2a06037f7a5": None, "25cbbaf8-117a-470f-a844-2cfc70f71dde": None, "cdf62f06-ec50-40de-b19e-adb3dd34bb95": None, @@ -60,6 +61,9 @@ class PeopleListEventMethods(MethodToEvent): completed=True, message="People are listed successfully", result=records, + cls_object=People, + filter_attributes=list_options, + response_model=PeopleListResponse, ) @classmethod diff --git a/api_validations/core_response.py b/api_validations/core_response.py index 5f5e8d2..a85cf3c 100644 --- a/api_validations/core_response.py +++ b/api_validations/core_response.py @@ -12,6 +12,18 @@ class AlchemyJsonResponse: completed: bool filter_attributes: Any = None response_model: Any = None + cls_object: Any = None + + @staticmethod + def get_total_count(cls_object, filter_attributes): + total_page_number = 1 + count_to_use = cls_object.total_count / int(filter_attributes.size) + if cls_object.total_count > int(filter_attributes.size): + if isinstance(count_to_use, int): + total_page_number = round(count_to_use, 0) + elif isinstance(count_to_use, float): + total_page_number = round(count_to_use, 0) + 1 + return total_page_number def __new__( cls, @@ -20,6 +32,8 @@ class AlchemyJsonResponse: result: Union[Any, list] = None, completed: bool = True, response_model: Any = None, + cls_object: Any = None, + filter_attributes: Any = None, ): cls.status_code = getattr(status, status_code, "HTTP_200_OK") cls.message = message @@ -27,13 +41,28 @@ class AlchemyJsonResponse: cls.completed = completed cls.response_model = response_model + pagination_dict = { + "size/total_count": [10, 10], + "page/total_page": [1, 1], + "order_field": "id", + "order_type": "asc", + } + if filter_attributes: + total_page_number = cls.get_total_count(cls_object, filter_attributes) + pagination_dict = { + "size/total_count": [filter_attributes.size, cls_object.total_count], + "page/total_page": [filter_attributes.page, total_page_number], + "order_field": filter_attributes.order_field, + "order_type": filter_attributes.order_type, + } + if isinstance(cls.result, dict) or isinstance(cls.result, list): return JSONResponse( status_code=cls.status_code, content=dict( total_count=len(cls.result), count=len(cls.result), - pagination=None, + pagination=pagination_dict, completed=cls.completed, message=cls.message, data=cls.result, @@ -47,7 +76,7 @@ class AlchemyJsonResponse: content=dict( total_count=0, count=0, - pagination=None, + pagination=pagination_dict, completed=cls.completed, message=cls.message, data=[], @@ -60,7 +89,7 @@ class AlchemyJsonResponse: content=dict( total_count=1, count=1, - pagination=None, + pagination=pagination_dict, completed=cls.completed, message=cls.message, data=cls.result.data.get_dict(), @@ -74,27 +103,25 @@ class AlchemyJsonResponse: content=dict( total_count=counts, count=counts, - pagination=None, + pagination=pagination_dict, completed=cls.completed, message=cls.message, data=[result_data.get_dict() for result_data in cls.result.data], ), ) - filter_model = cls.result.get(1).filter_attr + # filter_model = cls.result.get(1).filter_attr total_count = cls.result.get(1).query.limit(None).offset(None).count() - - total_page_number = round(total_count / int(filter_model.size), 0) - + total_page_number = cls.get_total_count(cls_object, filter_attributes) pagination_dict = { - "size/total_count": [cls.result.count, total_count], - "page/total_page": [filter_model.page, total_page_number], - "order_field": filter_model.order_field, - "order_type": filter_model.order_type, + "size/total_count": [filter_attributes.size, cls_object.total_count], + "page/total_page": [filter_attributes.page, total_page_number], + "order_field": filter_attributes.order_field, + "order_type": filter_attributes.order_type, } include_joins = dict( include_joins=( - filter_model.include_joins if filter_model.include_joins else [] + filter_attributes.include_joins if filter_attributes.include_joins else [] ) ) data = [] @@ -108,7 +135,7 @@ class AlchemyJsonResponse: return JSONResponse( status_code=cls.status_code, content=dict( - total_count=total_count, + total_count=total_count or 1, count=cls.result.count, pagination=pagination_dict, message=cls.message, diff --git a/api_validations/validations_response/living_space.py b/api_validations/validations_response/living_space.py new file mode 100644 index 0000000..2b6cdca --- /dev/null +++ b/api_validations/validations_response/living_space.py @@ -0,0 +1,54 @@ +from typing import Optional +from api_validations.core_validations import BaseModelRegular +from api_validations.validations_request import ( + PydanticBaseModel, + PydanticBaseModelValidation, + CrudRecordValidation, + CrudRecords, +) + + +class LivingSpaceListValidation: + tr = { + **CrudRecordValidation.tr, + "fix_value": "Sabit Değer", + "fix_percent": "Sabit Yüzde", + "agreement_no": "Anlaşma No", + "marketing_process": "Pazarlama Süreci", + "marketing_layer": "Pazarlama Katmanı", + "build_parts_id": "Bölüm ID", + "build_parts_uu_id": "Bölüm UUID", + "person_id": "Sorumlu Kişi ID", + "person_uu_id": "Sorumlu Kişi UUID", + "occupant_type": "Kiracı Tipi", + "occupant_type_uu_id": "Kiracı Tipi UUID", + } + en = { + **CrudRecordValidation.en, + "fix_value": "Fixed Value", + "fix_percent": "Fixed Percent", + "agreement_no": "Agreement No", + "marketing_process": "Marketing Process", + "marketing_layer": "Marketing Layer", + "build_parts_id": "Part ID", + "build_parts_uu_id": "Part UUID", + "person_id": "Responsible Person ID", + "person_uu_id": "Responsible Person UUID", + "occupant_type": "Occupant Type", + "occupant_type_uu_id": "Occupant Type UUID", + } + + +class LivingSpaceListResponse(BaseModelRegular, CrudRecords, LivingSpaceListValidation): + + fix_value: Optional[float] = None + fix_percent: Optional[float] = None + agreement_no: Optional[str] = None + marketing_process: Optional[str] = None + marketing_layer: Optional[str] = None + build_parts_id: Optional[int] = None + build_parts_uu_id: Optional[str] = None + person_id: Optional[int] = None + person_uu_id: Optional[str] = None + occupant_type: Optional[str] = None + occupant_type_uu_id: Optional[str] = None diff --git a/api_validations/validations_response/parts.py b/api_validations/validations_response/parts.py new file mode 100644 index 0000000..d77aa64 --- /dev/null +++ b/api_validations/validations_response/parts.py @@ -0,0 +1,55 @@ +from typing import Optional +from api_validations.core_validations import BaseModelRegular +from api_validations.validations_request import ( + PydanticBaseModel, + PydanticBaseModelValidation, + CrudRecordValidation, + CrudRecords, +) + + +class BuildPartsListValidation: + tr = { + **CrudRecordValidation.tr, + "address_gov_code": "Adres Kapı Kodu", + "part_no": "Bölüm No", + "part_level": "Bölüm Seviyesi", + "part_code": "Bölüm Kodu", + "part_gross": "Bölüm Brüt", + "part_net": "Bölüm Net", + "default_accessory": "Varsayılan Aksesuar", + "human_livable": "İnsan Yaşamı", + "due_part_key": "Sabit Ödeme Grubu", + "build_uu_id": "Bina UUID", + "part_direction_uu_id": "Bölüm Yönü UUID", + "part_type_uu_id": "Bölüm Tipi UUID", + } + en = { + **CrudRecordValidation.en, + "address_gov_code": "Address Government Code", + "part_no": "Part Number", + "part_level": "Part Level", + "part_code": "Part Code", + "part_gross": "Part Gross", + "part_net": "Part Net", + "default_accessory": "Default Accessory", + "human_livable": "Human Livable", + "due_part_key": "Constant Payment Group", + "build_uu_id": "Building UUID", + "part_direction_uu_id": "Part Direction UUID", + "part_type_uu_id": "Part Type UUID", + } + +class BuildPartsListResponse(BaseModelRegular, CrudRecords, BuildPartsListValidation): + address_gov_code: Optional[str] = None + part_no: Optional[int] = None + part_level: Optional[int] = None + part_code: Optional[str] = None + part_gross: Optional[int] = None + part_net: Optional[int] = None + default_accessory: Optional[str] = None + human_livable: Optional[bool] = None + due_part_key: Optional[str] = None + build_uu_id: Optional[str] = None + part_direction_uu_id: Optional[str] = None + part_type_uu_id: Optional[str] = None diff --git a/api_validations/validations_response/people.py b/api_validations/validations_response/people.py new file mode 100644 index 0000000..e7e8255 --- /dev/null +++ b/api_validations/validations_response/people.py @@ -0,0 +1,59 @@ +from typing import Optional +from api_validations.core_validations import BaseModelRegular +from api_validations.validations_request import ( + PydanticBaseModel, + PydanticBaseModelValidation, + CrudRecordValidation, + CrudRecords, +) + + +class PeopleListValidation: + tr = { + **CrudRecordValidation.tr, + "firstname": "Ad", + "surname": "Soyad", + "middle_name": "Orta İsim", + "sex_code": "Cinsiyet Kodu", + "person_ref": "Kişi Referansı", + "person_tag": "Kişi Etiketi", + "father_name": "Baba Adı", + "mother_name": "Anne Adı", + "country_code": "Ülke Kodu", + "national_identity_id": "Kimlik Numarası", + "birth_place": "Doğum Yeri", + "birth_date": "Doğum Tarihi", + "tax_no": "Vergi Numarası", + } + en = { + **CrudRecordValidation.en, + "firstname": "First Name", + "surname": "Surname", + "middle_name": "Middle Name", + "sex_code": "Sex Code", + "person_ref": "Person Reference", + "person_tag": "Person Tag", + "father_name": "Father's Name", + "mother_name": "Mother's Name", + "country_code": "Country Code", + "national_identity_id": "National Identity ID", + "birth_place": "Birth Place", + "birth_date": "Birth Date", + "tax_no": "Tax Number", + } + + +class PeopleListResponse(BaseModelRegular, CrudRecords, PeopleListValidation): + firstname: Optional[str] = None + surname: Optional[str] = None + middle_name: Optional[str] = None + sex_code: Optional[str] = None + person_ref: Optional[str] = None + person_tag: Optional[str] = None + father_name: Optional[str] = None + mother_name: Optional[str] = None + country_code: Optional[str] = None + national_identity_id: Optional[str] = None + birth_place: Optional[str] = None + birth_date: Optional[str] = None + tax_no: Optional[str] = None diff --git a/databases/sql_models/sql_operations.py b/databases/sql_models/sql_operations.py index 2c22e51..b074d00 100644 --- a/databases/sql_models/sql_operations.py +++ b/databases/sql_models/sql_operations.py @@ -77,6 +77,7 @@ class FilterAttributes: @classmethod def add_query_to_filter(cls, filter_query, filter_list): + print("filter_list", filter_list) return ( filter_query.order_by( getattr(cls, filter_list.get("order_field")).desc()