Skip to content

Commit

Permalink
Merge pull request #224 from DongwookKim0823/refactor/223-current-gen…
Browse files Browse the repository at this point in the history
…eration-to-latest-generation

[REFACTOR] 현재 기수 조회 기능 수정 #223
  • Loading branch information
DongwookKim0823 authored Sep 2, 2024
2 parents 36b2522 + e2429c7 commit 0e45beb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
10 changes: 5 additions & 5 deletions backend/attendance/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,12 @@ class UserListResponseSerializer(serializers.Serializer):
response_only=True,
)

CURRENT_GENERATION_SUCCESS_EXAMPLE = OpenApiExample(
"현재 기수 조회 성공 예시",
summary="Current Generation Success",
description="현재 기수 조회가 성공적으로 처리되었을 때의 응답 예시입니다.",
LATEST_GENERATION_SUCCESS_EXAMPLE = OpenApiExample(
"최근 기수 조회 성공 예시",
summary="Latest Generation Success",
description="최근 기수 조회가 성공적으로 처리되었을 때의 응답 예시입니다.",
value={
"detail": "현재 기수 조회를 성공했습니다.",
"detail": "최근 기수 조회를 성공했습니다.",
"data": {
"generation": 12,
},
Expand Down
4 changes: 2 additions & 2 deletions backend/attendance/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from attendance.views import (
AttendanceAcceptAPIView,
AttendanceAPIView,
AttendanceCurrentGenerationAPIView,
AttendanceDetailAPIView,
AttendanceLatestGenerationAPIView,
AttendanceLocationAPIView,
AttendanceRateAPIView,
AttendanceRejectAPIView,
Expand All @@ -21,5 +21,5 @@
path("users/<int:user_id>/details/", AttendanceDetailAPIView.as_view(), name="attendance-detail"),
path("location/", AttendanceLocationAPIView.as_view(), name="attendance-location"),
path("users/", AttendanceUserListAPIView.as_view(), name="attendance-user-list"),
path("current-generation/", AttendanceCurrentGenerationAPIView.as_view(), name="attendance-current-generation"),
path("latest-generation/", AttendanceLatestGenerationAPIView.as_view(), name="attendance-latest-generation"),
]
23 changes: 11 additions & 12 deletions backend/attendance/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
ATTENDANCE_REQUEST_LIST_SUCCESS_EXAMPLE,
ATTENDANCE_REQUEST_SUCCESS_EXAMPLE,
ATTENDANCE_STATUS_SUCCESS_EXAMPLE,
CURRENT_GENERATION_SUCCESS_EXAMPLE,
DUPLICATE_ATTENDANCE_EXAMPLE,
INTERNAL_SERVER_ERROR_EXAMPLE,
INVALID_ACCOUNT_EXAMPLE,
INVALID_FIELD_STATE_EXAMPLE,
LATEST_GENERATION_SUCCESS_EXAMPLE,
NOT_EXIST_EXAMPLE,
PERMISSION_DENIED_EXAMPLE,
REJECTION_SUCCESS_EXAMPLE,
Expand Down Expand Up @@ -653,21 +653,21 @@ def get(self, request: Request) -> Response:
)


class AttendanceCurrentGenerationAPIView(APIView):
class AttendanceLatestGenerationAPIView(APIView):
"""
현재 기수 조회를 위한 클래스입니다.
최근 기수 조회를 위한 클래스입니다.
"""

permission_classes = [IsAuthenticated]

@extend_schema(
tags=["출석"],
summary="현재 기수 조회",
description="현재 기수를 조회합니다.",
summary="최근 기수 조회",
description="최근 기수를 조회합니다.",
responses={
status.HTTP_200_OK: OpenApiResponse(
response=UserListResponseSerializer,
examples=[CURRENT_GENERATION_SUCCESS_EXAMPLE],
examples=[LATEST_GENERATION_SUCCESS_EXAMPLE],
),
status.HTTP_401_UNAUTHORIZED: OpenApiResponse(
response=ErrorResponseSerializer,
Expand All @@ -680,18 +680,17 @@ class AttendanceCurrentGenerationAPIView(APIView):
},
)
def get(self, request: Request) -> Response:
current_date: date = timezone.now().date()
generation_object = Generation.objects.filter(start_date__lte=current_date, end_date__gte=current_date).first()
generation_object = Generation.objects.filter(start_date__isnull=False).order_by("-start_date").first()

current_generation = None
latest_generation = None
if generation_object:
current_generation = generation_object.name[:-1]
latest_generation = int(generation_object.name[:-1])

return Response(
data={
"detail": "현재 기수 조회를 성공했습니다.",
"detail": "최근 기수 조회를 성공했습니다.",
"data": {
"generation": current_generation,
"generation": latest_generation,
},
},
status=status.HTTP_200_OK,
Expand Down

0 comments on commit 0e45beb

Please sign in to comment.