events updated

This commit is contained in:
berkay 2024-12-29 19:16:26 +03:00
parent 5223f36da7
commit 7997e561f7
12 changed files with 250 additions and 31 deletions

View File

@ -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"

View File

@ -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",

View File

@ -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,

View File

@ -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,
)

View File

@ -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,
)

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()