events are updated

This commit is contained in:
berkay 2024-11-08 18:23:28 +03:00
parent c5b771e5cb
commit df5927e5ac
37 changed files with 223 additions and 149 deletions

View File

@ -15,7 +15,7 @@ from api_validations.validations_request import (
InsertPostCode, InsertPostCode,
SearchAddress, 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_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
@ -55,8 +55,10 @@ class AddressListEventMethods(MethodToEvent):
records = Addresses.filter_active( records = Addresses.filter_active(
*Addresses.get_smart_query(list_options.query) *Addresses.get_smart_query(list_options.query)
) )
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options completed=True,
message="List Address records",
result=records,
) )
@classmethod @classmethod
@ -66,11 +68,12 @@ class AddressListEventMethods(MethodToEvent):
token_dict=token_dict, token_dict=token_dict,
filter_expr=Addresses.get_smart_query(list_options.query), filter_expr=Addresses.get_smart_query(list_options.query),
) )
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options completed=True,
message="List Address records",
result=records,
) )
class AddressCreateEventMethods(MethodToEvent): class AddressCreateEventMethods(MethodToEvent):
event_type = "CREATE" event_type = "CREATE"
@ -345,8 +348,10 @@ class AddressPostCodeListEventMethods(MethodToEvent):
records = AddressPostcode.filter_active( records = AddressPostcode.filter_active(
*Addresses.get_smart_query(list_options.query) *Addresses.get_smart_query(list_options.query)
) )
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options completed=True,
message="List Address records",
result=records,
) )

View File

@ -48,7 +48,7 @@ from api_configs import ApiStatic, Auth
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
from api_library.date_time_actions.date_functions import system_arrow, client_arrow 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): class AuthenticationLoginEventMethods(MethodToEvent):

View File

@ -19,7 +19,7 @@ from api_validations.validations_request import (
ListOptions, 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_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
@ -50,8 +50,10 @@ class BuildListEventMethods(MethodToEvent):
records = Build.filter_active( records = Build.filter_active(
*Build.get_smart_query(smart_query=list_options.query) *Build.get_smart_query(smart_query=list_options.query)
) )
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options completed=True,
message="Building Records are listed",
result=records,
) )

View File

@ -7,7 +7,7 @@ from databases import (
) )
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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 ( from api_validations.validations_request import (
InsertBuildParts, InsertBuildParts,
@ -34,8 +34,10 @@ class BuildingBuildPartsListEventMethods(MethodToEvent):
records = BuildParts.filter_active( records = BuildParts.filter_active(
*BuildParts.get_smart_query(list_options.query) *BuildParts.get_smart_query(list_options.query)
) )
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options completed=True,
message="Building Parts Records are listed",
result=records,
) )

View File

@ -13,7 +13,7 @@ from databases import (
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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 ( from api_validations.validations_request import (
InsertBuildLivingSpace, InsertBuildLivingSpace,
ListOptions, ListOptions,
@ -48,8 +48,10 @@ class BuildingLivingSpacesPartsListEventMethods(MethodToEvent):
), ),
*BuildLivingSpace.get_smart_query(smart_query=list_options.query), *BuildLivingSpace.get_smart_query(smart_query=list_options.query),
) )
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options completed=True,
message="Building Living Spaces are listed successfully",
result=records,
) )
@classmethod @classmethod
@ -71,8 +73,10 @@ class BuildingLivingSpacesPartsListEventMethods(MethodToEvent):
*BuildLivingSpace.get_smart_query(smart_query=list_options.query), *BuildLivingSpace.get_smart_query(smart_query=list_options.query),
expired=False, expired=False,
) )
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options completed=True,
message="Building Living Spaces are listed successfully",
result=records,
) )

View File

@ -14,7 +14,7 @@ from api_validations.validations_request import (
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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): class CompanyListEventMethods(MethodToEvent):
@ -45,8 +45,10 @@ class CompanyListEventMethods(MethodToEvent):
records = Companies.filter_active( records = Companies.filter_active(
*Companies.get_smart_query(list_options.query) *Companies.get_smart_query(list_options.query)
) )
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options completed=True,
message="Building Living Spaces are listed successfully",
result=records,
) )

View File

@ -13,7 +13,7 @@ from databases import Departments
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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): class DepartmentListEventMethods(MethodToEvent):
@ -34,8 +34,10 @@ class DepartmentListEventMethods(MethodToEvent):
*Departments.get_smart_query(smart_query=list_options.query), *Departments.get_smart_query(smart_query=list_options.query),
Departments.company_id == token_dict.selected_company.company_id, Departments.company_id == token_dict.selected_company.company_id,
) )
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options completed=True,
message="Departments are listed successfully",
result=records,
) )

View File

@ -13,7 +13,7 @@ from databases import Duty
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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): class DutyListEventMethods(MethodToEvent):
@ -32,8 +32,10 @@ class DutyListEventMethods(MethodToEvent):
records = Duty.filter_active( records = Duty.filter_active(
*Duty.get_smart_query(list_options.query), *Duty.get_smart_query(list_options.query),
) )
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options completed=True,
message="Duty list is brought successfully",
result=records,
) )

View File

@ -15,7 +15,7 @@ from databases import Employees, Staff, People, EmployeeHistory
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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): class EmployeeListEventMethods(MethodToEvent):
@ -36,8 +36,10 @@ class EmployeeListEventMethods(MethodToEvent):
*Employees.get_smart_query(smart_query=list_options.query), *Employees.get_smart_query(smart_query=list_options.query),
Employees.company_id == token_dict.selected_company.company_id, Employees.company_id == token_dict.selected_company.company_id,
) )
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options completed=True,
message="Employee are listed successfully",
result=records,
) )

View File

@ -13,7 +13,7 @@ from databases import Staff, Duties
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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): class StaffListEventMethods(MethodToEvent):
@ -28,8 +28,10 @@ class StaffListEventMethods(MethodToEvent):
records = Staff.filter_active( records = Staff.filter_active(
*Staff.get_smart_query(smart_query=list_options.query), *Staff.get_smart_query(smart_query=list_options.query),
) )
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options completed=True,
message="Staff are listed successfully",
result=records,
) )

View File

@ -17,7 +17,7 @@ from api_validations.validations_request import (
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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 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.build_id == token_dict.selected_occupant.build_id,
*BuildDecisionBook.get_smart_query(list_options.query), *BuildDecisionBook.get_smart_query(list_options.query),
) )
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options completed=True,
message="DecisionBook are listed successfully",
result=records,
) )

View File

@ -20,7 +20,7 @@ from databases import (
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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_library.date_time_actions.date_functions import system_arrow, client_arrow
from api_validations.validations_request import ( from api_validations.validations_request import (
@ -75,20 +75,25 @@ class DecisionBookDecisionBookItemsListEventMethods(MethodToEvent):
status_code=status.HTTP_404_NOT_FOUND, status_code=status.HTTP_404_NOT_FOUND,
detail=f"No company is match with given Employee UUID {token_dict.selected_company.employee_uu_id}", 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( records = BuildDecisionBookItems.filter_active(
BuildDecisionBookItems.build_decision_book_id == decision_book.id BuildDecisionBookItems.build_decision_book_id == decision_book.id
) )
return JSONResponse( return AlchemyJsonResponse(
status_code=status.HTTP_200_OK, completed=True,
content=dict( message="DecisionBook are listed successfully",
total_count=records.count, result=records,
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 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: else:
# BuildDecisionBookItems.pre_query = BuildDecisionBookItems.select_action( # BuildDecisionBookItems.pre_query = BuildDecisionBookItems.select_action(
# occupant_id=token_dict.occupant_list["occupant_id"] # occupant_id=token_dict.occupant_list["occupant_id"]

View File

@ -25,7 +25,7 @@ from api_validations.validations_request import (
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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): class DecisionBookPersonListEventMethods(MethodToEvent):

View File

@ -22,7 +22,7 @@ from api_validations.validations_request import (
) )
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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 from api_library.date_time_actions.date_functions import system_arrow

View File

@ -1,6 +1,6 @@
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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): ... class ProjectDecisionBookProjectDecisionBookEvents(MethodToEvent): ...

View File

@ -1,6 +1,6 @@
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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): ... class ProjectDecisionBookProjectDecisionBookPersonEvents(MethodToEvent): ...

View File

@ -15,7 +15,7 @@ from databases import (
from api_validations.validations_request import RegisterEvents2Occupant from api_validations.validations_request import RegisterEvents2Occupant
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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): class EventBindOccupantEventMethods(MethodToEvent):

View File

@ -14,7 +14,7 @@ from api_events.events.events.events_bind_services import (
ServiceBindOccupantEventMethods, ServiceBindOccupantEventMethods,
) )
from api_library.date_time_actions.date_functions import system_arrow 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): class ModulesBindOccupantEventMethods(MethodToEvent):

View File

@ -21,7 +21,7 @@ from api_validations.validations_request import (
) )
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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): class ServiceBindOccupantEventMethods(MethodToEvent):

View File

@ -20,7 +20,7 @@ from api_validations.validations_request import (
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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): class EventsListEventMethods(MethodToEvent):
@ -36,11 +36,14 @@ class EventsListEventMethods(MethodToEvent):
list_options: ListOptions, list_options: ListOptions,
token_dict: Union[EmployeeTokenObject, OccupantTokenObject], token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
): ):
Events.filter_attr = list_options
records = Events.filter_active( records = Events.filter_active(
*Events.get_smart_query(list_options.query), *Events.get_smart_query(list_options.query),
) )
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options completed=True,
message="DecisionBook are listed successfully",
result=records,
) )

View File

@ -6,7 +6,7 @@ from api_validations.validations_request import (
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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): class ModelEvents(MethodToEvent):

View File

@ -2,7 +2,7 @@ from api_validations.validations_request import DepartmentsPydantic, PatchRecord
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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): class ModulesEvents(MethodToEvent):

View File

@ -6,7 +6,7 @@ from api_validations.validations_request import (
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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): class ServicesEvents(MethodToEvent):

View File

@ -13,7 +13,7 @@ from api_validations.validations_request import InsertPerson, UpdateUsers
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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): class PeopleListEventMethods(MethodToEvent):
@ -31,23 +31,31 @@ class PeopleListEventMethods(MethodToEvent):
records = People.filter_active( records = People.filter_active(
*People.get_smart_query(smart_query=list_options.query) *People.get_smart_query(smart_query=list_options.query)
) )
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options completed=True,
message="People are listed successfully",
result=records,
) )
@classmethod @classmethod
def sales_users_people_list(cls, data, token_dict): def sales_users_people_list(cls, data, token_dict):
records = People.filter_active(*People.get_smart_query(smart_query=data.query)) records = People.filter_active(*People.get_smart_query(smart_query=data.query))
# records = [model_class(**record) for record in records.data] return AlchemyJsonResponse(
return return_json_response_from_alchemy(response=records, pagination=data) completed=True,
message="People are listed successfully",
result=records,
)
@classmethod @classmethod
def human_resources_users_people_list(cls, data, token_dict): def human_resources_users_people_list(cls, data, token_dict):
records = People.filter_active(*People.get_smart_query(smart_query=data.query)) records = People.filter_active(*People.get_smart_query(smart_query=data.query))
# records = [model_class(**record) for record in records.data] return AlchemyJsonResponse(
return return_json_response_from_alchemy(response=records, pagination=data) completed=True,
message="People are listed successfully",
result=records,
)
class PeopleCreateEventMethods(MethodToEvent): class PeopleCreateEventMethods(MethodToEvent):
@ -91,7 +99,7 @@ class PeopleUpdateEventMethods(MethodToEvent):
): ):
find_one_user = Users.find_one_or_abort(uu_id=user_uu_id) find_one_user = Users.find_one_or_abort(uu_id=user_uu_id)
access_authorized_company = Companies.select_action( 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], filter_expr=[Companies.id == find_one_user.id],
) )
if access_authorized_company.count: if access_authorized_company.count:

View File

@ -9,7 +9,8 @@ from databases.no_sql_models.validations import DomainViaUser
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject 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 ( from api_validations.validations_request import (
InsertUsers, InsertUsers,
@ -43,13 +44,19 @@ class UserListEventMethods(MethodToEvent):
user.person_id user.person_id
for user in Users.filter_active(Users.uu_id.in_(people_ids)).data 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)) records = People.filter_active(People.id.in_(people_id_list))
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options 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)) records = Users.filter_active(*Users.get_smart_query(list_options.query))
return return_json_response_from_alchemy( return AlchemyJsonResponse(
response=records, pagination=list_options completed=True,
message="Users are listed successfully",
result=records,
) )

View File

@ -1,58 +1,96 @@
from typing import Any, Union
from fastapi import status from fastapi import status
from fastapi.responses import JSONResponse 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 = { pagination_dict = {
"size/total_count": [response.count, total_count], "size/total_count": [cls.result.count, total_count],
"page/total_page": [pagination.page, total_page_number], "page/total_page": [filter_model.page, total_page_number],
"order_field": pagination.order_field, "order_field": filter_model.order_field,
"order_type": pagination.order_type, "order_type": filter_model.order_type,
} }
include_joins = dict( 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 []
) )
data = []
if not isinstance(response.data[0], dict): for data_object in cls.result.data:
data = [] data_dict = data_object.get_dict(include_joins=include_joins)
for obj in response.data: if cls.response_model:
data_object = obj.get_dict(**include_joins) data_dict = cls.response_model(**data_object.get_dict(include_joins=include_joins)).dump()
if response_model: data.append(data_dict)
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)
return JSONResponse( return JSONResponse(
status_code=status.HTTP_200_OK, status_code=cls.status_code,
content=dict( content=dict(
total_count=total_count,
count=cls.result.count,
pagination=pagination_dict, pagination=pagination_dict,
message="Found records are listed", message=cls.message,
completed=True, completed=cls.completed,
data=data, 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=[],
),
)

View File

@ -6,18 +6,18 @@ from api_validations.validations_request import (
) )
class DecisionBookDecisionBookInvitations(PydanticBaseModel): class DecisionBookDecisionBookInvitations(BaseModelRegular):
build_decision_book_uu_id: str build_decision_book_uu_id: str
message: str message: str
planned_date: str planned_date: str
class DecisionBookDecisionBookInvitationsAttend(PydanticBaseModel): class DecisionBookDecisionBookInvitationsAttend(BaseModelRegular):
token: str token: str
is_attend: bool is_attend: bool
class DecisionBookDecisionBookInvitationsAssign(PydanticBaseModel): class DecisionBookDecisionBookInvitationsAssign(BaseModelRegular):
token: str token: str
build_living_space_uu_id: str build_living_space_uu_id: str
occupant_type_uu_id: str occupant_type_uu_id: str
@ -28,7 +28,7 @@ class DecisionBookDecisionBookInvitationsUpdate(PydanticBaseModel):
occupant_type_uu_id: Optional[str] = None occupant_type_uu_id: Optional[str] = None
class ListDecisionBook(PydanticBaseModel): class ListDecisionBook(ListOptions, PydanticBaseModel):
build_decision_book_uu_id: Optional[str] = None build_decision_book_uu_id: Optional[str] = None
@ -42,12 +42,12 @@ class InsertDecisionBook(PydanticBaseModel):
resp_company_uu_id: Optional[str] = None resp_company_uu_id: Optional[str] = None
class InsertDecisionBookCompleted(PydanticBaseModel): class InsertDecisionBookCompleted(BaseModelRegular):
build_decision_book_uu_id: str build_decision_book_uu_id: str
meeting_completed_date: str meeting_completed_date: str
class InsertDecisionBookPerson(PydanticBaseModel): class InsertDecisionBookPerson(BaseModelRegular):
person_uu_id: str person_uu_id: str
build_decision_book_uu_id: str build_decision_book_uu_id: str
management_typecode_uu_id: str management_typecode_uu_id: str
@ -74,7 +74,7 @@ class UpdateDecisionBook(PydanticBaseModel):
resp_company_uu_id: Optional[str] = None resp_company_uu_id: Optional[str] = None
class InsertBuildDecisionBookItems(PydanticBaseModel): class InsertBuildDecisionBookItems(BaseModelRegular):
token: str token: str
info_type_uu_id: str info_type_uu_id: str
unit_price: float unit_price: float
@ -94,7 +94,7 @@ class UpdateBuildDecisionBookItems(PydanticBaseModel):
item_objection: Optional[str] = None item_objection: Optional[str] = None
class InsertBuildDecisionBookItemDebits(PydanticBaseModel): class InsertBuildDecisionBookItemDebits(BaseModelRegular):
build_decision_book_item_uu_id: str build_decision_book_item_uu_id: str
dues_values: dict dues_values: dict
# dues_types_uu_id: str # dues_types_uu_id: str

View File

@ -198,7 +198,7 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
for record in self.__class__.__dict__ for record in self.__class__.__dict__
if "_" not in record[0] and "id" not in record[-2:] if "_" not in record[0] and "id" not in record[-2:]
] ]
include_joins = include_joins or []
for all_argument in all_arguments: for all_argument in all_arguments:
column = getattr(self.__class__, all_argument) column = getattr(self.__class__, all_argument)
is_populate = isinstance(column, InstrumentedAttribute) and not hasattr( is_populate = isinstance(column, InstrumentedAttribute) and not hasattr(

View File

@ -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) 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. filter_attr = None # The filter attributes to use in the model.
FilterModel: ListOptions = ListOptions FilterModel = ListOptions
def flush(self): def flush(self):
"""Flush the current session.""" """Flush the current session."""

View File

@ -84,7 +84,6 @@ services:
- network_store_services - network_store_services
depends_on: depends_on:
- wag_management_service - wag_management_service
# - commercial_mongo_service
wag_management_test_service: wag_management_test_service:
container_name: wag_management_test_service container_name: wag_management_test_service
@ -96,7 +95,6 @@ services:
depends_on: depends_on:
- wag_management_init_service - 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: mail_service:
container_name: mail_service container_name: mail_service
restart: on-failure restart: on-failure

View File

@ -10,9 +10,9 @@ from handlers_exception import (
exception_handler_exception, exception_handler_exception,
) )
from prometheus_fastapi_instrumentator import Instrumentator 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() app = create_app()
Instrumentator().instrument(app=app).expose(app=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) app.add_exception_handler(Exception, exception_handler_exception)
create_endpoints_from_api_functions(api_app=app) 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__": if __name__ == "__main__":
uvicorn_config = { uvicorn_config = {
"app": "app:app", "app": "app:app",

View File

@ -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_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 ( from databases import (
BuildArea, BuildArea,
Build, Build,

View File

@ -13,7 +13,7 @@ from api_validations.validations_request import (
from databases import BuildSites from databases import BuildSites
from api_services.redis.auth_actions.token import parse_token_object_to_dict 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"]) build_sites_route = APIRouter(prefix="/building/sites", tags=["Building Sites"])

View File

@ -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_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 from databases import BuildTypes

View File

@ -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_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 from databases import BuildDecisionBookProjects

View File

@ -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_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 from databases import BuildDecisionBook, Build

View File

@ -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(): 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("Service is booting up")
print("Sending mail to users that have received email from banks") print("Sending mail to users that have received email from banks")