app apis and service stroe updated

This commit is contained in:
2025-01-08 17:00:14 +03:00
parent b29a229dd3
commit 364a4df4b1
63 changed files with 9282 additions and 2 deletions

17
api_objects/__init__.py Normal file
View File

@@ -0,0 +1,17 @@
from api_objects.auth.token_objects import (
OccupantTokenObject,
EmployeeTokenObject,
UserType,
CompanyToken,
OccupantToken,
ApplicationToken,
)
__all__ = [
"OccupantTokenObject",
"EmployeeTokenObject",
"UserType",
"CompanyToken",
"OccupantToken",
"ApplicationToken",
]

View File

@@ -0,0 +1,106 @@
import enum
from typing import Optional, List, Any
from pydantic import BaseModel
# Company / Priority / Department / Duty / Employee / Occupant / Module / Endpoint are changeable dynamics
class UserType(enum.Enum):
employee = 1
occupant = 2
class Credentials(BaseModel):
person_id: int
person_name: str
class ApplicationToken(BaseModel):
# Application Token Object -> is the main object for the user
domain: Optional[str] = "app.evyos.com.tr"
lang: Optional[str] = "TR"
timezone: Optional[str] = "Europe/Istanbul"
user_type: int = UserType.occupant.value
credentials: dict = None
user_uu_id: str
user_id: int
person_id: int
person_uu_id: str
request: Optional[dict] = None # Request Info of Client
class OccupantToken(BaseModel):
# Selection of the occupant type for a build part is made by the user
living_space_id: int # Internal use
living_space_uu_id: str # Outer use
occupant_type_id: int
occupant_type_uu_id: str
occupant_type: str
build_id: int
build_uuid: str
build_part_id: int
build_part_uuid: str
responsible_company_id: Optional[int] = None
responsible_company_uuid: Optional[str] = None
responsible_employee_id: Optional[int] = None
responsible_employee_uuid: Optional[str] = None
reachable_event_list_id: Optional[list] = None # ID list of reachable modules
# reachable_event_list_uu_id: Optional[list] = None # UUID list of reachable modules
class CompanyToken(BaseModel): # Required Company Object for an employee
company_id: int
company_uu_id: str
department_id: int # ID list of departments
department_uu_id: str # ID list of departments
duty_id: int
duty_uu_id: str
staff_id: int
staff_uu_id: str
employee_id: int
employee_uu_id: str
bulk_duties_id: int
reachable_event_list_id: Optional[list] = None # ID list of reachable modules
# reachable_event_list_uu_id: Optional[list] = None # UUID list of reachable modules
class OccupantTokenObject(ApplicationToken):
# Occupant Token Object -> Requires selection of the occupant type for a specific build part
available_occupants: dict = None
selected_occupant: Optional[OccupantToken] = None # Selected Occupant Type
available_event: Optional[Any] = None
class EmployeeTokenObject(ApplicationToken):
# Full hierarchy Employee[staff_id] -> Staff -> Duty -> Department -> Company
companies_id_list: List[int] # List of company objects
companies_uu_id_list: List[str] # List of company objects
duty_id_list: List[int] # List of duty objects
duty_uu_id_list: List[str] # List of duty objects
selected_company: Optional[CompanyToken] = None # Selected Company Object
available_event: Optional[Any] = None

View File

@@ -0,0 +1,85 @@
from .errors_dictionary import ErrorMessages
class AlchemyError:
ERRORS_DICT = {
"100": "HTTP_100_CONTINUE",
"101": "HTTP_101_SWITCHING_PROTOCOLS",
"102": "HTTP_102_PROCESSING",
"103": "HTTP_103_EARLY_HINTS",
"200": "HTTP_200_OK",
"201": "HTTP_201_CREATED",
"202": "HTTP_202_ACCEPTED",
"203": "HTTP_203_NON_AUTHORITATIVE_INFORMATION",
"204": "HTTP_204_NO_CONTENT",
"205": "HTTP_205_RESET_CONTENT",
"206": "HTTP_206_PARTIAL_CONTENT",
"207": "HTTP_207_MULTI_STATUS",
"208": "HTTP_208_ALREADY_REPORTED",
"226": "HTTP_226_IM_USED",
"300": "HTTP_300_MULTIPLE_CHOICES",
"301": "HTTP_301_MOVED_PERMANENTLY",
"302": "HTTP_302_FOUND",
"303": "HTTP_303_SEE_OTHER",
"304": "HTTP_304_NOT_MODIFIED",
"305": "HTTP_305_USE_PROXY",
"306": "HTTP_306_RESERVED",
"307": "HTTP_307_TEMPORARY_REDIRECT",
"308": "HTTP_308_PERMANENT_REDIRECT",
"400": "HTTP_400_BAD_REQUEST",
"401": "HTTP_401_UNAUTHORIZED",
"402": "HTTP_402_PAYMENT_REQUIRED",
"403": "HTTP_403_FORBIDDEN",
"404": "HTTP_404_NOT_FOUND",
"405": "HTTP_405_METHOD_NOT_ALLOWED",
"406": "HTTP_406_NOT_ACCEPTABLE",
"407": "HTTP_407_PROXY_AUTHENTICATION_REQUIRED",
"408": "HTTP_408_REQUEST_TIMEOUT",
"409": "HTTP_409_CONFLICT",
"410": "HTTP_410_GONE",
"411": "HTTP_411_LENGTH_REQUIRED",
"412": "HTTP_412_PRECONDITION_FAILED",
"413": "HTTP_413_REQUEST_ENTITY_TOO_LARGE",
"414": "HTTP_414_REQUEST_URI_TOO_LONG",
"415": "HTTP_415_UNSUPPORTED_MEDIA_TYPE",
"416": "HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE",
"417": "HTTP_417_EXPECTATION_FAILED",
"418": "HTTP_418_IM_A_TEAPOT",
"421": "HTTP_421_MISDIRECTED_REQUEST",
"422": "HTTP_422_UNPROCESSABLE_ENTITY",
"423": "HTTP_423_LOCKED",
"424": "HTTP_424_FAILED_DEPENDENCY",
"426": "HTTP_426_UPGRADE_REQUIRED",
"428": "HTTP_428_PRECONDITION_REQUIRED",
"429": "HTTP_429_TOO_MANY_REQUESTS",
"431": "HTTP_431_REQUEST_HEADER_FIELDS_TOO_LARGE",
"451": "HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS",
"500": "HTTP_500_INTERNAL_SERVER_ERROR",
}
ERRORS_KEYS = {
"delete": "DeletedRecord",
"update": "UpdatedRecord",
"create": "CreatedRecord",
"list": "ListedRecords",
"not_found": "RecordNotFound",
"already_exist": "AlreadyExists",
"not_deleted": "RecordNotDeleted",
"not_updated": "RecordNotUpdated",
"not_created": "RecordNotCreated",
"not_listed": "RecordsNotListed",
"not_confirm": "IsNotConfirmed",
}
def __init__(self, lang):
self.lang = lang
def retrieve_error_needs(self, data, status_code, error_case, message_key):
return dict(
status_code=self.ERRORS_DICT[status_code],
error_case=self.ERRORS_KEYS[error_case],
data=data,
message=ErrorMessages.get_message(message_key, self.lang),
)
alchemy_error = AlchemyError(lang="")

View File

@@ -0,0 +1,44 @@
from json import loads
class ErrorMessages:
__messages__ = {}
@classmethod
def get_message(cls, message_key, lang):
return cls.__messages__[lang][message_key]
class ErrorHandlers:
def __init__(self, requests, exceptions, response_model, status):
self.requests = requests # from fastapi.requests import Request
self.exceptions = exceptions # from fastapi.exceptions import HTTPException
self.response_model = response_model # from fastapi.responses import JSONResponse
self.status = status # from fastapi import status
def exception_handler_http(self, request, exc):
exc_detail = getattr(exc, "detail", None)
try:
detail = loads(str(exc_detail))
return self.response_model(
status_code=exc.status_code,
content={
"Data": detail.get("data", {}),
"Error": detail.get("error_case", "UNKNOWN"),
"Message": detail.get(
"message", "An error occurred while processing the request"
),
},
)
except Exception as e:
return self.response_model(
status_code=exc.status_code,
content={"Error": str(exc_detail), "Message": f"{str(e)}", "Data": {}},
)
def exception_handler_exception(self, request, exc):
return self.response_model(
status_code=self.status.HTTP_417_EXPECTATION_FAILED,
content={"message": exc.__str__()},
)