From 1afa4295edcff077f13ed142431ee5f67827b181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=8D?= <79096808+0321minji@users.noreply.github.com> Date: Wed, 8 May 2024 20:37:21 +0900 Subject: [PATCH] #39 feat: make swagger of services api (#43) --- services/views.py | 180 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 179 insertions(+), 1 deletion(-) diff --git a/services/views.py b/services/views.py index b9757782..16f0a78e 100644 --- a/services/views.py +++ b/services/views.py @@ -14,6 +14,9 @@ from .services import ServiceCoordinatorService, ServiceService, ServicePhotoService, ServiceKeywordService from .selectors import ServiceSelector +from drf_yasg import openapi +from drf_yasg.utils import swagger_auto_schema + # Create your views here. class ServiceCreateApi(APIView): permission_classes=(AllowAny,) @@ -39,6 +42,41 @@ class ServiceCreateInputSerializer(serializers.Serializer): transaction_package = serializers.BooleanField() refund = serializers.CharField() + @swagger_auto_schema( + request_body=ServiceCreateInputSerializer, + security=[], + operation_id='서비스 생성 API', + operation_description="서비스를 생성하는 API입니다.", + responses={ + "200":openapi.Response( + description="OK", + examples={ + "application/json":{ + "name":"서비스 이름", + "category":"1", + "style":[1,2], + "fit":[1], + "texture":[1], + "detail":[], + "keywords":[], + "basic_price":'8000', + "max_price":'12000', + "option":'단추', + "service_photos":'~~~.img', + "info":"서비스 정보", + "notice":'서비스 관련 공지사항', + "period":"3", + "trasaction_direct":"true", + "trasaction_package":'true', + "refund":"환불 관련 정보", + } + } + ), + "400":openapi.Response( + description="Bad Request", + ) + } + ) def post(self,request): serializers = self.ServiceCreateInputSerializer(data=request.data) serializers.is_valid(raise_exception=True) @@ -83,6 +121,26 @@ class ServicePhotoCreateApi(APIView): class ServicePhotoCreateInputSerializer(serializers.Serializer): image = serializers.ImageField() + + @swagger_auto_schema( + request_body=ServicePhotoCreateInputSerializer, + security=[], + operation_id='서비스 사진 등록 API', + operation_description="서비스 사진을 등록하는 API 입니다.", + responses={ + "200":openapi.Response( + description="OK", + examples={ + "application/json":{ + "status":"success", + } + } + ), + "400":openapi.Response( + description="Bad Request", + ), + } + ) def post(self, request): serializers = self.ServicePhotoCreateInputSerializer(data=request.data) @@ -126,7 +184,46 @@ class ServiceDetailOuputSerialier(serializers.Serializer): transaction_direct=serializers.BooleanField() transaction_package=serializers.BooleanField() - + + @swagger_auto_schema( + security=[], + operation_id='서비스 글 조회 API', + operation_description=''' + 전달된 id에 해당하는 서비스 글 디테일을 조회합니다.
+ photos 배열 중 0번째 원소가 대표 이미지(rep_pic)입니다.
+ ''', + responses={ + "200":openapi.Response( + description="OK", + examples={ + "application/json":{ + "name":'services_test_240106', + "category":'1', + "style":[1,2], + "fit":[1], + "texture":[1,2,3], + "detail":[], + "keywords":['후드티','후드'], + "basic_price":1000, + "info":'product no 1', + "notice":'noticesssss', + "option":'긴팔', + "period":3, + "transaction_direct":'true', + "transaction_package":'true', + "refund":'환불정책', + "reformer":"sdptech@gmail.com", + "likeuserset":['user1@gmail.com','user2@gmail.com',], + 'likecnt':2, + } + } + ), + "400":openapi.Response( + description="Bad Request", + ), + } + ) + def get(self,request,service_id): service=ServiceSelector.detail(service_id=service_id, user=request.user) serializer=self.ServiceDetailOuputSerialier(service) @@ -166,6 +263,65 @@ class ServiceListOutputSerializer(serializers.Serializer): fit=serializers.ListField(child=serializers.DictField()) detail=serializers.ListField(child=serializers.DictField()) + @swagger_auto_schema( + security=[], + operation_id='서비스 목록 조회 API', + operation_description=''' + 전달된 쿼리 파라미터에 부합하는 서비스 글 리스트를 반환합니다.
+ photos 배열 중 0번째 원소가 대표 이미지(rep_pic)입니다.
+
+ search : name, info 내 검색어
+ order : 정렬 기준(latest, hot)
+ category_filter: 카테고리 id
+ style_filter: 스타일 id
+ fit_filter: 핏 id
+ texture_filter : 텍스쳐 id
+ detail_filter: 디테일 id
+ ''', + responses={ + "200":openapi.Response( + description="OK", + examples={ + "application/json": { + "status": "success", + "data": { + "count": 1, + "next": None, + "previous": None, + "results": [ + { + "id": 1, + "name":'services_test_240106', + "category":'1', + "style":[1,2], + "fit":[1], + "texture":[1,2,3], + "detail":[], + "keywords":['후드티','후드'], + "basic_price":1000, + "info":'product no 1', + "notice":'noticesssss', + "option":'긴팔', + "period":3, + "transaction_direct":'true', + "transaction_package":'true', + "refund":'환불정책', + "reformer":"sdptech@gmail.com", + "likeuserset":['user1@gmail.com','user2@gmail.com',], + 'likecnt':2, + }, + ] + } + } + } + ), + + "400":openapi.Response( + description="Bad Request", + ), + } + ) + def get(self,request): filters_serializer=self.ServiceListFilterSerializer( data=request.query_params) @@ -194,6 +350,28 @@ def get(self,request): class ServiceLikeApi(APIView): permission_classes=(IsAuthenticated, ) + @swagger_auto_schema( + operation_id='서비스 좋아요 또는 좋아요 취소', + operation_description=''' + 입력한 id를 가지는 서비스에 대한 사용자의 좋아요/좋아요 취소를 수행합니다.
+ 결과로 좋아요 상태(TRUE:좋아요, FALSE:좋아요X)가 반환됩니다. + ''', + responses={ + "200": openapi.Response( + description="OK", + examples={ + "application/json": { + "status": "success", + "data": {"likes": True} + } + } + ), + "400": openapi.Response( + description="Bad Request", + ), + }, + ) + def post(self, request, service_id): likes=ServiceService.like_or_dislike( service=get_object_or_404(Service,pk=service_id),