diff --git a/account/urls/oj.py b/account/urls/oj.py index d24267f..eeb5e4d 100644 --- a/account/urls/oj.py +++ b/account/urls/oj.py @@ -4,7 +4,7 @@ from ..views.oj import ( ApplyResetPasswordAPI, ResetPasswordAPI, UserChangePasswordAPI, - UserProfileAnalyse, + Metrics, UserRegisterAPI, UserChangeEmailAPI, UserLoginAPI, @@ -35,8 +35,8 @@ urlpatterns = [ path("captcha", CaptchaAPIView.as_view()), path("check_username_or_email", UsernameOrEmailCheck.as_view()), path("profile", UserProfileAPI.as_view(), name="user_profile_api"), - path("profile/analyse", UserProfileAnalyse.as_view()), path("profile/fresh_display_id", ProfileProblemDisplayIDRefreshAPI.as_view()), + path("metrics", Metrics.as_view()), path("upload_avatar", AvatarUploadAPI.as_view()), path("tfa_required", CheckTFARequiredAPI.as_view()), path( diff --git a/account/views/oj.py b/account/views/oj.py index 8ea69ba..29a78c5 100644 --- a/account/views/oj.py +++ b/account/views/oj.py @@ -80,14 +80,22 @@ class UserProfileAPI(APIView): ) -class UserProfileAnalyse(APIView): +class Metrics(APIView): def get(self, request): userid = request.GET.get("userid") - submission = Submission.objects.filter(user_id=userid).latest("create_time") - if not submission: + submissions = Submission.objects.filter(user_id=userid) + if len(submissions) == 0: return self.error("暂无提交") else: - return self.success({"now": timezone.now(), "last": submission.create_time}) + latest_submission = submissions.first() + last_submission = submissions.last() + return self.success( + { + "now": timezone.now(), + "latest": latest_submission.create_time, + "first": last_submission.create_time, + } + ) class AvatarUploadAPI(APIView):