Skip to content

Commit

Permalink
#366 feat: add User delete (#460)
Browse files Browse the repository at this point in the history
* 366 feat: add user delete in mypage

* #366 feat: add userwithdrawview swagger
  • Loading branch information
kjiyun authored Jul 19, 2023
1 parent 8e51823 commit 8de521c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
10 changes: 10 additions & 0 deletions mypage/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from core.exceptions import ApplicationError

from users.models import User
from users.selectors import UserSelector
from mypage.selectors.follow_selectors import UserFollowSelector

JWT_PAYLOAD_HANDLER = api_settings.JWT_PAYLOAD_HANDLER
Expand Down Expand Up @@ -66,3 +67,12 @@ def update(self,
self.user.save()

return self.user

def withdraw(user: User, password: str):
user_selector = UserSelector()

if not user_selector.check_password(user, password):
raise ApplicationError(
{'detail': "비밀번호가 올바르지 않습니다."})

user.delete()
1 change: 1 addition & 0 deletions mypage/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
path('me/update/', user_info_views.UserUpdateApi.as_view(), name='me_update'),
path('my_reviewed_place/',places_view.UserReviewedPlaceGetApi.as_view(),
name='user_reviewed_place'),
path('withdraw/', user_info_views.UserWithdrawApi.as_view(), name='withdraw'),
path('myplace_search/',places_view.MyPlaceSearchApi.as_view(), name = 'myplace_search')
]
45 changes: 45 additions & 0 deletions mypage/views/user_info_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,48 @@ def patch(self, request):
'status': 'success',
'data': {'id': update.id},
}, status=status.HTTP_200_OK)


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

class UserWithdrawInputSerializer(serializers.Serializer):
password = serializers.CharField()

@swagger_auto_schema(
request_body=UserWithdrawInputSerializer,
security=[],
operation_id='회원 탈퇴하기',
operation_description='''
정보 확인을 위해 비밀번호를 체크한 뒤 회원 탈퇴하기를 진행합니다.
''',
responses={
"200": openapi.Response(
description="OK",
examples={
"application/json": {
"status": "success",
}
}
),
"400": openapi.Response(
description="Bad Request",
),
},
)

def delete(self, request):
serializer = self.UserWithdrawInputSerializer(
data=request.data
)
serializer.is_valid(raise_exception=True)
data=serializer.validated_data

UserInfoService.withdraw(
user=request.user,
password=data.get('password'),
)

return Response({
'status': 'success',
}, status=status.HTTP_200_OK)

0 comments on commit 8de521c

Please sign in to comment.