From df5927e5accd1a39e1ce67124dbbd7bbd265ef2d Mon Sep 17 00:00:00 2001 From: berkay Date: Fri, 8 Nov 2024 18:23:28 +0300 Subject: [PATCH] events are updated --- api_events/events/address/address.py | 21 +-- api_events/events/authentication.py | 2 +- api_events/events/building/building_build.py | 8 +- .../events/building/building_build_parts.py | 8 +- .../events/building/building_living_spaces.py | 14 +- api_events/events/company/company_company.py | 8 +- .../events/company/company_department.py | 8 +- api_events/events/company/company_duty.py | 8 +- api_events/events/company/company_employee.py | 8 +- api_events/events/company/company_staff.py | 8 +- .../decision_book_decision_book.py | 8 +- .../decision_book_decision_book_items.py | 27 ++-- .../decision_book_decision_book_person.py | 2 +- .../decision_book_invitations.py | 2 +- ...ect_decision_book_project_decision_book.py | 2 +- ...ision_book_project_decision_book_person.py | 2 +- .../events/events/events_bind_events.py | 2 +- .../events/events/events_bind_modules.py | 2 +- .../events/events/events_bind_services.py | 2 +- api_events/events/events/events_events.py | 9 +- api_events/events/events/events_models.py | 2 +- api_events/events/events/events_modules.py | 2 +- api_events/events/events/events_services.py | 2 +- api_events/events/identity/people.py | 24 ++-- api_events/events/identity/users.py | 17 ++- api_validations/core_response.py | 126 ++++++++++++------ .../validations_request/decision_book.py | 16 +-- databases/sql_models/core_mixin.py | 2 +- databases/sql_models/sql_operations.py | 2 +- docker-compose.yml | 2 - service_app/app.py | 14 +- .../routers/building/buildarea/router.py | 2 +- .../routers/building/buildsites/router.py | 2 +- .../routers/building/buildtypes/router.py | 2 +- .../project_decision_book/router.py | 2 +- .../project_decision_book_person/router.py | 2 +- service_app_mail/app_mail_sender.py | 2 +- 37 files changed, 223 insertions(+), 149 deletions(-) diff --git a/api_events/events/address/address.py b/api_events/events/address/address.py index f1d66f2..ac980ef 100644 --- a/api_events/events/address/address.py +++ b/api_events/events/address/address.py @@ -15,7 +15,7 @@ from api_validations.validations_request import ( InsertPostCode, SearchAddress, ) -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject @@ -55,8 +55,10 @@ class AddressListEventMethods(MethodToEvent): records = Addresses.filter_active( *Addresses.get_smart_query(list_options.query) ) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="List Address records", + result=records, ) @classmethod @@ -66,11 +68,12 @@ class AddressListEventMethods(MethodToEvent): token_dict=token_dict, filter_expr=Addresses.get_smart_query(list_options.query), ) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="List Address records", + result=records, ) - class AddressCreateEventMethods(MethodToEvent): event_type = "CREATE" @@ -345,8 +348,10 @@ class AddressPostCodeListEventMethods(MethodToEvent): records = AddressPostcode.filter_active( *Addresses.get_smart_query(list_options.query) ) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="List Address records", + result=records, ) diff --git a/api_events/events/authentication.py b/api_events/events/authentication.py index 80aef8f..a59ecd5 100644 --- a/api_events/events/authentication.py +++ b/api_events/events/authentication.py @@ -48,7 +48,7 @@ from api_configs import ApiStatic, Auth from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject from api_library.date_time_actions.date_functions import system_arrow, client_arrow -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class AuthenticationLoginEventMethods(MethodToEvent): diff --git a/api_events/events/building/building_build.py b/api_events/events/building/building_build.py index c134c34..47a7157 100644 --- a/api_events/events/building/building_build.py +++ b/api_events/events/building/building_build.py @@ -19,7 +19,7 @@ from api_validations.validations_request import ( ListOptions, ) -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject @@ -50,8 +50,10 @@ class BuildListEventMethods(MethodToEvent): records = Build.filter_active( *Build.get_smart_query(smart_query=list_options.query) ) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="Building Records are listed", + result=records, ) diff --git a/api_events/events/building/building_build_parts.py b/api_events/events/building/building_build_parts.py index 0d1fb22..1a18118 100644 --- a/api_events/events/building/building_build_parts.py +++ b/api_events/events/building/building_build_parts.py @@ -7,7 +7,7 @@ from databases import ( ) from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse from api_validations.validations_request import ( InsertBuildParts, @@ -34,8 +34,10 @@ class BuildingBuildPartsListEventMethods(MethodToEvent): records = BuildParts.filter_active( *BuildParts.get_smart_query(list_options.query) ) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="Building Parts Records are listed", + result=records, ) diff --git a/api_events/events/building/building_living_spaces.py b/api_events/events/building/building_living_spaces.py index 73cfeaa..7944699 100644 --- a/api_events/events/building/building_living_spaces.py +++ b/api_events/events/building/building_living_spaces.py @@ -13,7 +13,7 @@ from databases import ( from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse from api_validations.validations_request import ( InsertBuildLivingSpace, ListOptions, @@ -48,8 +48,10 @@ class BuildingLivingSpacesPartsListEventMethods(MethodToEvent): ), *BuildLivingSpace.get_smart_query(smart_query=list_options.query), ) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="Building Living Spaces are listed successfully", + result=records, ) @classmethod @@ -71,8 +73,10 @@ class BuildingLivingSpacesPartsListEventMethods(MethodToEvent): *BuildLivingSpace.get_smart_query(smart_query=list_options.query), expired=False, ) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="Building Living Spaces are listed successfully", + result=records, ) diff --git a/api_events/events/company/company_company.py b/api_events/events/company/company_company.py index a382e43..24be15d 100644 --- a/api_events/events/company/company_company.py +++ b/api_events/events/company/company_company.py @@ -14,7 +14,7 @@ from api_validations.validations_request import ( from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class CompanyListEventMethods(MethodToEvent): @@ -45,8 +45,10 @@ class CompanyListEventMethods(MethodToEvent): records = Companies.filter_active( *Companies.get_smart_query(list_options.query) ) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="Building Living Spaces are listed successfully", + result=records, ) diff --git a/api_events/events/company/company_department.py b/api_events/events/company/company_department.py index d7b746a..7681a5b 100644 --- a/api_events/events/company/company_department.py +++ b/api_events/events/company/company_department.py @@ -13,7 +13,7 @@ from databases import Departments from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class DepartmentListEventMethods(MethodToEvent): @@ -34,8 +34,10 @@ class DepartmentListEventMethods(MethodToEvent): *Departments.get_smart_query(smart_query=list_options.query), Departments.company_id == token_dict.selected_company.company_id, ) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="Departments are listed successfully", + result=records, ) diff --git a/api_events/events/company/company_duty.py b/api_events/events/company/company_duty.py index e1bae4b..e1bc6aa 100644 --- a/api_events/events/company/company_duty.py +++ b/api_events/events/company/company_duty.py @@ -13,7 +13,7 @@ from databases import Duty from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class DutyListEventMethods(MethodToEvent): @@ -32,8 +32,10 @@ class DutyListEventMethods(MethodToEvent): records = Duty.filter_active( *Duty.get_smart_query(list_options.query), ) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="Duty list is brought successfully", + result=records, ) diff --git a/api_events/events/company/company_employee.py b/api_events/events/company/company_employee.py index 53996b7..cfaeae9 100644 --- a/api_events/events/company/company_employee.py +++ b/api_events/events/company/company_employee.py @@ -15,7 +15,7 @@ from databases import Employees, Staff, People, EmployeeHistory from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class EmployeeListEventMethods(MethodToEvent): @@ -36,8 +36,10 @@ class EmployeeListEventMethods(MethodToEvent): *Employees.get_smart_query(smart_query=list_options.query), Employees.company_id == token_dict.selected_company.company_id, ) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="Employee are listed successfully", + result=records, ) diff --git a/api_events/events/company/company_staff.py b/api_events/events/company/company_staff.py index 1474cff..582a7ca 100644 --- a/api_events/events/company/company_staff.py +++ b/api_events/events/company/company_staff.py @@ -13,7 +13,7 @@ from databases import Staff, Duties from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class StaffListEventMethods(MethodToEvent): @@ -28,8 +28,10 @@ class StaffListEventMethods(MethodToEvent): records = Staff.filter_active( *Staff.get_smart_query(smart_query=list_options.query), ) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="Staff are listed successfully", + result=records, ) diff --git a/api_events/events/decision_book/decision_book_decision_book.py b/api_events/events/decision_book/decision_book_decision_book.py index 0530a46..d183740 100644 --- a/api_events/events/decision_book/decision_book_decision_book.py +++ b/api_events/events/decision_book/decision_book_decision_book.py @@ -17,7 +17,7 @@ from api_validations.validations_request import ( from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse from api_library.date_time_actions.date_functions import DateTimeLocal @@ -55,8 +55,10 @@ class DecisionBookListEventMethods(MethodToEvent): BuildDecisionBook.build_id == token_dict.selected_occupant.build_id, *BuildDecisionBook.get_smart_query(list_options.query), ) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="DecisionBook are listed successfully", + result=records, ) diff --git a/api_events/events/decision_book/decision_book_decision_book_items.py b/api_events/events/decision_book/decision_book_decision_book_items.py index 4288223..70a53ba 100644 --- a/api_events/events/decision_book/decision_book_decision_book_items.py +++ b/api_events/events/decision_book/decision_book_decision_book_items.py @@ -20,7 +20,7 @@ from databases import ( from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse from api_library.date_time_actions.date_functions import system_arrow, client_arrow from api_validations.validations_request import ( @@ -75,20 +75,25 @@ class DecisionBookDecisionBookItemsListEventMethods(MethodToEvent): status_code=status.HTTP_404_NOT_FOUND, detail=f"No company is match with given Employee UUID {token_dict.selected_company.employee_uu_id}", ) - + BuildDecisionBookItems.filter_attr = BuildDecisionBookItems.FilterModel(**data.dump()) records = BuildDecisionBookItems.filter_active( BuildDecisionBookItems.build_decision_book_id == decision_book.id ) - return JSONResponse( - status_code=status.HTTP_200_OK, - content=dict( - total_count=records.count, - count=len(records.data), - message=f"Decision Book Items has found from given Decision Book UUID {data.build_decision_book_uu_id}", - completed=True, - data=[record.get_dict() for record in records.data], - ), + return AlchemyJsonResponse( + completed=True, + message="DecisionBook are listed successfully", + result=records, ) + # return JSONResponse( + # status_code=status.HTTP_200_OK, + # content=dict( + # total_count=records.count, + # count=len(records.data), + # message=f"Decision Book Items has found from given Decision Book UUID {data.build_decision_book_uu_id}", + # completed=True, + # data=[record.get_dict() for record in records.data], + # ), + # ) else: # BuildDecisionBookItems.pre_query = BuildDecisionBookItems.select_action( # occupant_id=token_dict.occupant_list["occupant_id"] 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 099c57e..06c49c7 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 @@ -25,7 +25,7 @@ from api_validations.validations_request import ( from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class DecisionBookPersonListEventMethods(MethodToEvent): diff --git a/api_events/events/decision_book/decision_book_invitations.py b/api_events/events/decision_book/decision_book_invitations.py index 43a3be8..3669913 100644 --- a/api_events/events/decision_book/decision_book_invitations.py +++ b/api_events/events/decision_book/decision_book_invitations.py @@ -22,7 +22,7 @@ from api_validations.validations_request import ( ) from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse from api_library.date_time_actions.date_functions import system_arrow diff --git a/api_events/events/decision_book/project_decision_book_project_decision_book.py b/api_events/events/decision_book/project_decision_book_project_decision_book.py index 2446064..0ae00b1 100644 --- a/api_events/events/decision_book/project_decision_book_project_decision_book.py +++ b/api_events/events/decision_book/project_decision_book_project_decision_book.py @@ -1,6 +1,6 @@ from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class ProjectDecisionBookProjectDecisionBookEvents(MethodToEvent): ... diff --git a/api_events/events/decision_book/project_decision_book_project_decision_book_person.py b/api_events/events/decision_book/project_decision_book_project_decision_book_person.py index e24932b..55b1682 100644 --- a/api_events/events/decision_book/project_decision_book_project_decision_book_person.py +++ b/api_events/events/decision_book/project_decision_book_project_decision_book_person.py @@ -1,6 +1,6 @@ from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class ProjectDecisionBookProjectDecisionBookPersonEvents(MethodToEvent): ... diff --git a/api_events/events/events/events_bind_events.py b/api_events/events/events/events_bind_events.py index 0f478d9..f24c530 100644 --- a/api_events/events/events/events_bind_events.py +++ b/api_events/events/events/events_bind_events.py @@ -15,7 +15,7 @@ from databases import ( from api_validations.validations_request import RegisterEvents2Occupant from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class EventBindOccupantEventMethods(MethodToEvent): diff --git a/api_events/events/events/events_bind_modules.py b/api_events/events/events/events_bind_modules.py index 407a17e..55500d3 100644 --- a/api_events/events/events/events_bind_modules.py +++ b/api_events/events/events/events_bind_modules.py @@ -14,7 +14,7 @@ from api_events.events.events.events_bind_services import ( ServiceBindOccupantEventMethods, ) from api_library.date_time_actions.date_functions import system_arrow -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class ModulesBindOccupantEventMethods(MethodToEvent): diff --git a/api_events/events/events/events_bind_services.py b/api_events/events/events/events_bind_services.py index e77105a..83a0c54 100644 --- a/api_events/events/events/events_bind_services.py +++ b/api_events/events/events/events_bind_services.py @@ -21,7 +21,7 @@ from api_validations.validations_request import ( ) from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class ServiceBindOccupantEventMethods(MethodToEvent): diff --git a/api_events/events/events/events_events.py b/api_events/events/events/events_events.py index c59fc2c..927e51f 100644 --- a/api_events/events/events/events_events.py +++ b/api_events/events/events/events_events.py @@ -20,7 +20,7 @@ from api_validations.validations_request import ( from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class EventsListEventMethods(MethodToEvent): @@ -36,11 +36,14 @@ class EventsListEventMethods(MethodToEvent): list_options: ListOptions, token_dict: Union[EmployeeTokenObject, OccupantTokenObject], ): + Events.filter_attr = list_options records = Events.filter_active( *Events.get_smart_query(list_options.query), ) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="DecisionBook are listed successfully", + result=records, ) diff --git a/api_events/events/events/events_models.py b/api_events/events/events/events_models.py index b3f0323..595d9b1 100644 --- a/api_events/events/events/events_models.py +++ b/api_events/events/events/events_models.py @@ -6,7 +6,7 @@ from api_validations.validations_request import ( from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class ModelEvents(MethodToEvent): diff --git a/api_events/events/events/events_modules.py b/api_events/events/events/events_modules.py index 1bb54a0..62f3114 100644 --- a/api_events/events/events/events_modules.py +++ b/api_events/events/events/events_modules.py @@ -2,7 +2,7 @@ from api_validations.validations_request import DepartmentsPydantic, PatchRecord from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class ModulesEvents(MethodToEvent): diff --git a/api_events/events/events/events_services.py b/api_events/events/events/events_services.py index f9b5cf2..d3494d4 100644 --- a/api_events/events/events/events_services.py +++ b/api_events/events/events/events_services.py @@ -6,7 +6,7 @@ from api_validations.validations_request import ( from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class ServicesEvents(MethodToEvent): diff --git a/api_events/events/identity/people.py b/api_events/events/identity/people.py index 4efa85c..649d327 100644 --- a/api_events/events/identity/people.py +++ b/api_events/events/identity/people.py @@ -13,7 +13,7 @@ from api_validations.validations_request import InsertPerson, UpdateUsers from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse class PeopleListEventMethods(MethodToEvent): @@ -31,23 +31,31 @@ class PeopleListEventMethods(MethodToEvent): records = People.filter_active( *People.get_smart_query(smart_query=list_options.query) ) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="People are listed successfully", + result=records, ) @classmethod def sales_users_people_list(cls, data, token_dict): records = People.filter_active(*People.get_smart_query(smart_query=data.query)) - # records = [model_class(**record) for record in records.data] - return return_json_response_from_alchemy(response=records, pagination=data) + return AlchemyJsonResponse( + completed=True, + message="People are listed successfully", + result=records, + ) @classmethod def human_resources_users_people_list(cls, data, token_dict): records = People.filter_active(*People.get_smart_query(smart_query=data.query)) - # records = [model_class(**record) for record in records.data] - return return_json_response_from_alchemy(response=records, pagination=data) + return AlchemyJsonResponse( + completed=True, + message="People are listed successfully", + result=records, + ) class PeopleCreateEventMethods(MethodToEvent): @@ -91,7 +99,7 @@ class PeopleUpdateEventMethods(MethodToEvent): ): find_one_user = Users.find_one_or_abort(uu_id=user_uu_id) access_authorized_company = Companies.select_action( - duty_id=getattr(token_dict, "duty_id", 5), + duty_id_list=[getattr(token_dict, "duty_id")], filter_expr=[Companies.id == find_one_user.id], ) if access_authorized_company.count: diff --git a/api_events/events/identity/users.py b/api_events/events/identity/users.py index a0b0325..d9cab9f 100644 --- a/api_events/events/identity/users.py +++ b/api_events/events/identity/users.py @@ -9,7 +9,8 @@ from databases.no_sql_models.validations import DomainViaUser from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse + from api_validations.validations_request import ( InsertUsers, @@ -43,13 +44,19 @@ class UserListEventMethods(MethodToEvent): user.person_id for user in Users.filter_active(Users.uu_id.in_(people_ids)).data ] + People.filter_attr = list_options records = People.filter_active(People.id.in_(people_id_list)) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="Users are listed successfully", + result=records, ) + People.filter_attr = list_options records = Users.filter_active(*Users.get_smart_query(list_options.query)) - return return_json_response_from_alchemy( - response=records, pagination=list_options + return AlchemyJsonResponse( + completed=True, + message="Users are listed successfully", + result=records, ) diff --git a/api_validations/core_response.py b/api_validations/core_response.py index 4be9078..1a2d3be 100644 --- a/api_validations/core_response.py +++ b/api_validations/core_response.py @@ -1,58 +1,96 @@ +from typing import Any, Union from fastapi import status from fastapi.responses import JSONResponse +from databases.sql_models.response_model import AlchemyResponse + + +class AlchemyJsonResponse: + status_code: status + message: str + result: AlchemyResponse + completed: bool + filter_attributes: Any = None + response_model: Any = None + def __new__( + cls, + message: str, + status_code: str = 'HTTP_200_OK', + result: Union[Any, list] = None, + completed: bool = True + ): + cls.status_code = getattr(status, status_code, 'HTTP_200_OK') + cls.message = message + cls.result = result + cls.completed = completed + + first_item = cls.result.get(1) + if not first_item: + return JSONResponse( + status_code=cls.status_code, + content=dict( + total_count=0, + count=0, + pagination=None, + completed=cls.completed, + message=cls.message, + data=[], + ), + ) + if cls.result.first: + return JSONResponse( + status_code=cls.status_code, + content=dict( + total_count=1, + count=1, + pagination=None, + completed=cls.completed, + message=cls.message, + data=cls.result.data.get_dict(), + ), + ) + + if not first_item.filter_attr: + counts = cls.result.count + return JSONResponse( + status_code=cls.status_code, + content=dict( + total_count=counts, + count=counts, + pagination=None, + completed=cls.completed, + message=cls.message, + data=[result_data.get_dict() for result_data in cls.result.data], + ), + ) + + filter_model = first_item.filter_attr + total_count = cls.result.query.limit(None).offset(None).count() + total_page_number = round(total_count / int(first_item.filter_attr.size), 0) + 1 -def return_json_response_from_alchemy( - response, cls_obj=None, pagination=None, response_model=None -): - enums = cls_obj.__enums__ if cls_obj else [] - if response.count: - total_count = response.query.limit(None).offset(None).count() - total_page_number = round(total_count / int(pagination.size), 0) + 1 pagination_dict = { - "size/total_count": [response.count, total_count], - "page/total_page": [pagination.page, total_page_number], - "order_field": pagination.order_field, - "order_type": pagination.order_type, + "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, } include_joins = dict( - include_joins=pagination.include_joins if pagination.include_joins else None + include_joins=filter_model.include_joins if filter_model.include_joins else [] ) - - if not isinstance(response.data[0], dict): - data = [] - for obj in response.data: - data_object = obj.get_dict(**include_joins) - if response_model: - data_object = response_model( - **obj.get_dict(**include_joins) - ).model_dump() - data.append(data_object) - else: - data = [] - for obj in response.data: - data_object = obj - if response_model: - data_object = response_model(**obj).model_dump() - data.append(data_object) - + data = [] + for data_object in cls.result.data: + data_dict = data_object.get_dict(include_joins=include_joins) + if cls.response_model: + data_dict = cls.response_model(**data_object.get_dict(include_joins=include_joins)).dump() + data.append(data_dict) return JSONResponse( - status_code=status.HTTP_200_OK, + status_code=cls.status_code, content=dict( + total_count=total_count, + count=cls.result.count, pagination=pagination_dict, - message="Found records are listed", - completed=True, + message=cls.message, + completed=cls.completed, data=data, ), ) - - return JSONResponse( - status_code=status.HTTP_404_NOT_FOUND, - content=dict( - total_count=0, - count=0, - message="No record has found", - completed=False, - data=[], - ), - ) diff --git a/api_validations/validations_request/decision_book.py b/api_validations/validations_request/decision_book.py index 7d2ffb4..07b5b74 100644 --- a/api_validations/validations_request/decision_book.py +++ b/api_validations/validations_request/decision_book.py @@ -6,18 +6,18 @@ from api_validations.validations_request import ( ) -class DecisionBookDecisionBookInvitations(PydanticBaseModel): +class DecisionBookDecisionBookInvitations(BaseModelRegular): build_decision_book_uu_id: str message: str planned_date: str -class DecisionBookDecisionBookInvitationsAttend(PydanticBaseModel): +class DecisionBookDecisionBookInvitationsAttend(BaseModelRegular): token: str is_attend: bool -class DecisionBookDecisionBookInvitationsAssign(PydanticBaseModel): +class DecisionBookDecisionBookInvitationsAssign(BaseModelRegular): token: str build_living_space_uu_id: str occupant_type_uu_id: str @@ -28,7 +28,7 @@ class DecisionBookDecisionBookInvitationsUpdate(PydanticBaseModel): occupant_type_uu_id: Optional[str] = None -class ListDecisionBook(PydanticBaseModel): +class ListDecisionBook(ListOptions, PydanticBaseModel): build_decision_book_uu_id: Optional[str] = None @@ -42,12 +42,12 @@ class InsertDecisionBook(PydanticBaseModel): resp_company_uu_id: Optional[str] = None -class InsertDecisionBookCompleted(PydanticBaseModel): +class InsertDecisionBookCompleted(BaseModelRegular): build_decision_book_uu_id: str meeting_completed_date: str -class InsertDecisionBookPerson(PydanticBaseModel): +class InsertDecisionBookPerson(BaseModelRegular): person_uu_id: str build_decision_book_uu_id: str management_typecode_uu_id: str @@ -74,7 +74,7 @@ class UpdateDecisionBook(PydanticBaseModel): resp_company_uu_id: Optional[str] = None -class InsertBuildDecisionBookItems(PydanticBaseModel): +class InsertBuildDecisionBookItems(BaseModelRegular): token: str info_type_uu_id: str unit_price: float @@ -94,7 +94,7 @@ class UpdateBuildDecisionBookItems(PydanticBaseModel): item_objection: Optional[str] = None -class InsertBuildDecisionBookItemDebits(PydanticBaseModel): +class InsertBuildDecisionBookItemDebits(BaseModelRegular): build_decision_book_item_uu_id: str dues_values: dict # dues_types_uu_id: str diff --git a/databases/sql_models/core_mixin.py b/databases/sql_models/core_mixin.py index f055e52..1a62f69 100644 --- a/databases/sql_models/core_mixin.py +++ b/databases/sql_models/core_mixin.py @@ -198,7 +198,7 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes): for record in self.__class__.__dict__ if "_" not in record[0] and "id" not in record[-2:] ] - include_joins = include_joins or [] + for all_argument in all_arguments: column = getattr(self.__class__, all_argument) is_populate = isinstance(column, InstrumentedAttribute) and not hasattr( diff --git a/databases/sql_models/sql_operations.py b/databases/sql_models/sql_operations.py index 2e5603a..1c76957 100644 --- a/databases/sql_models/sql_operations.py +++ b/databases/sql_models/sql_operations.py @@ -20,7 +20,7 @@ class FilterAttributes: pre_query = None # The query to use before the filtering such as: query = cls.query.filter_by(active=True) filter_attr = None # The filter attributes to use in the model. - FilterModel: ListOptions = ListOptions + FilterModel = ListOptions def flush(self): """Flush the current session.""" diff --git a/docker-compose.yml b/docker-compose.yml index 57d3ec6..ba8d9ee 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -84,7 +84,6 @@ services: - network_store_services depends_on: - wag_management_service -# - commercial_mongo_service wag_management_test_service: container_name: wag_management_test_service @@ -96,7 +95,6 @@ services: depends_on: - wag_management_init_service -# Todo separate api with mail receiver services add mail_service to 2.43 LXC | Create an internal Api or Socket mail_service: container_name: mail_service restart: on-failure diff --git a/service_app/app.py b/service_app/app.py index e044597..b765d77 100644 --- a/service_app/app.py +++ b/service_app/app.py @@ -10,9 +10,9 @@ from handlers_exception import ( exception_handler_exception, ) from prometheus_fastapi_instrumentator import Instrumentator -from prometheus_client import Counter, Histogram +# from prometheus_client import Counter, Histogram -from service_app.app_runner_init import create_endpoints_from_api_functions +from .app_runner_init import create_endpoints_from_api_functions app = create_app() Instrumentator().instrument(app=app).expose(app=app) @@ -32,16 +32,6 @@ app.add_exception_handler(HTTPException, exception_handler_http) app.add_exception_handler(Exception, exception_handler_exception) create_endpoints_from_api_functions(api_app=app) -# # Define a counter metric -# REQUESTS_COUNT = Counter( -# "requests_total", "Total number of requests", ["method", "endpoint", "status_code"] -# ) -# # Define a histogram metric -# REQUESTS_TIME = Histogram("requests_time", "Request processing time", ["method", "endpoint"]) -# api_request_summary = Histogram("api_request_summary", "Request processing time", ["method", "endpoint"]) -# api_request_counter = Counter("api_request_counter", "Request processing time", ["method", "endpoint", "http_status"]) - - if __name__ == "__main__": uvicorn_config = { "app": "app:app", diff --git a/service_app/routers/building/buildarea/router.py b/service_app/routers/building/buildarea/router.py index c705e4c..ec98e7d 100644 --- a/service_app/routers/building/buildarea/router.py +++ b/service_app/routers/building/buildarea/router.py @@ -11,7 +11,7 @@ from api_validations.validations_request import ( ) from api_services.redis.auth_actions.token import parse_token_object_to_dict -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse from databases import ( BuildArea, Build, diff --git a/service_app/routers/building/buildsites/router.py b/service_app/routers/building/buildsites/router.py index 52a800a..b9945cd 100644 --- a/service_app/routers/building/buildsites/router.py +++ b/service_app/routers/building/buildsites/router.py @@ -13,7 +13,7 @@ from api_validations.validations_request import ( from databases import BuildSites from api_services.redis.auth_actions.token import parse_token_object_to_dict -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse build_sites_route = APIRouter(prefix="/building/sites", tags=["Building Sites"]) diff --git a/service_app/routers/building/buildtypes/router.py b/service_app/routers/building/buildtypes/router.py index 5f402b1..48a656a 100644 --- a/service_app/routers/building/buildtypes/router.py +++ b/service_app/routers/building/buildtypes/router.py @@ -11,7 +11,7 @@ from api_validations.validations_request import ( ) from api_services.redis.auth_actions.token import parse_token_object_to_dict -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse from databases import BuildTypes diff --git a/service_app/routers/project_decision_book/project_decision_book/router.py b/service_app/routers/project_decision_book/project_decision_book/router.py index a3f83c8..97e21bc 100644 --- a/service_app/routers/project_decision_book/project_decision_book/router.py +++ b/service_app/routers/project_decision_book/project_decision_book/router.py @@ -11,7 +11,7 @@ from api_validations.validations_request import ( ) from api_services.redis.auth_actions.token import parse_token_object_to_dict -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse from databases import BuildDecisionBookProjects diff --git a/service_app/routers/project_decision_book/project_decision_book_person/router.py b/service_app/routers/project_decision_book/project_decision_book_person/router.py index a31e4d7..3c6b93e 100644 --- a/service_app/routers/project_decision_book/project_decision_book_person/router.py +++ b/service_app/routers/project_decision_book/project_decision_book_person/router.py @@ -11,7 +11,7 @@ from api_validations.validations_request import ( ) from api_services.redis.auth_actions.token import parse_token_object_to_dict -from api_validations.core_response import return_json_response_from_alchemy +from api_validations.core_response import AlchemyJsonResponse from databases import BuildDecisionBook, Build diff --git a/service_app_mail/app_mail_sender.py b/service_app_mail/app_mail_sender.py index 32faee2..3b7240d 100644 --- a/service_app_mail/app_mail_sender.py +++ b/service_app_mail/app_mail_sender.py @@ -3,7 +3,7 @@ from api_library.date_time_actions.date_functions import client_arrow def send_mail_to_users_that_have_received_email_from_banks(): - from databases.sql_models import AccountRecords + from databases import AccountRecords print("Service is booting up") print("Sending mail to users that have received email from banks")