Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kwanok committed Mar 25, 2024
1 parent 9cc47fe commit 5915c5d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
4 changes: 3 additions & 1 deletion web/project/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion web/project/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
44 changes: 25 additions & 19 deletions web/project/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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,
Expand All @@ -223,43 +224,48 @@ 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}일 전"


@login_required(login_url="/accounts/discord/login/")
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,
Expand Down

0 comments on commit 5915c5d

Please sign in to comment.