85 lines
2.6 KiB
Python
85 lines
2.6 KiB
Python
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)
|
|
|
|
DUPLICATE_CHECK = {
|
|
'email': 'email',
|
|
'nickname': 'nickname'
|
|
}
|
|
|
|
class CheckUserFieldDuplicateService:
|
|
@staticmethod
|
|
def check_duplicate(field: str, value: str) -> bool:
|
|
if field not in DUPLICATE_CHECK:
|
|
raise ValueError(f"{field}는 지원하지 않는 필드입니다.")
|
|
|
|
filter_dict = {DUPLICATE_CHECK[field]:value}
|
|
return User.objects.filter(**filter_dict).exists()
|
|
|
|
|
|
|
|
class UserToNotificationService:
|
|
@staticmethod
|
|
def get_new_notification_count(user: User):
|
|
return user.notifications.filter(created_at__gt=thirty_days_ago, is_read=False).count()
|
|
|
|
@staticmethod
|
|
def get_all_notification(user: User):
|
|
return user.notifications.filter(created_at__gt=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)
|