Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat #25 - 유치원 요약 정보 조회 API 구현 #26

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions mung_manager/pet_kindergardens/apis/api_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from mung_manager.pet_kindergardens.apis.apis import (
PetKindergardenListAPI,
PetKindergardenSelectionAPI,
PetKindergardenSummaryInfoAPI,
)
from mung_manager.schemas.errors.authentications import (
ErrorAuthenticationPasswordChangedSchema,
Expand Down Expand Up @@ -117,3 +118,43 @@ class PetKindergardenSelectionAPIManager(BaseAPIManager):
)
def post(self, request, *args, **kwargs):
return self.VIEWS_BY_METHOD["POST"]()(request, *args, **kwargs)


class PetKindergardenSummaryInfoAPIManager(BaseAPIManager):
VIEWS_BY_METHOD = {
"GET": PetKindergardenSummaryInfoAPI.as_view,
}

@extend_schema(
tags=["반려동물 유치원"],
summary="반려동물 유치원 요약 정보 조회",
description="""
Rogic
- 유저 토큰 클레임에 포함된 반려동물 유치원 아이디로 해당 반려동물 유치원의 요약 정보를 조회합니다.
""",
responses={
status.HTTP_200_OK: VIEWS_BY_METHOD["GET"]().cls.OutputSerializer,
status.HTTP_401_UNAUTHORIZED: OpenApiResponse(
response=OpenApiTypes.OBJECT,
examples=[
ErrorAuthenticationFailedSchema,
ErrorNotAuthenticatedSchema,
ErrorInvalidTokenSchema,
ErrorAuthorizationHeaderSchema,
ErrorAuthenticationPasswordChangedSchema,
ErrorAuthenticationUserDeletedSchema,
ErrorAuthenticationUserInactiveSchema,
ErrorAuthenticationUserNotFoundSchema,
ErrorTokenIdentificationSchema,
],
),
status.HTTP_403_FORBIDDEN: OpenApiResponse(
response=OpenApiTypes.OBJECT, examples=[ErrorPermissionDeniedSchema]
),
status.HTTP_500_INTERNAL_SERVER_ERROR: OpenApiResponse(
response=OpenApiTypes.OBJECT, examples=[ErrorUnknownServerSchema]
),
},
)
def get(self, request, *args, **kwargs):
return self.VIEWS_BY_METHOD["GET"]()(request, *args, **kwargs)
28 changes: 27 additions & 1 deletion mung_manager/pet_kindergardens/apis/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rest_framework.response import Response
from rest_framework.views import APIView

from mung_manager.apis.mixins import APIAuthMixin
from mung_manager.apis.mixins import APIAuthMixin, APIAuthWithPetKindergardenAccessMixin
from mung_manager.authentications.containers import AuthenticationContainer
from mung_manager.commons.base.serializers import BaseSerializer
from mung_manager.pet_kindergardens.containers import PetKindergardenContainer
Expand Down Expand Up @@ -56,3 +56,29 @@ def post(self, request: Request) -> Response:
}
).data
return Response(data=auth_data, status=status.HTTP_200_OK)


class PetKindergardenSummaryInfoAPI(APIAuthWithPetKindergardenAccessMixin, APIView):
class OutputSerializer(BaseSerializer):
id = serializers.IntegerField(label="유치원 아이디")
name = serializers.CharField(label="유치원 이름")
business_hour = serializers.CharField(label="유치원 영업 시간")

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._pet_kindergarden_selector = PetKindergardenContainer.pet_kindergarden_selector()

def get(self, request: Request) -> Response:
pet_kindergarden_id = request.pet_kindergarden_id
pet_kindergarden = self._pet_kindergarden_selector.get_by_pet_kindergarden_id_for_summary_info(
pet_kindergarden_id
)
summary_info_data = {
"id": pet_kindergarden["id"],
"name": pet_kindergarden["name"],
"business_hour": pet_kindergarden["business_start_hour"].strftime("%H:%M")
+ " - "
+ pet_kindergarden["business_end_hour"].strftime("%H:%M"),
DongwookKim0823 marked this conversation as resolved.
Show resolved Hide resolved
}
pet_kindergardens_data = self.OutputSerializer(summary_info_data).data
return Response(data=pet_kindergardens_data, status=status.HTTP_200_OK)
6 changes: 6 additions & 0 deletions mung_manager/pet_kindergardens/apis/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from mung_manager.pet_kindergardens.apis.api_managers import (
PetkindergardenListAPIManager,
PetKindergardenSelectionAPIManager,
PetKindergardenSummaryInfoAPIManager,
)

urlpatterns = [
Expand All @@ -16,4 +17,9 @@
PetKindergardenSelectionAPIManager.as_view(),
name="pet-kindergarden-selection",
),
path(
"/summary",
PetKindergardenSummaryInfoAPIManager.as_view(),
name="pet-kindergarden-summary-info",
),
]
11 changes: 6 additions & 5 deletions mung_manager/pet_kindergardens/selectors/abstracts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
from typing import Any
from typing import Any, Optional

from django.db.models.query import QuerySet

Expand All @@ -9,8 +9,9 @@
class AbstractPetKindergardenSelector(ABC):

@abstractmethod
def get_queryset_by_user(
self,
user,
) -> QuerySet[Any]:
def get_queryset_by_user(self, user) -> QuerySet[Any]:
raise NotImplementedException()

@abstractmethod
def get_by_pet_kindergarden_id_for_summary_info(self, pet_kindergarden_id: int) -> Optional[Any]:
DongwookKim0823 marked this conversation as resolved.
Show resolved Hide resolved
raise NotImplementedException()
22 changes: 20 additions & 2 deletions mung_manager/pet_kindergardens/selectors/pet_kindergardens.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, Optional

from django.db.models import F, QuerySet, Value
from django.db.models.functions import Concat
Expand All @@ -15,7 +15,8 @@ class PetKindergardenSelector(AbstractPetKindergardenSelector):
"""

def get_queryset_by_user(self, user) -> QuerySet[Any]:
"""이 함수는 사용자 정보로, 해당 사용자가 속한 유치원 목록을 조회합니다.
"""
이 함수는 사용자 정보로, 해당 사용자가 속한 유치원 목록을 조회합니다.

DongwookKim0823 marked this conversation as resolved.
Show resolved Hide resolved
Args:
user: User: 유저 객체
Expand All @@ -29,3 +30,20 @@ def get_queryset_by_user(self, user) -> QuerySet[Any]:
.annotate(full_address=Concat(F("road_address"), Value(" "), F("detail_address")))
.values("id", "name", "full_address", "profile_thumbnail_url")
)

def get_by_pet_kindergarden_id_for_summary_info(self, pet_kindergarden_id: int) -> Optional[Any]:
"""
이 함수는 반려동물 유치원 아이디로 해당 반려동물 유치원의 요약 정보를 조회합니다.
DongwookKim0823 marked this conversation as resolved.
Show resolved Hide resolved

Args:
pet_kindergarden_id (int): 반려동물 유치원 아이디

Returns:
Optional[Any]: 반려동물 유치원이 존재하지 않으면 None을 반환
"""

return (
PetKindergarden.objects.filter(id=pet_kindergarden_id)
.values("id", "name", "business_start_hour", "business_end_hour")
.get()
)
Loading