Skip to content

Commit

Permalink
'FEAT:02-03'
Browse files Browse the repository at this point in the history
  • Loading branch information
jelee2555 committed Aug 30, 2023
1 parent 32ad771 commit 7eedfa2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Binary file modified accounts/__pycache__/views.cpython-311.pyc
Binary file not shown.
27 changes: 25 additions & 2 deletions accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ def get(self, request):
# 01-02 이메일 로그인
def post(self, request):
# user 인증
print(request.data)

user = authenticate(
username=request.data.get("email"), password=request.data.get("password")
)
Expand Down Expand Up @@ -189,6 +187,31 @@ def post(self, request):
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


# API 02-03 회원 정보 수정
# PUT vs PATCH
# PUT : 모든 속성 수정 / PATCH : 일부 속성 수정
@login_check
def put(self, request):
# User의 userinfo가 존재하는 지 확인
is_exist = Userinfo.objects.filter(user_id=request.user.id)
if not is_exist:
return Response({'message': 'No Userinfo'}, status=status.HTTP_400_BAD_REQUEST)

request.data['user'] = request.user.id

userinfo = Userinfo.objects.get(user_id=request.user.id)

# bmi 계산
weight = request.data.get('weight')
height = request.data.get('height') * 0.01
bmi = round(weight / (height * height), 2)
request.data['bmi'] = bmi

serializer = UserinfoSerializer(userinfo, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


class UserDetailAPIView(APIView):
Expand Down

0 comments on commit 7eedfa2

Please sign in to comment.