Skip to content

Commit

Permalink
#39 feat: make swagger of services api (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
0321minji authored May 8, 2024
1 parent bf22f6a commit 1afa429
Showing 1 changed file with 179 additions and 1 deletion.
180 changes: 179 additions & 1 deletion services/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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에 해당하는 서비스 글 디테일을 조회합니다.<br/>
photos 배열 중 0번째 원소가 대표 이미지(rep_pic)입니다.<br/>
''',
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":"[email protected]",
"likeuserset":['[email protected]','[email protected]',],
'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)
Expand Down Expand Up @@ -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='''
전달된 쿼리 파라미터에 부합하는 서비스 글 리스트를 반환합니다.<br/>
photos 배열 중 0번째 원소가 대표 이미지(rep_pic)입니다.<br/>
<br/>
search : name, info 내 검색어<br/>
order : 정렬 기준(latest, hot)<br/>
category_filter: 카테고리 id <br/>
style_filter: 스타일 id <br/>
fit_filter: 핏 id <br/>
texture_filter : 텍스쳐 id <br/>
detail_filter: 디테일 id <br/>
''',
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":"[email protected]",
"likeuserset":['[email protected]','[email protected]',],
'likecnt':2,
},
]
}
}
}
),
"400":openapi.Response(
description="Bad Request",
),
}
)

def get(self,request):
filters_serializer=self.ServiceListFilterSerializer(
data=request.query_params)
Expand Down Expand Up @@ -194,6 +350,28 @@ def get(self,request):
class ServiceLikeApi(APIView):
permission_classes=(IsAuthenticated, )

@swagger_auto_schema(
operation_id='서비스 좋아요 또는 좋아요 취소',
operation_description='''
입력한 id를 가지는 서비스에 대한 사용자의 좋아요/좋아요 취소를 수행합니다.<br/>
결과로 좋아요 상태(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),
Expand Down

0 comments on commit 1afa429

Please sign in to comment.