2024-07-24 04:30:01 +08:00
|
|
|
from felicity.apps.abstract.repository import BaseRepository
|
2024-07-28 03:52:31 +08:00
|
|
|
from felicity.apps.reflex.entities import (ReflexAction, ReflexBrain,
|
|
|
|
ReflexBrainAddition,
|
|
|
|
ReflexBrainCriteria,
|
2024-09-21 16:20:17 +08:00
|
|
|
ReflexBrainFinal, ReflexRule,
|
|
|
|
ComplexCondition)
|
2024-07-21 15:06:51 +08:00
|
|
|
|
|
|
|
|
2024-07-22 16:20:56 +08:00
|
|
|
class ReflexRuleRepository(BaseRepository[ReflexRule]):
|
2024-07-21 15:06:51 +08:00
|
|
|
def __init__(self) -> None:
|
2024-07-22 16:20:56 +08:00
|
|
|
super().__init__(ReflexRule)
|
2024-07-21 15:06:51 +08:00
|
|
|
|
2024-09-21 16:20:17 +08:00
|
|
|
async def get_active_rules(self):
|
|
|
|
"""Retrieve all active reflex rules"""
|
|
|
|
return await self.get_all(is_active=True, order_by="priority")
|
|
|
|
|
2024-07-21 15:06:51 +08:00
|
|
|
|
2024-07-28 03:52:31 +08:00
|
|
|
class ReflexBrainAdditionRepository(BaseRepository[ReflexBrainAddition]):
|
2024-07-21 15:06:51 +08:00
|
|
|
def __init__(self) -> None:
|
2024-07-22 16:20:56 +08:00
|
|
|
super().__init__(ReflexBrainAddition)
|
2024-07-21 15:06:51 +08:00
|
|
|
|
2024-09-21 16:20:17 +08:00
|
|
|
async def get_by_conditions(self, conditions):
|
|
|
|
"""Retrieve additions based on specific conditions"""
|
|
|
|
return await self.get_all(conditions=conditions)
|
|
|
|
|
2024-07-21 15:06:51 +08:00
|
|
|
|
2024-07-28 03:52:31 +08:00
|
|
|
class ReflexBrainFinalRepository(BaseRepository[ReflexBrainFinal]):
|
2024-07-21 15:06:51 +08:00
|
|
|
def __init__(self) -> None:
|
2024-07-22 16:20:56 +08:00
|
|
|
super().__init__(ReflexBrainFinal)
|
2024-07-21 15:06:51 +08:00
|
|
|
|
2024-09-21 16:20:17 +08:00
|
|
|
async def get_by_conditions(self, conditions):
|
|
|
|
"""Retrieve final results based on specific conditions"""
|
|
|
|
return await self.get_all(conditions=conditions)
|
|
|
|
|
2024-07-21 15:06:51 +08:00
|
|
|
|
2024-07-28 03:52:31 +08:00
|
|
|
class ReflexBrainCriteriaRepository(BaseRepository[ReflexBrainCriteria]):
|
2024-07-21 15:06:51 +08:00
|
|
|
def __init__(self) -> None:
|
2024-07-22 16:20:56 +08:00
|
|
|
super().__init__(ReflexBrainCriteria)
|
2024-07-21 15:06:51 +08:00
|
|
|
|
2024-09-21 16:20:17 +08:00
|
|
|
async def get_by_custom_logic(self, custom_logic):
|
|
|
|
"""Retrieve criteria based on custom logic"""
|
|
|
|
return await self.get_all(custom_logic=custom_logic)
|
|
|
|
|
|
|
|
|
|
|
|
class ComplexConditionRepository(BaseRepository[ComplexCondition]):
|
|
|
|
def __init__(self) -> None:
|
|
|
|
super().__init__(ComplexCondition)
|
|
|
|
|
|
|
|
async def get_by_condition_type(self, condition_type):
|
|
|
|
"""Retrieve complex conditions by condition type"""
|
|
|
|
return await self.get_all(condition_type=condition_type)
|
|
|
|
|
2024-07-21 15:06:51 +08:00
|
|
|
|
2024-07-22 16:20:56 +08:00
|
|
|
class ReflexBrainRepository(BaseRepository[ReflexBrain]):
|
2024-07-21 15:06:51 +08:00
|
|
|
def __init__(self) -> None:
|
2024-07-22 16:20:56 +08:00
|
|
|
super().__init__(ReflexBrain)
|
2024-07-21 15:06:51 +08:00
|
|
|
|
2024-09-21 16:20:17 +08:00
|
|
|
async def get_with_complex_conditions(self):
|
|
|
|
"""Retrieve reflex brains with their associated complex conditions"""
|
|
|
|
return await self.get_all(include_related=["complex_conditions"])
|
|
|
|
|
2024-07-21 15:06:51 +08:00
|
|
|
|
2024-07-22 16:20:56 +08:00
|
|
|
class ReflexActionRepository(BaseRepository[ReflexAction]):
|
2024-07-21 15:06:51 +08:00
|
|
|
def __init__(self) -> None:
|
2024-07-22 16:20:56 +08:00
|
|
|
super().__init__(ReflexAction)
|
2024-09-21 16:20:17 +08:00
|
|
|
|
|
|
|
async def get_by_execution_order(self):
|
|
|
|
"""Retrieve reflex actions ordered by execution order"""
|
|
|
|
return await self.get_all(order_by="execution_order")
|
|
|
|
|
|
|
|
async def get_with_custom_logic(self):
|
|
|
|
"""Retrieve reflex actions with custom logic"""
|
|
|
|
return await self.get_all(custom_logic__isnull=False)
|