updated app reachable codes

This commit is contained in:
2025-04-09 11:51:28 +03:00
parent 7eadadbd1d
commit 7c2150a8b0
23 changed files with 1040 additions and 187 deletions

View File

@@ -11,6 +11,25 @@ from sqlalchemy.orm import mapped_column, Mapped
from Controllers.Postgres.mixin import CrudCollection
class Applications(CrudCollection):
"""
Applications class based on declarative_base and BaseMixin via session
"""
__tablename__ = "applications"
__exclude__fields__ = []
name: Mapped[str] = mapped_column(
String, nullable=False, comment="Application Name"
)
site_url: Mapped[str] = mapped_column(String, nullable=False, comment="Site URL")
application_code: Mapped[str] = mapped_column(
String, nullable=False, comment="Application Code"
)
application_type: Mapped[str] = mapped_column(String, comment="Application Type")
description: Mapped[str] = mapped_column(String, comment="Application Description")
class Events(CrudCollection):
"""
Events class based on declarative_base and BaseMixin via session
@@ -82,6 +101,42 @@ class Modules(CrudCollection):
__table_args__ = ({"comment": "Modules Information"},)
class ModulePrice(CrudCollection):
"""
ModulePrice class based on declarative_base and BaseMixin via session
"""
__tablename__ = "module_price"
__exclude__fields__ = []
campaign_code: Mapped[str] = mapped_column(
String, nullable=False, comment="Campaign Code"
)
module_id: Mapped[int] = mapped_column(ForeignKey("modules.id"), nullable=False)
module_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Module UUID"
)
service_id: Mapped[int] = mapped_column(ForeignKey("services.id"), nullable=False)
service_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Service UUID"
)
event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), nullable=False)
event_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Event UUID"
)
is_counted_percentage: Mapped[float] = mapped_column(
Numeric(6, 2), server_default="0.00"
) # %22
discounted_price: Mapped[float] = mapped_column(
Numeric(20, 2), server_default="0.00"
) # Normal: 78.00 TL
calculated_price: Mapped[float] = mapped_column(
Numeric(20, 2), server_default="0.00"
) # sana düz 75.00 TL yapar
__table_args__ = ({"comment": "ModulePrice Information"},)
class Services(CrudCollection):
"""
Services class based on declarative_base and BaseMixin via session
@@ -143,6 +198,10 @@ class Service2Events(CrudCollection):
__table_args__ = ({"comment": "Service2Events Information"},)
# class Service2Application(CrudCollection):
# pass
class Event2OccupantExtra(CrudCollection):
__tablename__ = "event2occupant_extra"
@@ -229,7 +288,7 @@ class Event2Employee(CrudCollection):
)
@classmethod
def get_event_codes(cls, employee_id: int, db) -> list:
def get_event_codes(cls, employee_id: int, db) -> dict[str : list[str]]:
employee_events = cls.filter_all(
cls.employee_id == employee_id,
db=db,
@@ -253,43 +312,13 @@ class Event2Employee(CrudCollection):
db=db,
).data
active_events.extend(events_extra)
return [event.function_code for event in active_events]
# @classmethod
# def get_event_endpoints(cls, employee_id: int) -> list:
# from Schemas import EndpointRestriction
#
# db = cls.new_session()
# employee_events = cls.filter_all(
# cls.employee_id == employee_id,
# db=db,
# ).data
# active_event_ids = Service2Events.filter_all(
# Service2Events.service_id.in_(
# [event.event_service_id for event in employee_events]
# ),
# db=db,
# system=True,
# ).data
# active_events = Events.filter_all(
# Events.id.in_([event.event_id for event in active_event_ids]),
# db=db,
# ).data
# if extra_events := Event2EmployeeExtra.filter_all(
# Event2EmployeeExtra.employee_id == employee_id,
# db=db,
# ).data:
# events_extra = Events.filter_all(
# Events.id.in_([event.event_id for event in extra_events]),
# db=db,
# ).data
# active_events.extend(events_extra)
# endpoint_restrictions = EndpointRestriction.filter_all(
# EndpointRestriction.id.in_([event.endpoint_id for event in active_events]),
# db=db,
# ).data
# return [event.endpoint_name for event in endpoint_restrictions]
#
events_dict = {}
for event in active_events:
if event.endpoint_code in events_dict:
events_dict[event.endpoint_code].append(event.function_code)
else:
events_dict[event.endpoint_code] = [event.function_code]
return events_dict
class Event2Occupant(CrudCollection):
@@ -326,7 +355,7 @@ class Event2Occupant(CrudCollection):
)
@classmethod
def get_event_codes(cls, build_living_space_id, db) -> list:
def get_event_codes(cls, build_living_space_id: int, db) -> dict[str : list[str]]:
occupant_events = cls.filter_all(
cls.build_living_space_id == build_living_space_id,
db=db,
@@ -350,75 +379,106 @@ class Event2Occupant(CrudCollection):
db=db,
).data
active_events.extend(events_extra)
return [event.function_code for event in active_events]
# @classmethod
# def get_event_endpoints(cls, build_living_space_id) -> list:
# from Schemas import EndpointRestriction
#
# db = cls.new_session()
# occupant_events = cls.filter_all(
# cls.build_living_space_id == build_living_space_id,
# db=db,
# ).data
# active_event_ids = Service2Events.filter_all(
# Service2Events.service_id.in_(
# [event.event_service_id for event in occupant_events]
# ),
# db=db,
# system=True,
# ).data
# active_events = Events.filter_all(
# Events.id.in_([event.event_id for event in active_event_ids]),
# db=db,
# ).data
# if extra_events := Event2OccupantExtra.filter_all(
# Event2OccupantExtra.build_living_space_id == build_living_space_id,
# db=db,
# ).data:
# events_extra = Events.filter_all(
# Events.id.in_([event.event_id for event in extra_events]),
# db=db,
# ).data
# active_events.extend(events_extra)
# endpoint_restrictions = EndpointRestriction.filter_all(
# EndpointRestriction.id.in_([event.endpoint_id for event in active_events]),
# db=db,
# ).data
# return [event.endpoint_name for event in endpoint_restrictions]
events_dict = {}
for event in active_events:
if event.endpoint_code in events_dict:
events_dict[event.endpoint_code].append(event.function_code)
else:
events_dict[event.endpoint_code] = [event.function_code]
return events_dict
class ModulePrice(CrudCollection):
class Application2Employee(CrudCollection):
"""
ModulePrice class based on declarative_base and BaseMixin via session
Application2Employee class based on declarative_base and BaseMixin via session
"""
__tablename__ = "module_price"
__tablename__ = "application2employee"
__exclude__fields__ = []
campaign_code: Mapped[str] = mapped_column(
String, nullable=False, comment="Campaign Code"
employee_id: Mapped[int] = mapped_column(ForeignKey("employees.id"), nullable=False)
employee_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Employee UUID"
)
module_id: Mapped[int] = mapped_column(ForeignKey("modules.id"), nullable=False)
module_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Module UUID"
)
service_id: Mapped[int] = mapped_column(ForeignKey("services.id"), nullable=False)
service_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Service UUID"
)
event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), nullable=False)
event_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Event UUID"
)
is_counted_percentage: Mapped[float] = mapped_column(
Numeric(6, 2), server_default="0.00"
) # %22
discounted_price: Mapped[float] = mapped_column(
Numeric(20, 2), server_default="0.00"
) # Normal: 78.00 TL
calculated_price: Mapped[float] = mapped_column(
Numeric(20, 2), server_default="0.00"
) # sana düz 75.00 TL yapar
__table_args__ = ({"comment": "ModulePrice Information"},)
application_id: Mapped[int] = mapped_column(ForeignKey("applications.id"))
application_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Application UUID"
)
site_url: Mapped[str] = mapped_column(String, nullable=False, comment="Site URL")
application_code: Mapped[str] = mapped_column(
String, nullable=False, comment="Application Code"
)
@classmethod
def get_application_codes(cls, employee_id: int, db) -> dict[str , str]:
print('employee_id', employee_id)
employee_applications = cls.filter_all(
Application2Employee.employee_id == employee_id, db=db,
).data
applications_dict = {}
print('employee_applications', employee_applications)
for employee_application in employee_applications:
if employee_application.site_url not in applications_dict:
applications_dict[str(employee_application.site_url)] = str(employee_application.application_code)
return applications_dict
__table_args__ = (
Index(
"application_to_employee",
employee_id,
site_url,
application_id,
unique=True,
),
{"comment": "Application2Employee Information"},
)
class Application2Occupant(CrudCollection):
"""
Application2Occupant class based on declarative_base and BaseMixin via session
"""
__tablename__ = "application2occupant"
__exclude__fields__ = []
build_living_space_id: Mapped[int] = mapped_column(
ForeignKey("build_living_space.id"), nullable=False
)
build_living_space_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Build Living Space UUID"
)
application_id: Mapped[int] = mapped_column(ForeignKey("applications.id"))
application_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Application UUID"
)
site_url: Mapped[str] = mapped_column(String, nullable=False, comment="Site URL")
application_code: Mapped[str] = mapped_column(
String, nullable=False, comment="Application Code"
)
@classmethod
def get_application_codes(cls, build_living_space_id: int, db) -> dict[str , str]:
occupant_applications = cls.filter_all(
cls.build_living_space_id == build_living_space_id, db=db,
).data
applications_dict = {}
for occupant_application in occupant_applications:
if occupant_application.site_url not in applications_dict:
applications_dict[str(occupant_application.site_url)] = str(occupant_application.application_code)
return applications_dict
__table_args__ = (
Index(
"application_to_occupant",
build_living_space_id,
site_url,
application_id,
unique=True,
),
{"comment": "Application2Occupant Information"},
)