migrator completed
This commit is contained in:
parent
ac037ae54a
commit
1ae1264ace
|
|
@ -56,6 +56,9 @@ from api_events.events.building.building_build_sites import (
|
||||||
BuildSitesCreateEventMethod,
|
BuildSitesCreateEventMethod,
|
||||||
BuildSitesUpdateEventMethod,
|
BuildSitesUpdateEventMethod,
|
||||||
)
|
)
|
||||||
|
from api_events.events.building.building_build_types import (
|
||||||
|
BuildTypesListEventMethod,
|
||||||
|
)
|
||||||
from api_events.events.company.company_company import (
|
from api_events.events.company.company_company import (
|
||||||
CompanyListEventMethod,
|
CompanyListEventMethod,
|
||||||
CompanyCreateEventMethod,
|
CompanyCreateEventMethod,
|
||||||
|
|
@ -182,6 +185,7 @@ __all__ = [
|
||||||
"BuildSitesListEventMethod",
|
"BuildSitesListEventMethod",
|
||||||
"BuildSitesCreateEventMethod",
|
"BuildSitesCreateEventMethod",
|
||||||
"BuildSitesUpdateEventMethod",
|
"BuildSitesUpdateEventMethod",
|
||||||
|
"BuildTypesListEventMethod",
|
||||||
"DecisionBookListEventMethod",
|
"DecisionBookListEventMethod",
|
||||||
"DecisionBookCreateEventMethod",
|
"DecisionBookCreateEventMethod",
|
||||||
"DecisionBookUpdateEventMethod",
|
"DecisionBookUpdateEventMethod",
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,9 @@ from databases import (
|
||||||
from api_validations.validations_request import (
|
from api_validations.validations_request import (
|
||||||
ListOptions,
|
ListOptions,
|
||||||
InsertAddress,
|
InsertAddress,
|
||||||
|
UpdateAddress,
|
||||||
InsertPostCode,
|
InsertPostCode,
|
||||||
|
UpdatePostCode,
|
||||||
SearchAddress,
|
SearchAddress,
|
||||||
)
|
)
|
||||||
from api_validations.core_response import AlchemyJsonResponse
|
from api_validations.core_response import AlchemyJsonResponse
|
||||||
|
|
@ -117,16 +119,19 @@ class AddressCreateEventMethods(MethodToEvent):
|
||||||
|
|
||||||
data_dict = data.excluded_dump()
|
data_dict = data.excluded_dump()
|
||||||
data_dict["street_id"] = post_code.street_id
|
data_dict["street_id"] = post_code.street_id
|
||||||
|
data_dict["street_uu_id"] = str(post_code.street_uu_id)
|
||||||
del data_dict["post_code_uu_id"]
|
del data_dict["post_code_uu_id"]
|
||||||
data_dict["is_confirmed"] = True
|
|
||||||
address = Addresses.find_or_create(**data_dict)
|
address = Addresses.find_or_create(**data_dict)
|
||||||
RelationshipEmployee2PostCode.find_or_create(
|
relation_employee = RelationshipEmployee2PostCode.find_or_create(
|
||||||
employee_id=token_dict.selected_company.employee_id,
|
employee_id=token_dict.selected_company.employee_id,
|
||||||
member_id=post_code.id,
|
member_id=post_code.id,
|
||||||
company_id=token_dict.selected_company.company_id,
|
company_id=token_dict.selected_company.company_id,
|
||||||
is_confirmed=True,
|
|
||||||
)
|
)
|
||||||
Addresses.save()
|
address.save()
|
||||||
|
address.update(is_confirmed=True)
|
||||||
|
address.save()
|
||||||
|
relation_employee.update(is_confirmed=True)
|
||||||
|
relation_employee.save()
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
"completed": True,
|
"completed": True,
|
||||||
|
|
@ -220,29 +225,21 @@ class AddressUpdateEventMethods(MethodToEvent):
|
||||||
def update_address(
|
def update_address(
|
||||||
cls,
|
cls,
|
||||||
address_uu_id: str,
|
address_uu_id: str,
|
||||||
data: InsertAddress,
|
data: UpdateAddress,
|
||||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||||
):
|
):
|
||||||
|
if isinstance(token_dict, EmployeeTokenObject):
|
||||||
address = Addresses.filter_one(
|
address = Addresses.filter_one(
|
||||||
Addresses.uu_id == address_uu_id,
|
Addresses.uu_id == address_uu_id,
|
||||||
*Addresses.valid_record_args(Addresses),
|
*Addresses.valid_record_args(Addresses),
|
||||||
)
|
|
||||||
post_code = RelationshipEmployee2PostCode.filter_one(
|
|
||||||
RelationshipEmployee2PostCode.member_id == address.post_code_id,
|
|
||||||
*RelationshipEmployee2PostCode.valid_record_args(
|
|
||||||
RelationshipEmployee2PostCode
|
|
||||||
),
|
|
||||||
).data
|
).data
|
||||||
if not post_code:
|
if not address:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=404,
|
status_code=404,
|
||||||
detail="Post code not found. User can not update address without post code.",
|
detail=f"Address not found. User can not update with given address uuid : {address_uu_id}",
|
||||||
)
|
)
|
||||||
|
|
||||||
data_dict = data.excluded_dump()
|
data_dict = data.excluded_dump()
|
||||||
data_dict["post_code_id"] = post_code.id
|
|
||||||
del data_dict["post_code_uu_id"]
|
|
||||||
data_dict["is_confirmed"] = True
|
|
||||||
updated_address = address.update(**data_dict)
|
updated_address = address.update(**data_dict)
|
||||||
updated_address.save()
|
updated_address.save()
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
|
|
@ -253,6 +250,11 @@ class AddressUpdateEventMethods(MethodToEvent):
|
||||||
},
|
},
|
||||||
status_code=200,
|
status_code=200,
|
||||||
)
|
)
|
||||||
|
elif isinstance(token_dict, OccupantTokenObject):
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=403,
|
||||||
|
detail="Occupant can not update address.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class AddressPatchEventMethods(MethodToEvent):
|
class AddressPatchEventMethods(MethodToEvent):
|
||||||
|
|
@ -325,16 +327,19 @@ class AddressPostCodeCreateEventMethods(MethodToEvent):
|
||||||
)
|
)
|
||||||
data_dump["street_id"] = street.id
|
data_dump["street_id"] = street.id
|
||||||
data_dump["postcode"] = data.post_code
|
data_dump["postcode"] = data.post_code
|
||||||
del data_dump["street_uu_id"], data_dump["post_code"]
|
del data_dump["post_code"]
|
||||||
|
|
||||||
post_code = AddressPostcode.find_or_create(**data_dump)
|
post_code = AddressPostcode.find_or_create(**data_dump)
|
||||||
AddressPostcode.__many__table__.find_or_create(
|
relation_table = AddressPostcode.__many__table__.find_or_create(
|
||||||
member_id=post_code.id,
|
member_id=post_code.id,
|
||||||
employee_id=token_dict.selected_company.employee_id,
|
employee_id=token_dict.selected_company.employee_id,
|
||||||
company_id=token_dict.selected_company.company_id,
|
company_id=token_dict.selected_company.company_id,
|
||||||
is_confirmed=True,
|
|
||||||
)
|
)
|
||||||
AddressStreet.save()
|
post_code.save()
|
||||||
|
post_code.update(is_confirmed=True)
|
||||||
|
post_code.save()
|
||||||
|
relation_table.update(is_confirmed=True)
|
||||||
|
relation_table.save()
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
"completed": True,
|
"completed": True,
|
||||||
|
|
@ -356,22 +361,25 @@ class AddressPostCodeUpdateEventMethods(MethodToEvent):
|
||||||
def update_post_code_address(
|
def update_post_code_address(
|
||||||
cls,
|
cls,
|
||||||
post_code_uu_id: str,
|
post_code_uu_id: str,
|
||||||
data: InsertPostCode,
|
data: UpdatePostCode,
|
||||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||||
):
|
):
|
||||||
|
if isinstance(token_dict, EmployeeTokenObject):
|
||||||
|
AddressPostcode.pre_query = AddressPostcode.select_action(
|
||||||
|
employee_id=token_dict.selected_company.employee_id,
|
||||||
|
)
|
||||||
post_code = AddressPostcode.filter_one(
|
post_code = AddressPostcode.filter_one(
|
||||||
AddressPostcode.uu_id == post_code_uu_id
|
AddressPostcode.uu_id == post_code_uu_id,
|
||||||
|
*AddressPostcode.valid_record_args(AddressPostcode),
|
||||||
).data
|
).data
|
||||||
street = AddressStreet.filter_one(
|
if not post_code:
|
||||||
AddressPostcode.uu_id == data.street_uu_id
|
|
||||||
).data
|
|
||||||
if not street:
|
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=404,
|
status_code=404,
|
||||||
detail="Street not found. User can not update post code without street.",
|
detail="Street not found. User can not update post code without street.",
|
||||||
)
|
)
|
||||||
|
|
||||||
updated_post_code = post_code.update(**data.excluded_dump())
|
data_dict = data.excluded_dump()
|
||||||
|
updated_post_code = post_code.update(**data_dict)
|
||||||
updated_post_code.save()
|
updated_post_code.save()
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
|
|
@ -381,6 +389,19 @@ class AddressPostCodeUpdateEventMethods(MethodToEvent):
|
||||||
},
|
},
|
||||||
status_code=200,
|
status_code=200,
|
||||||
)
|
)
|
||||||
|
elif isinstance(token_dict, OccupantTokenObject):
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=403,
|
||||||
|
detail="Occupant can not update post code.",
|
||||||
|
)
|
||||||
|
return JSONResponse(
|
||||||
|
content={
|
||||||
|
"completed": True,
|
||||||
|
"message": "Update Post Code record",
|
||||||
|
"data": {},
|
||||||
|
},
|
||||||
|
status_code=404,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class AddressPostCodeListEventMethods(MethodToEvent):
|
class AddressPostCodeListEventMethods(MethodToEvent):
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,6 @@ class AuthenticationLoginEventMethods(MethodToEvent):
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
detail="This User has no active role registered. Please contact your administrator.",
|
detail="This User has no active role registered. Please contact your administrator.",
|
||||||
)
|
)
|
||||||
|
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
"completed": True,
|
"completed": True,
|
||||||
|
|
|
||||||
|
|
@ -107,11 +107,20 @@ class BuildCreateEventMethods(MethodToEvent):
|
||||||
part_direction_uu_id=str(api_enum.uu_id),
|
part_direction_uu_id=str(api_enum.uu_id),
|
||||||
part_code="MAN-ROOM",
|
part_code="MAN-ROOM",
|
||||||
human_livable=False,
|
human_livable=False,
|
||||||
is_confirmed=True,
|
|
||||||
)
|
)
|
||||||
man_build_part = BuildParts.find_or_create(**build_parts)
|
man_build_part = BuildParts.find_or_create(**build_parts)
|
||||||
|
created_build.save()
|
||||||
created_build.update(management_room_id=man_build_part.id)
|
created_build.update(management_room_id=man_build_part.id)
|
||||||
BuildParts.save()
|
created_build.save()
|
||||||
|
man_build_part.update(is_confirmed=True)
|
||||||
|
man_build_part.save()
|
||||||
|
# created_build_relation = RelationshipEmployee2Build.find_or_create(
|
||||||
|
# company_id=token_dict.selected_company.company_id,
|
||||||
|
# member_id=created_build.id,
|
||||||
|
# employee_id=token_dict.selected_company.employee_id,
|
||||||
|
# )
|
||||||
|
# created_build_relation.update(is_confirmed=True)
|
||||||
|
# created_build_relation.save()
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
"completed": True,
|
"completed": True,
|
||||||
|
|
@ -147,12 +156,13 @@ class BuildCreateEventMethods(MethodToEvent):
|
||||||
)
|
)
|
||||||
|
|
||||||
created_build = Build.create_action(data=data, token=token_dict)
|
created_build = Build.create_action(data=data, token=token_dict)
|
||||||
RelationshipEmployee2Build.find_or_create(
|
|
||||||
|
created_build_relation = RelationshipEmployee2Build.find_or_create(
|
||||||
company_id=token_dict.selected_company.company_id,
|
company_id=token_dict.selected_company.company_id,
|
||||||
member_id=created_build.id,
|
member_id=created_build.id,
|
||||||
employee_id=token_dict.selected_company.employee_id,
|
employee_id=token_dict.selected_company.employee_id,
|
||||||
is_confirmed=True,
|
|
||||||
)
|
)
|
||||||
|
created_build.save()
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
"completed": True,
|
"completed": True,
|
||||||
|
|
@ -207,7 +217,10 @@ class BuildPatchEventMethods(MethodToEvent):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def build_patch(cls, build_uu_id: str, data: PatchRecord, token_dict):
|
def build_patch(cls, build_uu_id: str, data: PatchRecord, token_dict):
|
||||||
find_one_build = Build.find_one_or_abort(uu_id=build_uu_id)
|
find_one_build = Build.filter_one(
|
||||||
|
Build.uu_id==build_uu_id,
|
||||||
|
*Build.valid_record_args(Build)
|
||||||
|
)
|
||||||
access_authorized_build = Build.select_action(
|
access_authorized_build = Build.select_action(
|
||||||
employee_id=token_dict.selected_company.employee_id,
|
employee_id=token_dict.selected_company.employee_id,
|
||||||
filter_expr=[Build.id == find_one_build.id],
|
filter_expr=[Build.id == find_one_build.id],
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,8 @@ class BuildAreaCreateEventMethods(MethodToEvent):
|
||||||
data: InsertBuildArea,
|
data: InsertBuildArea,
|
||||||
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
||||||
):
|
):
|
||||||
|
data_dict = data.excluded_dump()
|
||||||
|
selected_build = None
|
||||||
if isinstance(token_dict, OccupantTokenObject):
|
if isinstance(token_dict, OccupantTokenObject):
|
||||||
if not token_dict.selected_occupant.build_uuid == data.build_uu_id:
|
if not token_dict.selected_occupant.build_uuid == data.build_uu_id:
|
||||||
BuildArea.raise_http_exception(
|
BuildArea.raise_http_exception(
|
||||||
|
|
@ -78,6 +80,7 @@ class BuildAreaCreateEventMethods(MethodToEvent):
|
||||||
"build_uu_id": data.build_uu_id,
|
"build_uu_id": data.build_uu_id,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
selected_build = Build.filter_by_one(system=True, uu_id=data.build_uu_id).data
|
||||||
elif isinstance(token_dict, EmployeeTokenObject):
|
elif isinstance(token_dict, EmployeeTokenObject):
|
||||||
build_ids = Build.select_action(
|
build_ids = Build.select_action(
|
||||||
employee_id=token_dict.selected_company.employee_id
|
employee_id=token_dict.selected_company.employee_id
|
||||||
|
|
@ -91,7 +94,10 @@ class BuildAreaCreateEventMethods(MethodToEvent):
|
||||||
"build_uu_id": data.build_uu_id,
|
"build_uu_id": data.build_uu_id,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
data_dict = data.excluded_dump()
|
selected_build = Build.filter_by_one(system=True, uu_id=data.build_uu_id).data
|
||||||
|
|
||||||
|
data_dict["build_id"] = selected_build.id
|
||||||
|
data_dict["build_uu_id"] = str(selected_build.uu_id)
|
||||||
created_build_part = BuildArea.find_or_create(**data_dict)
|
created_build_part = BuildArea.find_or_create(**data_dict)
|
||||||
created_build_part.save()
|
created_build_part.save()
|
||||||
created_build_part.update(is_confirmed=True)
|
created_build_part.update(is_confirmed=True)
|
||||||
|
|
@ -99,7 +105,7 @@ class BuildAreaCreateEventMethods(MethodToEvent):
|
||||||
return AlchemyJsonResponse(
|
return AlchemyJsonResponse(
|
||||||
completed=True,
|
completed=True,
|
||||||
message="Created Build Area",
|
message="Created Build Area",
|
||||||
result=created_build_part,
|
result=created_build_part.get_dict(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,49 @@
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
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 AlchemyJsonResponse
|
||||||
|
from api_validations.validations_request import (
|
||||||
|
ListOptions,
|
||||||
|
)
|
||||||
|
from databases.sql_models.building.build import BuildTypes
|
||||||
|
|
||||||
|
|
||||||
class BuildingBuildTypesEvents(MethodToEvent): ...
|
class BuildTypesListEventMethods(MethodToEvent):
|
||||||
|
|
||||||
|
event_type = "SELECT"
|
||||||
|
__event_keys__ = {
|
||||||
|
"5344d03c-fc47-43ec-8c44-6c2acd7e5d9f": "build_types_list",
|
||||||
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def build_types_list(
|
||||||
|
cls,
|
||||||
|
list_options: ListOptions,
|
||||||
|
token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
||||||
|
):
|
||||||
|
from fastapi.exceptions import HTTPException
|
||||||
|
if isinstance(token_dict, EmployeeTokenObject):
|
||||||
|
BuildTypes.filter_attr = list_options
|
||||||
|
results = BuildTypes.filter_all(
|
||||||
|
*BuildTypes.valid_record_args(BuildTypes)
|
||||||
|
)
|
||||||
|
return AlchemyJsonResponse(
|
||||||
|
completed=True,
|
||||||
|
result=results,
|
||||||
|
message="Build Types are listed successfully",
|
||||||
|
)
|
||||||
|
elif isinstance(token_dict, OccupantTokenObject):
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=403,
|
||||||
|
detail="You are not authorized to access this endpoint"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=403,
|
||||||
|
detail="You are not authorized to access this endpoint"
|
||||||
|
)
|
||||||
|
|
||||||
|
BuildTypesListEventMethod = BuildTypesListEventMethods(
|
||||||
|
action=ActionsSchema(endpoint="/building/types/list")
|
||||||
|
)
|
||||||
|
|
@ -131,7 +131,10 @@ class CompanyPatchEventMethods(MethodToEvent):
|
||||||
def company_patch(
|
def company_patch(
|
||||||
cls, company_uu_id: str, data: PatchRecord, token_dict: EmployeeTokenObject
|
cls, company_uu_id: str, data: PatchRecord, token_dict: EmployeeTokenObject
|
||||||
):
|
):
|
||||||
find_one_company = Companies.find_one_or_abort(uu_id=company_uu_id)
|
find_one_company = Companies.filter_one(
|
||||||
|
Companies.uu_id==company_uu_id,
|
||||||
|
*Companies.valid_record_args(Companies)
|
||||||
|
).data
|
||||||
access_authorized_company = Companies.select_action(
|
access_authorized_company = Companies.select_action(
|
||||||
duty_id_list=[
|
duty_id_list=[
|
||||||
token_dict.selected_company.bulk_duties_id,
|
token_dict.selected_company.bulk_duties_id,
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ class SuperUserEventBlock(AddEventFunctionality):
|
||||||
{"function_code": "f6900cb5-ac5b-478e-8e7c-fa87e65cd2e5"},
|
{"function_code": "f6900cb5-ac5b-478e-8e7c-fa87e65cd2e5"},
|
||||||
{"function_code": "76f11a08-5f4a-4e1f-961f-aaef21699acd"},
|
{"function_code": "76f11a08-5f4a-4e1f-961f-aaef21699acd"},
|
||||||
{"function_code": "41ea7f29-006a-4310-b5c4-b2a0e1a504bd"},
|
{"function_code": "41ea7f29-006a-4310-b5c4-b2a0e1a504bd"},
|
||||||
|
{"function_code": "5344d03c-fc47-43ec-8c44-6c2acd7e5d9f"},
|
||||||
]
|
]
|
||||||
|
|
||||||
def __new__(cls, *args, **kwargs):
|
def __new__(cls, *args, **kwargs):
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,13 @@ from .core_request_validations import (
|
||||||
EndpointPydantic,
|
EndpointPydantic,
|
||||||
BaseModelRegular,
|
BaseModelRegular,
|
||||||
)
|
)
|
||||||
from .address import InsertAddress, InsertPostCode, SearchAddress
|
from .address import (
|
||||||
|
InsertAddress,
|
||||||
|
UpdateAddress,
|
||||||
|
UpdatePostCode,
|
||||||
|
InsertPostCode,
|
||||||
|
SearchAddress
|
||||||
|
)
|
||||||
from .application import (
|
from .application import (
|
||||||
SingleEnumUUID,
|
SingleEnumUUID,
|
||||||
SingleEnumClassKey,
|
SingleEnumClassKey,
|
||||||
|
|
@ -138,6 +144,8 @@ __all__ = [
|
||||||
"EndpointPydantic",
|
"EndpointPydantic",
|
||||||
"BaseModelRegular",
|
"BaseModelRegular",
|
||||||
"InsertAddress",
|
"InsertAddress",
|
||||||
|
"UpdateAddress",
|
||||||
|
"UpdatePostCode",
|
||||||
"InsertPostCode",
|
"InsertPostCode",
|
||||||
"SearchAddress",
|
"SearchAddress",
|
||||||
"SingleEnumUUID",
|
"SingleEnumUUID",
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,16 @@ from api_validations.validations_request import (
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
class InsertPostCode(PydanticBaseModel):
|
class InsertPostCode(BaseModelRegular):
|
||||||
street_uu_id: str
|
street_uu_id: str
|
||||||
post_code: str
|
post_code: str
|
||||||
|
|
||||||
|
|
||||||
|
class UpdatePostCode(PydanticBaseModel):
|
||||||
|
street_uu_id: Optional[str] = None
|
||||||
|
post_code: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class SearchAddress(PydanticBaseModel):
|
class SearchAddress(PydanticBaseModel):
|
||||||
search: str
|
search: str
|
||||||
list_options: ListOptions
|
list_options: ListOptions
|
||||||
|
|
@ -27,7 +32,7 @@ class InsertStreet(PydanticBaseModel):
|
||||||
address_geographic_uu_id: Optional[str] = None
|
address_geographic_uu_id: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class InsertAddress(PydanticBaseModel):
|
class InsertAddress(BaseModelRegular):
|
||||||
post_code_uu_id: str
|
post_code_uu_id: str
|
||||||
|
|
||||||
comment_address: Optional[str] = None
|
comment_address: Optional[str] = None
|
||||||
|
|
@ -42,14 +47,13 @@ class InsertAddress(PydanticBaseModel):
|
||||||
longitude: Optional[float] = None
|
longitude: Optional[float] = None
|
||||||
|
|
||||||
|
|
||||||
class _UpdateAddress(PydanticBaseModel):
|
class UpdateAddress(PydanticBaseModel):
|
||||||
...
|
country_code: Optional[str] = None
|
||||||
# country_code: Optional[str] = None
|
city: Optional[str] = None
|
||||||
# city: Optional[str] = None
|
district: Optional[str] = None
|
||||||
# district: Optional[str] = None
|
b_state: Optional[str] = None
|
||||||
# b_state: Optional[str] = None
|
neighborhood: Optional[str] = None
|
||||||
# neighborhood: Optional[str] = None
|
street: Optional[str] = None
|
||||||
# street: Optional[str] = None
|
postcode: Optional[str] = None
|
||||||
# postcode: Optional[str] = None
|
latitude: Optional[float] = None
|
||||||
# latitude: Optional[float] = None
|
longitude: Optional[float] = None
|
||||||
# longitude: Optional[float] = None
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import typing
|
import typing
|
||||||
from operator import or_
|
from operator import or_
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from platform import system
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from fastapi import HTTPException, status
|
from fastapi import HTTPException, status
|
||||||
|
|
@ -174,10 +175,10 @@ class Build(CrudCollection, SelectActionWithEmployee):
|
||||||
Integer, nullable=True, comment="Management Room ID"
|
Integer, nullable=True, comment="Management Room ID"
|
||||||
)
|
)
|
||||||
|
|
||||||
site_id: Mapped[int] = mapped_column(ForeignKey("build_sites.id"))
|
site_id: Mapped[int] = mapped_column(ForeignKey("build_sites.id"), nullable=True)
|
||||||
site_uu_id: Mapped[str] = mapped_column(String, comment="Site UUID")
|
site_uu_id: Mapped[str] = mapped_column(String, comment="Site UUID", nullable=True)
|
||||||
address_id: Mapped[int] = mapped_column(ForeignKey("addresses.id"))
|
address_id: Mapped[int] = mapped_column(ForeignKey("addresses.id"), nullable=False)
|
||||||
address_uu_id: Mapped[str] = mapped_column(String, comment="Address UUID")
|
address_uu_id: Mapped[str] = mapped_column(String, comment="Address UUID", nullable=False)
|
||||||
build_types_id: Mapped[int] = mapped_column(
|
build_types_id: Mapped[int] = mapped_column(
|
||||||
ForeignKey("build_types.id"), nullable=False, comment="Building Type"
|
ForeignKey("build_types.id"), nullable=False, comment="Building Type"
|
||||||
)
|
)
|
||||||
|
|
@ -243,22 +244,24 @@ class Build(CrudCollection, SelectActionWithEmployee):
|
||||||
).data
|
).data
|
||||||
data_dict["address_id"] = official_address.id
|
data_dict["address_id"] = official_address.id
|
||||||
data_dict["build_no"] = str(official_address.build_number)
|
data_dict["build_no"] = str(official_address.build_number)
|
||||||
data_dict.pop("address_uu_id", None)
|
|
||||||
if not data_dict["address_id"]:
|
if not data_dict["address_id"]:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
detail="Address is not found in database. Re-enter address record then try again.",
|
detail="Address is not found in database. Re-enter address record then try again.",
|
||||||
)
|
)
|
||||||
build_type = BuildTypes.find_one(uu_id=str(data.build_types_uu_id))
|
build_type = BuildTypes.filter_by_one(system=True, uu_id=str(data.build_types_uu_id)).data
|
||||||
data_dict["build_types_id"] = build_type.id
|
data_dict["build_types_id"] = build_type.id
|
||||||
del data_dict["build_types_uu_id"]
|
|
||||||
build_created = cls.find_or_create(**data_dict)
|
build_created = cls.find_or_create(**data_dict)
|
||||||
cls.__many__table__.find_or_create(
|
created_build_relation = cls.__many__table__.find_or_create(
|
||||||
company_id=token.selected_company.company_id,
|
company_id=token.selected_company.company_id,
|
||||||
employee_id=token.selected_company.employee_id,
|
employee_id=token.selected_company.employee_id,
|
||||||
member_id=build_created.id,
|
member_id=build_created.id,
|
||||||
is_confirmed=True,
|
|
||||||
)
|
)
|
||||||
|
build_created.save()
|
||||||
|
build_created.update(is_confirmed=True)
|
||||||
|
build_created.save()
|
||||||
|
created_build_relation.update(is_confirmed=True)
|
||||||
|
created_build_relation.save()
|
||||||
return build_created
|
return build_created
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -316,7 +319,7 @@ class Build(CrudCollection, SelectActionWithEmployee):
|
||||||
building_types = None
|
building_types = None
|
||||||
for part in self.parts:
|
for part in self.parts:
|
||||||
building_types = {}
|
building_types = {}
|
||||||
build_type = BuildTypes.find_one(id=part.build_part_type_id)
|
build_type = BuildTypes.filter_by_one(system=True, id=part.build_part_type_id).data
|
||||||
if build_type.type_code in building_types:
|
if build_type.type_code in building_types:
|
||||||
building_types[build_type.type_code]["list"].append(part.part_no)
|
building_types[build_type.type_code]["list"].append(part.part_no)
|
||||||
else:
|
else:
|
||||||
|
|
@ -412,13 +415,14 @@ class BuildParts(CrudCollection):
|
||||||
building = build_from_duty.first()
|
building = build_from_duty.first()
|
||||||
if not building:
|
if not building:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_418_IM_A_TEAPOT,
|
status_code=status.HTTP_406_NOT_ACCEPTABLE,
|
||||||
detail="This Employee can not reach this building or building uu-id not found in database. "
|
detail="This Employee can not reach this building or building uu-id not found in database. "
|
||||||
"Check with your supervisor.",
|
"Check with your supervisor.",
|
||||||
)
|
)
|
||||||
|
|
||||||
if build_types := BuildTypes.filter_one(
|
if build_types := BuildTypes.filter_one(
|
||||||
BuildTypes.uu_id == data.build_part_type_uu_id
|
BuildTypes.uu_id == data.build_part_type_uu_id,
|
||||||
|
*BuildTypes.valid_record_args(BuildTypes)
|
||||||
).data:
|
).data:
|
||||||
part_direction = ApiEnumDropdown.get_by_uuid(
|
part_direction = ApiEnumDropdown.get_by_uuid(
|
||||||
uuid=str(data.part_direction_uu_id)
|
uuid=str(data.part_direction_uu_id)
|
||||||
|
|
@ -467,7 +471,7 @@ class BuildParts(CrudCollection):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def part_name(self):
|
def part_name(self):
|
||||||
if build_type := BuildTypes.find_one(id=self.build_part_type_id):
|
if build_type := BuildTypes.filter_by_one(system=True, id=self.build_part_type_id).data:
|
||||||
return f"{str(build_type.type_name).upper()} : {str(self.part_no).upper()}"
|
return f"{str(build_type.type_name).upper()} : {str(self.part_no).upper()}"
|
||||||
return f"Undefined:{str(build_type.type_name).upper()}"
|
return f"Undefined:{str(build_type.type_name).upper()}"
|
||||||
|
|
||||||
|
|
@ -594,6 +598,7 @@ class BuildArea(CrudCollection):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__tablename__ = "build_area"
|
__tablename__ = "build_area"
|
||||||
|
__exclude__fields__ = []
|
||||||
|
|
||||||
area_name: Mapped[str] = mapped_column(String, server_default="")
|
area_name: Mapped[str] = mapped_column(String, server_default="")
|
||||||
area_code: Mapped[str] = mapped_column(String, server_default="")
|
area_code: Mapped[str] = mapped_column(String, server_default="")
|
||||||
|
|
|
||||||
|
|
@ -125,35 +125,34 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
||||||
row_attr = bool(getattr(getattr(cls, key), "foreign_keys", None))
|
row_attr = bool(getattr(getattr(cls, key), "foreign_keys", None))
|
||||||
if is_primary or row_attr and key_ == Mapped[int]:
|
if is_primary or row_attr and key_ == Mapped[int]:
|
||||||
return False, None
|
return False, None
|
||||||
|
elif val is None:
|
||||||
if key_:
|
return True, None
|
||||||
|
elif str(key[-5:]).lower() == "uu_id":
|
||||||
|
return True, str(val)
|
||||||
|
elif key_:
|
||||||
if key_ == Mapped[int]:
|
if key_ == Mapped[int]:
|
||||||
return True, int(val) if val is not None else None
|
return True, int(val)
|
||||||
elif key_ == Mapped[bool]:
|
elif key_ == Mapped[bool]:
|
||||||
return True, bool(val) if val is not None else None
|
return True, bool(val)
|
||||||
elif key_ == Mapped[float] or key_ == Mapped[NUMERIC]:
|
elif key_ == Mapped[float] or key_ == Mapped[NUMERIC]:
|
||||||
return True, round(float(val), 3) if val is not None else None
|
return True, round(float(val), 3)
|
||||||
elif key_ == Mapped[int]:
|
elif key_ == Mapped[int]:
|
||||||
return True, int(val) if val is not None else None
|
return True, int(val)
|
||||||
elif key_ == Mapped[TIMESTAMP]:
|
elif key_ == Mapped[TIMESTAMP]:
|
||||||
formatted_date = client_arrow.get(str(val)).format(
|
return True, str(client_arrow.get(str(val)).format("DD-MM-YYYY HH:mm:ss"))
|
||||||
"DD-MM-YYYY HH:mm:ss"
|
elif key_ == Mapped[str]:
|
||||||
)
|
return True, str(val)
|
||||||
return True, str(formatted_date) if val is not None else None
|
|
||||||
else:
|
else:
|
||||||
if isinstance(val, datetime.datetime):
|
if isinstance(val, datetime.datetime):
|
||||||
formatted_date = client_arrow.get(str(val)).format(
|
return True, str(client_arrow.get(str(val)).format("DD-MM-YYYY HH:mm:ss"))
|
||||||
"DD-MM-YYYY HH:mm:ss"
|
|
||||||
)
|
|
||||||
return True, str(formatted_date) if val is not None else None
|
|
||||||
elif isinstance(value_type, bool):
|
elif isinstance(value_type, bool):
|
||||||
return True, bool(val) if val is not None else None
|
return True, bool(val)
|
||||||
elif isinstance(value_type, float) or isinstance(value_type, Decimal):
|
elif isinstance(value_type, float) or isinstance(value_type, Decimal):
|
||||||
return True, round(float(val), 3) if val is not None else None
|
return True, round(float(val), 3)
|
||||||
elif isinstance(value_type, int):
|
elif isinstance(value_type, int):
|
||||||
return True, int(val) if val is not None else None
|
return True, int(val)
|
||||||
elif isinstance(value_type, str):
|
elif isinstance(value_type, str):
|
||||||
return True, str(val) if val is not None else None
|
return True, str(val)
|
||||||
elif isinstance(value_type, type(None)):
|
elif isinstance(value_type, type(None)):
|
||||||
return True, None
|
return True, None
|
||||||
return False, None
|
return False, None
|
||||||
|
|
@ -242,10 +241,12 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
||||||
exclude_list = [
|
exclude_list = [
|
||||||
element
|
element
|
||||||
for element in self.__system_default_model__
|
for element in self.__system_default_model__
|
||||||
if str(element)[-2:] == "id"
|
if str(element)[-2:] == "id" and str(element)[-5:].lower() == 'uu_id'
|
||||||
]
|
]
|
||||||
columns_include_list = list(set(include).difference(set(exclude_list)))
|
columns_include_list = list(set(include).difference(set(exclude_list)))
|
||||||
columns_include_list.extend(["uu_id", "active"])
|
# columns_include_list.extend([column for column in self.columns if str(column)[-5:].lower() == 'uu_id'])
|
||||||
|
|
||||||
|
columns_include_list.extend(['uu_id'])
|
||||||
for key in list(columns_include_list):
|
for key in list(columns_include_list):
|
||||||
val = getattr(self, key)
|
val = getattr(self, key)
|
||||||
correct, value_of_database = self.iterate_over_variables(val, key)
|
correct, value_of_database = self.iterate_over_variables(val, key)
|
||||||
|
|
@ -262,7 +263,10 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
||||||
if str(element)[-2:] == "id"
|
if str(element)[-2:] == "id"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
columns_excluded_list = set(self.columns).difference(set(exclude))
|
columns_excluded_list = list(set(self.columns).difference(set(exclude)))
|
||||||
|
# columns_excluded_list.extend([column for column in self.columns if str(column)[-5:].lower() == 'uu_id'])
|
||||||
|
columns_excluded_list.extend(['uu_id', 'active'])
|
||||||
|
|
||||||
for key in list(columns_excluded_list):
|
for key in list(columns_excluded_list):
|
||||||
val = getattr(self, key)
|
val = getattr(self, key)
|
||||||
correct, value_of_database = self.iterate_over_variables(val, key)
|
correct, value_of_database = self.iterate_over_variables(val, key)
|
||||||
|
|
@ -274,16 +278,17 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
||||||
)
|
)
|
||||||
columns_list = list(set(self.columns).difference(set(exclude_list)))
|
columns_list = list(set(self.columns).difference(set(exclude_list)))
|
||||||
columns_list = [
|
columns_list = [
|
||||||
columns
|
columns for columns in columns_list if str(columns)[-2:] != "id"
|
||||||
for columns in columns_list
|
|
||||||
if str(columns)[-2:] != "id" and "uu_id" not in str(columns)
|
|
||||||
]
|
]
|
||||||
|
columns_list.extend([column for column in self.columns if str(column)[-5:].lower() == 'uu_id'])
|
||||||
|
for remove_field in self.__system_default_model__:
|
||||||
|
if remove_field in columns_list:
|
||||||
|
columns_list.remove(remove_field)
|
||||||
for key in list(columns_list):
|
for key in list(columns_list):
|
||||||
val = getattr(self, key)
|
val = getattr(self, key)
|
||||||
correct, value_of_database = self.iterate_over_variables(val, key)
|
correct, value_of_database = self.iterate_over_variables(val, key)
|
||||||
if correct:
|
if correct:
|
||||||
return_dict[key] = value_of_database
|
return_dict[key] = value_of_database
|
||||||
|
|
||||||
# all_arguments = [
|
# all_arguments = [
|
||||||
# record
|
# record
|
||||||
# for record in self.__class__.__dict__
|
# for record in self.__class__.__dict__
|
||||||
|
|
@ -305,7 +310,8 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
||||||
# return_dict[all_argument] = (
|
# return_dict[all_argument] = (
|
||||||
# populate_arg.get_dict() if populate_arg else []
|
# populate_arg.get_dict() if populate_arg else []
|
||||||
# )
|
# )
|
||||||
return dict(sorted(return_dict.items(), reverse=False))
|
# return dict(sorted(return_dict.items(), reverse=False))
|
||||||
|
return return_dict
|
||||||
|
|
||||||
|
|
||||||
class BaseMixin(CrudMixin, ReprMixin, SerializeMixin, FilterAttributes):
|
class BaseMixin(CrudMixin, ReprMixin, SerializeMixin, FilterAttributes):
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ from sqlalchemy.orm import (
|
||||||
Mapped,
|
Mapped,
|
||||||
mapped_column,
|
mapped_column,
|
||||||
)
|
)
|
||||||
from databases.sql_models.core_mixin import BaseCollection
|
from databases.sql_models.core_mixin import CrudCollection
|
||||||
|
|
||||||
|
|
||||||
class ApiEnumDropdown(BaseCollection):
|
class ApiEnumDropdown(CrudCollection):
|
||||||
__tablename__ = "api_enum_dropdown"
|
__tablename__ = "api_enum_dropdown"
|
||||||
__exclude__fields__ = ["enum_class"]
|
__exclude__fields__ = ["enum_class"]
|
||||||
|
|
||||||
|
|
@ -31,35 +31,30 @@ class ApiEnumDropdown(BaseCollection):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_by_uuid(cls, uuid: str):
|
def get_by_uuid(cls, uuid: str):
|
||||||
return cls.query.filter(cls.uu_id == uuid).first()
|
return cls.filter_by_one(system=True, uu_id=str(uuid)).data
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_debit_search(cls, search_debit: str = None, search_uu_id: str = None):
|
def get_debit_search(cls, search_debit: str = None, search_uu_id: str = None):
|
||||||
if search_uu_id:
|
if search_uu_id:
|
||||||
if search := cls.query.filter(
|
if search := cls.filter_one(
|
||||||
cls.enum_class.in_(["DebitTypes"]),
|
cls.enum_class.in_(["DebitTypes"]), cls.uu_id == search_uu_id, system=True
|
||||||
cls.uu_id == search_uu_id,
|
).data:
|
||||||
cls.active == True,
|
|
||||||
).first():
|
|
||||||
return search
|
return search
|
||||||
elif search_debit:
|
elif search_debit:
|
||||||
if search := cls.query.filter(
|
if search := cls.filter_one(
|
||||||
cls.enum_class.in_(["DebitTypes"]),
|
cls.enum_class.in_(["DebitTypes"]), cls.key == search_debit, system=True
|
||||||
cls.key == search_debit,
|
).data:
|
||||||
cls.active == True,
|
|
||||||
).first():
|
|
||||||
return search
|
return search
|
||||||
return cls.query.filter(
|
return cls.filter_all(
|
||||||
cls.enum_class.in_(["DebitTypes"]),
|
cls.enum_class.in_(["DebitTypes"]), system=True
|
||||||
cls.active == True,
|
).data
|
||||||
).all()
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_due_types(cls):
|
def get_due_types(cls):
|
||||||
if due_list := cls.filter_all(
|
if due_list := cls.filter_all(
|
||||||
cls.enum_class == "BuildDuesTypes",
|
cls.enum_class == "BuildDuesTypes",
|
||||||
cls.key.in_(["BDT-A", "BDT-D"]),
|
cls.key.in_(["BDT-A", "BDT-D"]),
|
||||||
cls.active == True,
|
system=True
|
||||||
).data:
|
).data:
|
||||||
return [due.uu_id.__str__() for due in due_list]
|
return [due.uu_id.__str__() for due in due_list]
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
@ -70,23 +65,21 @@ class ApiEnumDropdown(BaseCollection):
|
||||||
@classmethod
|
@classmethod
|
||||||
def due_type_search(cls, search_management: str = None, search_uu_id: str = None):
|
def due_type_search(cls, search_management: str = None, search_uu_id: str = None):
|
||||||
if search_uu_id:
|
if search_uu_id:
|
||||||
if search := cls.query.filter(
|
if search := cls.filter_one(
|
||||||
cls.enum_class.in_(["BuildDuesTypes"]),
|
cls.enum_class.in_(["BuildDuesTypes"]), cls.uu_id == search_uu_id,
|
||||||
cls.uu_id == search_uu_id,
|
system=True
|
||||||
cls.active == True,
|
).data:
|
||||||
).first():
|
|
||||||
return search
|
return search
|
||||||
elif search_management:
|
elif search_management:
|
||||||
if search := cls.query.filter(
|
if search := cls.filter_one(
|
||||||
cls.enum_class.in_(["BuildDuesTypes"]),
|
cls.enum_class.in_(["BuildDuesTypes"]), cls.key == search_management,
|
||||||
cls.key == search_management,
|
system=True
|
||||||
cls.active == True,
|
).data:
|
||||||
).first():
|
|
||||||
return search
|
return search
|
||||||
return cls.query.filter(
|
return cls.filter_all(
|
||||||
cls.enum_class.in_(["BuildDuesTypes"]),
|
cls.enum_class.in_(["BuildDuesTypes"]),
|
||||||
cls.active == True,
|
system=True
|
||||||
).all()
|
).data
|
||||||
|
|
||||||
def get_enum_dict(self):
|
def get_enum_dict(self):
|
||||||
return {
|
return {
|
||||||
|
|
@ -101,7 +94,7 @@ class ApiEnumDropdown(BaseCollection):
|
||||||
def uuid_of_enum(cls, enum_class: str, key: str):
|
def uuid_of_enum(cls, enum_class: str, key: str):
|
||||||
return str(
|
return str(
|
||||||
getattr(
|
getattr(
|
||||||
cls.filter_one(cls.enum_class == enum_class, cls.key == key).data,
|
cls.filter_one(cls.enum_class == enum_class, cls.key == key, system=True).data,
|
||||||
"uu_id",
|
"uu_id",
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from fastapi.requests import Request
|
||||||
|
|
||||||
from api_validations.validations_request import (
|
from api_validations.validations_request import (
|
||||||
InsertAddress,
|
InsertAddress,
|
||||||
|
UpdateAddress,
|
||||||
SearchAddress,
|
SearchAddress,
|
||||||
ListOptions,
|
ListOptions,
|
||||||
PatchRecord,
|
PatchRecord,
|
||||||
|
|
@ -36,7 +37,7 @@ def address_search(request: Request, data: SearchAddress):
|
||||||
@address_router.post(
|
@address_router.post(
|
||||||
path="/update/{address_uu_id}", summary="Update Address with given auth levels"
|
path="/update/{address_uu_id}", summary="Update Address with given auth levels"
|
||||||
)
|
)
|
||||||
def address_update(request: Request, address_uu_id: str, data: InsertAddress):
|
def address_update(request: Request, address_uu_id: str, data: UpdateAddress):
|
||||||
token_dict = parse_token_object_to_dict(request=request)
|
token_dict = parse_token_object_to_dict(request=request)
|
||||||
return token_dict.available_event(
|
return token_dict.available_event(
|
||||||
data=data, address_uu_id=address_uu_id, token_dict=token_dict
|
data=data, address_uu_id=address_uu_id, token_dict=token_dict
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from fastapi.requests import Request
|
||||||
|
|
||||||
from api_validations.validations_request import (
|
from api_validations.validations_request import (
|
||||||
InsertPostCode,
|
InsertPostCode,
|
||||||
|
UpdatePostCode,
|
||||||
ListOptions,
|
ListOptions,
|
||||||
PatchRecord,
|
PatchRecord,
|
||||||
)
|
)
|
||||||
|
|
@ -29,7 +30,7 @@ def post_code_create(request: Request, data: InsertPostCode):
|
||||||
@post_code_router.post(
|
@post_code_router.post(
|
||||||
path="/update/{post_code_uu_id}", summary="Update PostCode with given auth levels"
|
path="/update/{post_code_uu_id}", summary="Update PostCode with given auth levels"
|
||||||
)
|
)
|
||||||
def post_code_update(request: Request, post_code_uu_id: str, data: InsertPostCode):
|
def post_code_update(request: Request, post_code_uu_id: str, data: UpdatePostCode):
|
||||||
token_dict = parse_token_object_to_dict(request=request)
|
token_dict = parse_token_object_to_dict(request=request)
|
||||||
return token_dict.available_event(
|
return token_dict.available_event(
|
||||||
data=data, post_code_uu_id=post_code_uu_id, token_dict=token_dict
|
data=data, post_code_uu_id=post_code_uu_id, token_dict=token_dict
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,7 @@ def building_types_list(request: Request, list_options: ListOptions):
|
||||||
return token_dict.available_event(list_options=list_options, token_dict=token_dict)
|
return token_dict.available_event(list_options=list_options, token_dict=token_dict)
|
||||||
|
|
||||||
|
|
||||||
@build_types_route.post(
|
@build_types_route.post(path="/create", summary="Create BuildParts with given auth levels")
|
||||||
path="/create", summary="Create BuildParts with given auth levels"
|
|
||||||
)
|
|
||||||
def building_types_create(request: Request, data: InsertBuildTypes):
|
def building_types_create(request: Request, data: InsertBuildTypes):
|
||||||
token_dict = parse_token_object_to_dict(request=request)
|
token_dict = parse_token_object_to_dict(request=request)
|
||||||
return token_dict.available_event(data=data, token_dict=token_dict)
|
return token_dict.available_event(data=data, token_dict=token_dict)
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,9 @@ def create_all_events_from_actions():
|
||||||
endpoint_uu_id=str(endpoint_restriction.uu_id),
|
endpoint_uu_id=str(endpoint_restriction.uu_id),
|
||||||
**active_confirmed,
|
**active_confirmed,
|
||||||
)
|
)
|
||||||
Events.save()
|
created_event.save()
|
||||||
|
created_event.update(is_confirmed=True)
|
||||||
|
created_event.save()
|
||||||
print(f"Event created: {created_event.uu_id}")
|
print(f"Event created: {created_event.uu_id}")
|
||||||
|
|
||||||
for item in an_empty_list:
|
for item in an_empty_list:
|
||||||
|
|
|
||||||
|
|
@ -69,9 +69,11 @@ def init_api_enums_build_types():
|
||||||
lang=insert_type["lang"],
|
lang=insert_type["lang"],
|
||||||
type_code=str(insert_type["type_code"]).upper(),
|
type_code=str(insert_type["type_code"]).upper(),
|
||||||
type_name=insert_type["type_name"],
|
type_name=insert_type["type_name"],
|
||||||
is_confirmed=True,
|
|
||||||
)
|
)
|
||||||
BuildTypes.find_or_create(**build_types.model_dump())
|
created_build_type = BuildTypes.find_or_create(**build_types.model_dump())
|
||||||
|
created_build_type.save()
|
||||||
|
created_build_type.update(is_confirmed=True)
|
||||||
|
created_build_type.save()
|
||||||
|
|
||||||
insert_enums = [
|
insert_enums = [
|
||||||
{"enum_class": "BuildDuesTypes", "type_code": "BDT-D", "type_name": "Debit"},
|
{"enum_class": "BuildDuesTypes", "type_code": "BDT-D", "type_name": "Debit"},
|
||||||
|
|
@ -230,13 +232,15 @@ def init_api_enums_build_types():
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
for insert_enum in insert_enums:
|
for insert_enum in insert_enums:
|
||||||
ApiEnumDropdown.find_or_create(
|
created_api_enum = ApiEnumDropdown.find_or_create(
|
||||||
enum_class=insert_enum["enum_class"],
|
enum_class=insert_enum["enum_class"],
|
||||||
value=insert_enum["type_name"],
|
value=insert_enum["type_name"],
|
||||||
key=str(insert_enum["type_code"]).upper(),
|
key=str(insert_enum["type_code"]).upper(),
|
||||||
description=insert_enum["type_name"],
|
description=insert_enum["type_name"],
|
||||||
)
|
)
|
||||||
BuildTypes.save()
|
created_api_enum.save()
|
||||||
|
created_api_enum.update(is_confirmed=True)
|
||||||
|
created_api_enum.save()
|
||||||
|
|
||||||
# for insert_meeting_type in insert_meeting_types:
|
# for insert_meeting_type in insert_meeting_types:
|
||||||
# ApiEnumDropdown.find_or_create(
|
# ApiEnumDropdown.find_or_create(
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ requester_dict_build_area = lambda data: {
|
||||||
"data": data,
|
"data": data,
|
||||||
}
|
}
|
||||||
requester_dict_build_part = lambda data: {
|
requester_dict_build_part = lambda data: {
|
||||||
"endpoint": "/building/part/create",
|
"endpoint": "/building/parts/create",
|
||||||
"data": data,
|
"data": data,
|
||||||
}
|
}
|
||||||
requester_dict_build_iban = lambda data: {
|
requester_dict_build_iban = lambda data: {
|
||||||
|
|
@ -52,10 +52,12 @@ def get_build_area_from_json():
|
||||||
return with_pydantic
|
return with_pydantic
|
||||||
|
|
||||||
|
|
||||||
def get_build_part_from_json():
|
def get_build_part_from_json(build_part_type_uu_id: str, part_direction_uu_id: str):
|
||||||
read_files_json, with_pydantic = read_json_file(json_file="build_parts"), []
|
read_files_json, with_pydantic = read_json_file(json_file="build_parts"), []
|
||||||
read_files = read_files_json.get("build_parts")
|
read_files = read_files_json.get("build_parts")
|
||||||
for row in read_files:
|
for row in read_files:
|
||||||
|
row["build_part_type_uu_id"] = build_part_type_uu_id
|
||||||
|
row["part_direction_uu_id"] = part_direction_uu_id
|
||||||
pydantic_row = InsertBuildParts(**row)
|
pydantic_row = InsertBuildParts(**row)
|
||||||
with_pydantic.append(pydantic_row.model_dump())
|
with_pydantic.append(pydantic_row.model_dump())
|
||||||
if not with_pydantic:
|
if not with_pydantic:
|
||||||
|
|
@ -100,7 +102,14 @@ def create_address(requester: BothAPIS, post_code):
|
||||||
)
|
)
|
||||||
print("post_code_response", post_code_response.text)
|
print("post_code_response", post_code_response.text)
|
||||||
response_post_code = post_code_response.json()
|
response_post_code = post_code_response.json()
|
||||||
return response_post_code
|
response_post_code_uu_id = response_post_code["data"]["uu_id"]
|
||||||
|
requester.local_api.post(
|
||||||
|
endpoint=f"/postcode/update/{response_post_code_uu_id}",
|
||||||
|
data={
|
||||||
|
"is_confirmed": True,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return response_post_code_uu_id
|
||||||
|
|
||||||
|
|
||||||
def search_street(search_text, requester):
|
def search_street(search_text, requester):
|
||||||
|
|
@ -134,50 +143,24 @@ def create_addresses(address, requester):
|
||||||
data=address,
|
data=address,
|
||||||
)
|
)
|
||||||
print("text", address_response.text)
|
print("text", address_response.text)
|
||||||
print("json", address_response.json())
|
|
||||||
response_address = address_response.json()
|
response_address = address_response.json()
|
||||||
|
print("json", response_address)
|
||||||
return response_address
|
return response_address
|
||||||
|
|
||||||
|
|
||||||
def migrate_build(requester: BothAPIS):
|
# def grab_new_build_uu_id(requester: BothAPIS, build_uu_id: str):
|
||||||
street_uu_id = search_street("Reşat Nuri", requester=requester)
|
# response_wag = requester.wag_api.post(
|
||||||
response_post_code = create_address(requester=requester, post_code=post_code_dict(uu_id_street=street_uu_id))
|
# endpoint="/building/build/list",
|
||||||
print("response_post_code", response_post_code)
|
# data={"page": 1, "size": 1, "query": {"uu_id": build_uu_id}},
|
||||||
created_address = create_addresses(
|
# )
|
||||||
address=address_dict(post_code_uu_id=response_post_code["data"]["uu_id"]),
|
# build_uu_id = response_wag.json()["data"]["uu_id"]
|
||||||
requester=requester
|
# if not build_uu_id:
|
||||||
)
|
# raise Exception("Build UU ID not found")
|
||||||
print('created_address', created_address)
|
# return build_uu_id
|
||||||
created_address_uu_id = created_address["data"]["uu_id"]
|
|
||||||
for response_data in get_build_from_json():
|
|
||||||
print("response_data", response_data)
|
|
||||||
response_data["address_uu_id"] = created_address_uu_id
|
|
||||||
exit()
|
|
||||||
response = requester.local_api.post(**requester_dict_build(data=response_data))
|
|
||||||
print("response", response.text)
|
|
||||||
if response.ok:
|
|
||||||
build_uu_id = response.json()["data"]["uu_id"]
|
|
||||||
print("response build_uu_id", build_uu_id)
|
|
||||||
exit()
|
|
||||||
migrate_build_area(requester=requester, build_uu_id=build_uu_id)
|
|
||||||
migrate_build_part(requester=requester, build_uu_id=build_uu_id)
|
|
||||||
migrate_build_iban(requester=requester, build_uu_id=build_uu_id)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def grab_new_build_uu_id(requester: BothAPIS, build_uu_id: str):
|
|
||||||
response_wag = requester.wag_api.post(
|
|
||||||
endpoint="/building/build/list",
|
|
||||||
data={"page": 1, "size": 1, "query": {"uu_id": build_uu_id}},
|
|
||||||
)
|
|
||||||
build_uu_id = response_wag.json()["data"]["uu_id"]
|
|
||||||
if not build_uu_id:
|
|
||||||
raise Exception("Build UU ID not found")
|
|
||||||
return build_uu_id
|
|
||||||
|
|
||||||
|
|
||||||
def migrate_build_area(requester: BothAPIS, build_uu_id: str):
|
def migrate_build_area(requester: BothAPIS, build_uu_id: str):
|
||||||
build_uu_id = grab_new_build_uu_id(requester=requester, build_uu_id=build_uu_id)
|
# build_uu_id = grab_new_build_uu_id(requester=requester, build_uu_id=build_uu_id)
|
||||||
response_datas = get_build_area_from_json()
|
response_datas = get_build_area_from_json()
|
||||||
for response_data in response_datas:
|
for response_data in response_datas:
|
||||||
response_data["build_uu_id"] = build_uu_id
|
response_data["build_uu_id"] = build_uu_id
|
||||||
|
|
@ -189,10 +172,17 @@ def migrate_build_area(requester: BothAPIS, build_uu_id: str):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def migrate_build_part(requester: BothAPIS, build_uu_id: str):
|
def migrate_build_part(
|
||||||
build_uu_id = grab_new_build_uu_id(requester=requester, build_uu_id=build_uu_id)
|
requester: BothAPIS, build_uu_id: str, build_part_type_uu_id: str, part_direction_uu_id: str
|
||||||
response_datas = get_build_part_from_json()
|
):
|
||||||
|
# build_uu_id = grab_new_build_uu_id(requester=requester, build_uu_id=build_uu_id)
|
||||||
|
response_datas = get_build_part_from_json(
|
||||||
|
build_part_type_uu_id=build_part_type_uu_id, part_direction_uu_id=part_direction_uu_id
|
||||||
|
)
|
||||||
|
|
||||||
for response_data in response_datas:
|
for response_data in response_datas:
|
||||||
|
if response_data.get('part_no') == 0:
|
||||||
|
continue
|
||||||
response_data["build_uu_id"] = build_uu_id
|
response_data["build_uu_id"] = build_uu_id
|
||||||
response = requester.local_api.post(
|
response = requester.local_api.post(
|
||||||
**requester_dict_build_part(data=response_data)
|
**requester_dict_build_part(data=response_data)
|
||||||
|
|
@ -202,7 +192,7 @@ def migrate_build_part(requester: BothAPIS, build_uu_id: str):
|
||||||
|
|
||||||
|
|
||||||
def migrate_build_iban(requester: BothAPIS, build_uu_id: str):
|
def migrate_build_iban(requester: BothAPIS, build_uu_id: str):
|
||||||
build_uu_id = grab_new_build_uu_id(requester=requester, build_uu_id=build_uu_id)
|
# build_uu_id = grab_new_build_uu_id(requester=requester, build_uu_id=build_uu_id)
|
||||||
response_datas = get_build_iban_from_json()
|
response_datas = get_build_iban_from_json()
|
||||||
for response_data in response_datas:
|
for response_data in response_datas:
|
||||||
response_data["build_uu_id"] = build_uu_id
|
response_data["build_uu_id"] = build_uu_id
|
||||||
|
|
@ -214,7 +204,7 @@ def migrate_build_iban(requester: BothAPIS, build_uu_id: str):
|
||||||
|
|
||||||
|
|
||||||
def migrate_build_living_space(requester: BothAPIS, build_uu_id: str):
|
def migrate_build_living_space(requester: BothAPIS, build_uu_id: str):
|
||||||
build_uu_id = grab_new_build_uu_id(requester=requester, build_uu_id=build_uu_id)
|
# build_uu_id = grab_new_build_uu_id(requester=requester, build_uu_id=build_uu_id)
|
||||||
response_datas = get_build_iban_from_json()
|
response_datas = get_build_iban_from_json()
|
||||||
for response_data in response_datas:
|
for response_data in response_datas:
|
||||||
response_data["build_uu_id"] = build_uu_id
|
response_data["build_uu_id"] = build_uu_id
|
||||||
|
|
@ -223,3 +213,43 @@ def migrate_build_living_space(requester: BothAPIS, build_uu_id: str):
|
||||||
)
|
)
|
||||||
print("response", response.text)
|
print("response", response.text)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_build(requester: BothAPIS):
|
||||||
|
from service_app_test.test_application.migrate_old_data.get_building_types import (
|
||||||
|
list_building_types,
|
||||||
|
)
|
||||||
|
from service_app_test.test_application.migrate_old_data.get_type_codes import (
|
||||||
|
get_type_codes_key_and_class
|
||||||
|
)
|
||||||
|
|
||||||
|
building_type_flat = list_building_types(requester=requester.local_api, type_code="daire").get("uu_id")
|
||||||
|
building_type_build = list_building_types(requester=requester.local_api, type_code="apt").get("uu_id")
|
||||||
|
api_enum_dropdown_nn = get_type_codes_key_and_class(
|
||||||
|
class_name="Directions", key_name="NN", requester=requester.local_api
|
||||||
|
)
|
||||||
|
api_enum_dropdown_nn_uuid = api_enum_dropdown_nn.get("data").get("uu_id")
|
||||||
|
street_uu_id = search_street("Reşat Nuri", requester=requester)
|
||||||
|
post_code_uuid = create_address(requester=requester, post_code=post_code_dict(uu_id_street=street_uu_id))
|
||||||
|
|
||||||
|
created_address = create_addresses(
|
||||||
|
address=address_dict(post_code_uu_id=post_code_uuid),
|
||||||
|
requester=requester
|
||||||
|
)
|
||||||
|
created_address_uu_id = created_address["data"]["uu_id"]
|
||||||
|
for response_data in get_build_from_json():
|
||||||
|
response_data["address_uu_id"] = created_address_uu_id
|
||||||
|
response_data["build_types_uu_id"] = building_type_build
|
||||||
|
response = requester.local_api.post(**requester_dict_build(data=response_data))
|
||||||
|
response_json = response.json()
|
||||||
|
build_uu_id = str(response_json.get("data").get("uu_id"))
|
||||||
|
migrate_build_area(requester=requester, build_uu_id=build_uu_id)
|
||||||
|
migrate_build_part(
|
||||||
|
requester=requester,
|
||||||
|
build_uu_id=build_uu_id,
|
||||||
|
build_part_type_uu_id=building_type_flat,
|
||||||
|
part_direction_uu_id=api_enum_dropdown_nn_uuid
|
||||||
|
)
|
||||||
|
migrate_build_iban(requester=requester, build_uu_id=build_uu_id)
|
||||||
|
return
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
|
||||||
|
|
||||||
|
def list_building_types(requester, lang: str = "TR", type_code: str = None):
|
||||||
|
from service_app_test.test_application.evyos.datas.company_employee_data import (
|
||||||
|
list_options,
|
||||||
|
)
|
||||||
|
|
||||||
|
options_smart_query = {
|
||||||
|
**list_options,
|
||||||
|
"query": {
|
||||||
|
"lang": lang,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if type_code:
|
||||||
|
options_smart_query["query"]["type_code__ilike"] = type_code
|
||||||
|
response = requester.post(
|
||||||
|
endpoint="/building/types/list",
|
||||||
|
data=options_smart_query,
|
||||||
|
)
|
||||||
|
if type_code:
|
||||||
|
for item in response.json().get("data"):
|
||||||
|
if str(item.get("type_code")).upper() == str(type_code).upper():
|
||||||
|
return item
|
||||||
|
print("text", response.text)
|
||||||
|
print("json", response.json())
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
|
||||||
|
# list_building_types(type_code="apt")
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
def get_occupants_types(occupant_code, requester):
|
||||||
|
response = requester.post(
|
||||||
|
endpoint="/occupant_types/get/code",
|
||||||
|
data={"type_code": occupant_code},
|
||||||
|
)
|
||||||
|
print("text", response.text)
|
||||||
|
print("json", response.json())
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
|
||||||
|
def get_occupants_types_uu_id(occupant_uu_id, requester):
|
||||||
|
response = requester.post(
|
||||||
|
endpoint="/occupant_types/get/uu_id",
|
||||||
|
data={"uu_id": occupant_uu_id},
|
||||||
|
)
|
||||||
|
print("text", response.text)
|
||||||
|
print("json", response.json())
|
||||||
|
return response.json()
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
def get_type_codes_key_and_class(class_name, key_name, requester):
|
||||||
|
response = requester.post(
|
||||||
|
endpoint="/enums/get/key",
|
||||||
|
data={"class_name": class_name, "key_name": key_name},
|
||||||
|
)
|
||||||
|
print("text", response.text)
|
||||||
|
print("json", response.json())
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
|
||||||
|
def get_type_codes_via_uuid(uu_id, requester):
|
||||||
|
response = requester.post(
|
||||||
|
endpoint="/enums/get/uu_id",
|
||||||
|
data={"uu_id": uu_id},
|
||||||
|
)
|
||||||
|
print("text", response.text)
|
||||||
|
print("json", response.json())
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
|
||||||
|
def get_all_type_codes(requester):
|
||||||
|
response = requester.post(
|
||||||
|
endpoint="/enums/list/all",
|
||||||
|
data={},
|
||||||
|
)
|
||||||
|
print("text", response.text)
|
||||||
|
print("json", response.json())
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
|
||||||
|
def get_all_type_codes_with_class(class_name, requester):
|
||||||
|
response = requester.post(
|
||||||
|
endpoint="/enums/list/class",
|
||||||
|
data={"class_name": class_name},
|
||||||
|
)
|
||||||
|
print("text", response.text)
|
||||||
|
print("json", response.json())
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
|
||||||
|
# get_type_codes(class_name="buildmanagementtype", key_name="BM")
|
||||||
|
# get_all_type_codes()
|
||||||
|
|
@ -7,13 +7,13 @@ from service_app_test.test_application.migrate_old_data.building import (
|
||||||
)
|
)
|
||||||
from service_app_test.test_application.migrate_old_data.company import migrate_company
|
from service_app_test.test_application.migrate_old_data.company import migrate_company
|
||||||
|
|
||||||
|
password_token = "b-4liqvEJIX9wtmMScnJhDOkPTIvyra1I_1HQCgTKG3Mp6Oaj-Vh8dVqqpZFC-fGlQ-5bnuDpzrju4Jg6qoi48EB5brdNT4YQCLdQqMlO8uUrL8iuJmRPk4L9AOQl82NFXD0U4pbZ9fhZkp4vHl487S9HcO1Dz5qUYR1VOs5mt2p0d96c5qrWB4QcDkkbz2F"
|
||||||
login_data = {
|
login_data = {
|
||||||
"domain": "evyos.com.tr",
|
"domain": "evyos.com.tr",
|
||||||
"access_key": "karatay.berkay.sup@evyos.com.tr",
|
"access_key": "karatay.berkay.sup@evyos.com.tr",
|
||||||
"password": "string",
|
"password": "string",
|
||||||
"remember_me": False,
|
"remember_me": False,
|
||||||
"password_token": "Jx4t2JM3Xc_yNGCBe-hk_4c299ov51_s20kQueVUjm-NJU0KGWENm3alGfyGO6-y79esC5WtuhXHAsw35XJYFn-UOdUAvuW6kbHk-F2MTNbavXMp2f_UdkPrav0PppZEQ2TRcIJQ6DzFWO0ONOxJMhcGTUbqxO4DfidKiq_VjYUqfwcl6ZxSsJolctLzyfwf",
|
"password_token": password_token
|
||||||
}
|
}
|
||||||
login_data_wag = {
|
login_data_wag = {
|
||||||
"domain": "evyos.com.tr",
|
"domain": "evyos.com.tr",
|
||||||
|
|
@ -39,6 +39,6 @@ both_apis = BothAPIS()
|
||||||
both_apis.wag_api = wag_api
|
both_apis.wag_api = wag_api
|
||||||
both_apis.local_api = local_api
|
both_apis.local_api = local_api
|
||||||
|
|
||||||
# migrate_company(requester=both_apis)
|
migrate_company(requester=both_apis)
|
||||||
# migrate_people(requester=both_apis)
|
migrate_people(requester=both_apis)
|
||||||
migrate_build(requester=both_apis)
|
migrate_build(requester=both_apis)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue