Skip to content

Commit

Permalink
#53 feat : make update service api (#56)
Browse files Browse the repository at this point in the history
* Update deploy.yml

rsync option 변경

* Update deploy.yml

* Update deploy.yml

* #53 feat : make update service api
  • Loading branch information
0321minji authored Jun 5, 2024
1 parent 2726614 commit 74b92a6
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.
31 changes: 31 additions & 0 deletions services/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,37 @@ def create(name : str,basic_price : str, max_price: str, option : str,info : str
service.detail.set(detail)
return service

# @staticmethod
# @transaction.atomic
# def update(service:Service,
# name : str,basic_price : str, max_price: str, option : str,info : str,notice : str,
# period : str,transaction_direct : bool,transaction_package : bool,refund : str, reformer : User,
# category : str, style : list[str], texture : list[str], fit : list[str], detail:list[str]):
# category=get_object_or_404(Category,id=category)
# style=Style.objects.filter(id__in=style)
# texture=Texture.objects.filter(id__in=texture)
# fit=Fit.objects.filter(id__in=fit)
# detail=Detail.objects.filter(id__in=detail)

# service.name=name
# service.basic_price=basic_price
# service.

# service.style.set(style)
# service.texture.set(texture)
# service.fit.set(fit)
# service.detail.set(detail)

# service.full_clean()
# service.save()
# return service
@staticmethod
def update(service,data):
for key,value in data.items():
setattr(service,key,value)
service.save()
return service

class ServicePhotoService:
def __init__(self, file):
self.file = file
Expand Down
1 change: 1 addition & 0 deletions services/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
path('',ServiceListApi.as_view(),name='service_list'),
path('<int:service_id>/like/',ServiceLikeApi.as_view(), name='service_like'),
path('<int:service_id>/', ServiceDetailApi.as_view(), name='service_detail'),
path('<int:service_id>/update/',ServiceUpdateApi.as_view(),name='service_update'),
]
79 changes: 78 additions & 1 deletion services/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,5 +390,82 @@ def post(self, request, service_id):
'data':{'likes':likes},
},status=status.HTTP_200_OK)

class ServiceUpdateApi(APIView):
permission_classes=(IsAuthenticated,)

class ServiceUpdateInputSerializer(serializers.Serializer):
name= serializers.CharField(required=False)
category=serializers.CharField(required=False)
style=serializers.ListField(required=False)
fit=serializers.ListField(required=False)
texture=serializers.ListField(required=False)
detail=serializers.ListField(required=False)
keywords = serializers.ListField(required=False)
basic_price = serializers.CharField(required=False)
max_price = serializers.CharField(required=False)
option = serializers.CharField(required=False)
service_photos = serializers.ListField(required=False)
info = serializers.CharField(required=False)
notice = serializers.CharField(required=False)
period = serializers.CharField(required=False)
transaction_direct = serializers.BooleanField(required=False)
transaction_package = serializers.BooleanField(required=False)
refund = serializers.CharField(required=False)
def __init__(self, *args, **kwargs):
self.service = kwargs.pop('service', None)
super().__init__(*args, **kwargs)


@swagger_auto_schema(
request_body=ServiceUpdateInputSerializer,
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",
"transaction_direct": "true",
"transaction_package": 'true',
"refund": "환불 관련 정보",
}
}
),
"400": openapi.Response(
description="Bad Request",
)
}
)

def patch(self,request,service_id):
try:
service=Service.objects.get(pk=service_id)
except Service.DoesNotExist:
return Response({
'status':'failure',
'message':'Service is not found',
},status=status.HTTP_404_NOT_FOUND)

serializer=self.ServiceUpdateInputSerializer(service=service,data=request.data,partial=True)
serializer.is_valid(raise_exception=True)
data=serializer.validated_data

service=ServiceService.update(service,data)
return Response({
'status': 'success',
'data': {'id': service.id},
}, status=status.HTTP_200_OK)

0 comments on commit 74b92a6

Please sign in to comment.