From fecca366c890cd8a9b63c2c92474c08c7595c69b Mon Sep 17 00:00:00 2001 From: sm4640 Date: Fri, 2 May 2025 18:17:05 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Feat:=20[#41]=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EC=99=80=20=EB=8B=A4=EB=A5=B8=20=ED=85=8C=EC=9D=B4=EB=B8=94?= =?UTF-8?q?=EA=B0=84=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- users/services.py | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 users/services.py 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) +