diff --git a/users/services.py b/users/services.py new file mode 100644 index 0000000..9ea3ba6 --- /dev/null +++ b/users/services.py @@ -0,0 +1,85 @@ +from .models import * +from projects.models import * +from portfolios.models import * + +from django.utils import timezone +from datetime import timedelta + +# 30일 이전 일수 계산 +thirty_days_ago = timezone.now() - timedelta(days=30) + +class CheckUserFieldDuplicateService: + @staticmethod + def check_nickname_duplicate(query): + pass + + @staticmethod + def check_custom_url_duplicate(): + pass + +# 알림 관련 서비스 로직 +class NotifiationService: + @staticmethod + def set_content_by_type(): + pass + + +class UserToNotificationService: + @staticmethod + def get_new_notification_count(user: User): + return user.notifications.filter(created_at__lt=thirty_days_ago, is_read=False).count() + + @staticmethod + def get_all_notification(user: User): + return user.notifications.filter(created_at__lt=thirty_days_ago) + + +# 유저 -> 포트폴리오 관련 서비스 로직 +class UserToPortfolioService: + @staticmethod + def get_represent_portfolio(user: User): + if represent_portfolio := user.owned_portfolios.filter(is_represent=True).first(): + return represent_portfolio.id + else: + return None + + @staticmethod + def get_published_portfolio(user: User): + return user.owned_portfolios.filter(is_published=True) + + @staticmethod + def get_unpublished_portfolio(user: User): + return user.owned_portfolios.filter(is_published=False) + + @staticmethod + def get_scrap_portfolio(user: User): + return user.scrapped_portfolios.filter(is_published=True) + +# 유저 -> 프로젝트 관련 서비스 로직 +class UserToProjectService: + @staticmethod + def get_published_solo_project(user: User): + return user.owned_projects.filter(is_team=False, is_published=True) + + @staticmethod + def get_unpublished_solo_project(user: User): + return user.owned_projects.filter(is_team=False, is_published=False) + + @staticmethod + def get_published_team_project(user: User): + return Project.objects.filter( + team_project_member_list__user = user, + is_published=True + ).distinct() + + @staticmethod + def get_unpublished_team_project(user: User): + return Project.objects.filter( + team_project_member_list__user = user, + is_published=False + ).distinct() + + @staticmethod + def get_scrap_project(user: User): + return user.scrapped_projects.filter(is_published=True) +