2023-11-24 12:25:02 +03:00
|
|
|
from uuid import UUID
|
|
|
|
|
|
|
|
from modules.onboarding.dto.inputs import OnboardingUpdatableProperties
|
|
|
|
from modules.onboarding.entity.onboarding import OnboardingStates
|
|
|
|
from modules.onboarding.repository.onboardings import Onboarding
|
2023-11-28 16:27:39 +03:00
|
|
|
from modules.onboarding.repository.onboardings_interface import OnboardingInterface
|
2023-11-24 12:25:02 +03:00
|
|
|
|
|
|
|
|
|
|
|
class OnboardingService:
|
2023-11-28 16:27:39 +03:00
|
|
|
repository: OnboardingInterface
|
2023-11-24 12:25:02 +03:00
|
|
|
|
|
|
|
def __init__(self):
|
2023-11-28 16:27:39 +03:00
|
|
|
self.repository = Onboarding()
|
2023-11-24 12:25:02 +03:00
|
|
|
|
|
|
|
def create_user_onboarding(self, user_id: UUID) -> OnboardingStates:
|
|
|
|
"""Update user onboarding information by user_id"""
|
|
|
|
|
|
|
|
return self.repository.create_user_onboarding(user_id)
|
|
|
|
|
|
|
|
def get_user_onboarding(self, user_id: UUID) -> OnboardingStates | None:
|
|
|
|
"""
|
|
|
|
Get a user's onboarding status
|
|
|
|
|
|
|
|
Args:
|
|
|
|
user_id (UUID): The id of the user
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Onboardings: The user's onboarding status
|
|
|
|
"""
|
|
|
|
return self.repository.get_user_onboarding(user_id)
|
|
|
|
|
|
|
|
def remove_onboarding_more_than_x_days(self, days: int):
|
|
|
|
"""
|
|
|
|
Remove onboarding if it is older than x days
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.repository.remove_onboarding_more_than_x_days(days)
|
|
|
|
|
|
|
|
def update_user_onboarding(
|
|
|
|
self, user_id: UUID, onboarding: OnboardingUpdatableProperties
|
|
|
|
) -> OnboardingStates:
|
|
|
|
"""Update user onboarding information by user_id"""
|
|
|
|
|
|
|
|
updated_onboarding = self.repository.update_user_onboarding(user_id, onboarding)
|
|
|
|
|
|
|
|
if all(not value for value in updated_onboarding.dict().values()):
|
|
|
|
self.repository.remove_user_onboarding(user_id)
|
|
|
|
|
|
|
|
return updated_onboarding
|