diff --git a/web/project/app/models.py b/web/project/app/models.py index 29b5194..8150821 100644 --- a/web/project/app/models.py +++ b/web/project/app/models.py @@ -74,7 +74,9 @@ class Meta: class DuoMatch(models.Model): - id = models.CharField(max_length=36, blank=False, null=False, primary_key=True, default=uuid.uuid4) + id = models.CharField( + max_length=36, blank=False, null=False, primary_key=True, default=uuid.uuid4 + ) user1 = models.ForeignKey(User, on_delete=models.CASCADE, related_name="user1") user2 = models.ForeignKey(User, on_delete=models.CASCADE, related_name="user2") created_at = models.DateTimeField(auto_now_add=True) diff --git a/web/project/app/urls.py b/web/project/app/urls.py index 642b377..debbb0f 100644 --- a/web/project/app/urls.py +++ b/web/project/app/urls.py @@ -32,7 +32,6 @@ path("match/duo/history", get_duo_match_history, name="get-duo-match-history"), path("tos", terms_of_service, name="terms-of-service"), path("privacy", privacy_policy, name="privacy-policy"), - ] if settings.DEBUG: diff --git a/web/project/app/views.py b/web/project/app/views.py index 0b2e29e..90079ec 100644 --- a/web/project/app/views.py +++ b/web/project/app/views.py @@ -185,9 +185,9 @@ def inference(request: WSGIRequest): me = request.user # Fake User - + user = AppUser.objects.get(id=2) - + result = DuoMatch.objects.create(user1=me, user2=user) result.save() @@ -200,20 +200,21 @@ def inference(request: WSGIRequest): safe=False, ) + def get_duo_match(request: WSGIRequest): duo_match_id = request.GET.get("duo_match_id") - + if not duo_match_id: return JsonResponse({"error": "duo_match_id is required"}, status=400) - + duo_match = DuoMatch.objects.get(id=duo_match_id) - + summoner2: Summoner = duo_match.user2.summoner - + summoner2_rank = LeagueEntry.objects.get(summoner=summoner2) - + return render( - request, + request, "recommend/duo_match.html", { "user": request.user, @@ -223,21 +224,22 @@ def get_duo_match(request: WSGIRequest): }, ) + def _n_days_ago(target_date: datetime.datetime): timezone = datetime.timezone(datetime.timedelta(hours=9)) today = datetime.datetime.now().astimezone(timezone) - + diff = today - target_date.astimezone(timezone) - + if diff.days == 0 and diff.seconds < 3600: return f"{diff.seconds // 60}분 전" - + if diff.days == 0: return f"{diff.seconds // 3600}시간 전" - + if diff.days < 7: return f"{diff.days}일 전" - + return f"{diff.days}일 전" @@ -245,21 +247,25 @@ def _n_days_ago(target_date: datetime.datetime): def get_duo_match_history(request: WSGIRequest): me = request.user timezone = datetime.timezone(datetime.timedelta(hours=9)) - today = datetime.datetime.now().astimezone(timezone) duo_matches = [ { "id": duo_match.id, "target_username": duo_match.user2.summoner.name, - "target_profile_icon_id": duo_match.user2.summoner.profile_icon_id, - "target_summoner_tier": LeagueEntry.objects.get(summoner=duo_match.user2.summoner).tier, - "target_summoner_rank": LeagueEntry.objects.get(summoner=duo_match.user2.summoner).rank, - "created_at": duo_match.created_at.astimezone(timezone).strftime("%Y-%m-%d %H:%M:%S"), + "target_profile_icon_id": duo_match.user2.summoner.profile_icon_id, + "target_summoner_tier": LeagueEntry.objects.get( + summoner=duo_match.user2.summoner + ).tier, + "target_summoner_rank": LeagueEntry.objects.get( + summoner=duo_match.user2.summoner + ).rank, + "created_at": duo_match.created_at.astimezone(timezone).strftime( + "%Y-%m-%d %H:%M:%S" + ), "n_days_ago": _n_days_ago(duo_match.created_at), } for duo_match in DuoMatch.objects.filter(user1=me).order_by("-created_at") ] - return render( request,