Skip to content

Commit

Permalink
Merge pull request #106 from snuhcs-course/feat/initialize-weights-ba…
Browse files Browse the repository at this point in the history
…ckend

Initialize weight table when signing up (Backend)
  • Loading branch information
JH747 authored Dec 7, 2023
2 parents 5cb070b + c6429e8 commit 45ae686
Show file tree
Hide file tree
Showing 5 changed files with 511 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/setup/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_get_settings_success(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
data = response.json()
self.assertEqual(data['display_mode'], 0) # 0 is the default value
self.assertEqual(data['default_menu'], 0) # 0 is the default value
self.assertEqual(data['default_menu'], 1) # 1 is the default value



Expand Down
2 changes: 1 addition & 1 deletion backend/setup/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get(self, request):
if not Setting.objects.filter(user=user).exists():
response_data = {
"display_mode": 0,
"default_menu": 0,
"default_menu": 1,
"updated_at": ""
}
else:
Expand Down
7 changes: 7 additions & 0 deletions backend/user/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from user.models import EmailVerification
from user.utils import normalize_email
from weight_table.models import WeightTable

User = get_user_model()

Expand All @@ -30,6 +31,12 @@ def create(self, validated_data):
password = validated_data.get('password')
nickname = validated_data.get('nickname')
user = User.objects.create_user(nickname, email, password)

with open('./weight_table.txt', 'r') as file:
for symbol_id, line in enumerate(file, start=1):
weight = f"[{line}]"
WeightTable.objects.create(symbol_id=symbol_id, weight=weight, user=user)

return user


Expand Down
2 changes: 2 additions & 0 deletions backend/user/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import boto3
from django.contrib.auth import get_user_model
from django.core.mail import EmailMessage
from django.db import transaction
from rest_framework import status, permissions
from rest_framework.views import APIView
from rest_framework.response import Response
Expand All @@ -22,6 +23,7 @@
class UserSignUpView(APIView):
permission_classes = (permissions.AllowAny,)

@transaction.atomic
def post(self, request):
serializer = UserSignUpSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
Expand Down
Loading

0 comments on commit 45ae686

Please sign in to comment.