diff --git a/accounts/__pycache__/models.cpython-311.pyc b/accounts/__pycache__/models.cpython-311.pyc index 43572c0..dcd5392 100644 Binary files a/accounts/__pycache__/models.cpython-311.pyc and b/accounts/__pycache__/models.cpython-311.pyc differ diff --git a/accounts/__pycache__/views.cpython-311.pyc b/accounts/__pycache__/views.cpython-311.pyc index ce1e6d7..ecce009 100644 Binary files a/accounts/__pycache__/views.cpython-311.pyc and b/accounts/__pycache__/views.cpython-311.pyc differ diff --git a/accounts/migrations/0001_initial.py b/accounts/migrations/0001_initial.py index f205bd8..dabe4eb 100644 --- a/accounts/migrations/0001_initial.py +++ b/accounts/migrations/0001_initial.py @@ -1,8 +1,9 @@ -# Generated by Django 3.2.16 on 2024-01-19 06:02 +# Generated by Django 3.2.16 on 2024-01-21 19:09 import django.contrib.auth.models import django.contrib.auth.validators from django.db import migrations, models +import django.db.models.deletion import django.utils.timezone @@ -12,6 +13,7 @@ class Migration(migrations.Migration): dependencies = [ ('auth', '0012_alter_user_first_name_max_length'), + ('llo', '0001_initial'), ] operations = [ @@ -32,6 +34,7 @@ class Migration(migrations.Migration): ('phone_number', models.CharField(max_length=15, unique=True)), ('nickname', models.CharField(blank=True, max_length=255)), ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')), + ('selected_team', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='llo.selectedteam')), ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')), ], options={ diff --git a/accounts/migrations/0002_customuser_selected_team.py b/accounts/migrations/0002_customuser_selected_team.py deleted file mode 100644 index fb235d3..0000000 --- a/accounts/migrations/0002_customuser_selected_team.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.2.16 on 2024-01-20 08:26 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('accounts', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='customuser', - name='selected_team', - field=models.IntegerField(blank=True, null=True), - ), - ] diff --git a/accounts/migrations/__pycache__/0001_initial.cpython-311.pyc b/accounts/migrations/__pycache__/0001_initial.cpython-311.pyc index 5fe6400..798b81f 100644 Binary files a/accounts/migrations/__pycache__/0001_initial.cpython-311.pyc and b/accounts/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/accounts/migrations/__pycache__/0002_customuser_selected_team.cpython-311.pyc b/accounts/migrations/__pycache__/0002_customuser_selected_team.cpython-311.pyc deleted file mode 100644 index d3fc987..0000000 Binary files a/accounts/migrations/__pycache__/0002_customuser_selected_team.cpython-311.pyc and /dev/null differ diff --git a/accounts/models.py b/accounts/models.py index c28d737..e427192 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -2,8 +2,9 @@ from django.db import models from django.contrib.auth.models import AbstractUser +from llo.models import SelectedTeam class CustomUser(AbstractUser): phone_number = models.CharField(max_length=15, unique=True) nickname = models.CharField(max_length=255, blank=True) - selected_team = models.IntegerField(null=True, blank=True) + selected_team = models.ForeignKey(SelectedTeam, null=True, blank=True, on_delete=models.SET_NULL) diff --git a/accounts/views.py b/accounts/views.py index 0d6a0e5..43137f8 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -6,16 +6,24 @@ from rest_framework_simplejwt.tokens import RefreshToken from .models import CustomUser from .serializers import CustomUserSerializer +from llo.models import SelectedTeam @api_view(['POST']) @permission_classes([AllowAny]) def register_user(request): data = request.data serializer = CustomUserSerializer(data=data) - selected_team = request.data.get('selected_team') + selected_team_id = request.data.get('selected_team') # 'selected_team'로부터 팀 ID를 받아옴 if serializer.is_valid(): - serializer.save(selected_team=selected_team) - return Response(serializer.data, status=status.HTTP_201_CREATED) + user = serializer.save() + + # 선택한 팀 정보를 사용자와 연결 + if selected_team_id: + selected_team = SelectedTeam.objects.get(id=selected_team_id) + user.selected_team = selected_team + user.save() + + return Response({'detail': 'User registered successfully'}, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) @api_view(['POST']) @@ -42,9 +50,9 @@ def login_user(request): # 인증 실패 return Response({'detail': 'Invalid credentials'}, status=status.HTTP_401_UNAUTHORIZED) + @api_view(['POST']) @permission_classes([IsAuthenticated]) def logout_user(request): # You can add additional logout logic here if needed return Response({'detail': 'Successfully logged out'}, status=status.HTTP_200_OK) - diff --git a/madcamp_week4_BE/__pycache__/settings.cpython-311.pyc b/madcamp_week4_BE/__pycache__/settings.cpython-311.pyc index 625fb44..bce9262 100644 Binary files a/madcamp_week4_BE/__pycache__/settings.cpython-311.pyc and b/madcamp_week4_BE/__pycache__/settings.cpython-311.pyc differ diff --git a/madcamp_week4_BE/__pycache__/urls.cpython-311.pyc b/madcamp_week4_BE/__pycache__/urls.cpython-311.pyc index 760e7d5..9436dfe 100644 Binary files a/madcamp_week4_BE/__pycache__/urls.cpython-311.pyc and b/madcamp_week4_BE/__pycache__/urls.cpython-311.pyc differ diff --git a/madcamp_week4_BE/settings.py b/madcamp_week4_BE/settings.py index 1b49c89..7afdec0 100644 --- a/madcamp_week4_BE/settings.py +++ b/madcamp_week4_BE/settings.py @@ -52,6 +52,7 @@ 'accounts', 'info', 'llo', + 'news', ] # Authentication backends diff --git a/madcamp_week4_BE/urls.py b/madcamp_week4_BE/urls.py index ddcca5e..fb7558e 100644 --- a/madcamp_week4_BE/urls.py +++ b/madcamp_week4_BE/urls.py @@ -7,4 +7,5 @@ path('accounts/', include('accounts.urls')), path('info/', include('info.urls')), path('llo/', include('llo.urls')), + path('news/', include('news.urls')), ] diff --git a/news/__init__.py b/news/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/news/__pycache__/__init__.cpython-311.pyc b/news/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..b70e271 Binary files /dev/null and b/news/__pycache__/__init__.cpython-311.pyc differ diff --git a/news/__pycache__/admin.cpython-311.pyc b/news/__pycache__/admin.cpython-311.pyc new file mode 100644 index 0000000..11b1d44 Binary files /dev/null and b/news/__pycache__/admin.cpython-311.pyc differ diff --git a/news/__pycache__/apps.cpython-311.pyc b/news/__pycache__/apps.cpython-311.pyc new file mode 100644 index 0000000..6d05818 Binary files /dev/null and b/news/__pycache__/apps.cpython-311.pyc differ diff --git a/news/__pycache__/models.cpython-311.pyc b/news/__pycache__/models.cpython-311.pyc new file mode 100644 index 0000000..e9876e3 Binary files /dev/null and b/news/__pycache__/models.cpython-311.pyc differ diff --git a/news/__pycache__/urls.cpython-311.pyc b/news/__pycache__/urls.cpython-311.pyc new file mode 100644 index 0000000..e8e5ee4 Binary files /dev/null and b/news/__pycache__/urls.cpython-311.pyc differ diff --git a/news/__pycache__/views.cpython-311.pyc b/news/__pycache__/views.cpython-311.pyc new file mode 100644 index 0000000..64f8030 Binary files /dev/null and b/news/__pycache__/views.cpython-311.pyc differ diff --git a/news/admin.py b/news/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/news/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/news/apps.py b/news/apps.py new file mode 100644 index 0000000..44db8e5 --- /dev/null +++ b/news/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class NewsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'news' diff --git a/news/migrations/__init__.py b/news/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/news/migrations/__pycache__/__init__.cpython-311.pyc b/news/migrations/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..20d5838 Binary files /dev/null and b/news/migrations/__pycache__/__init__.cpython-311.pyc differ diff --git a/news/models.py b/news/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/news/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/news/tests.py b/news/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/news/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/news/urls.py b/news/urls.py new file mode 100644 index 0000000..58524ef --- /dev/null +++ b/news/urls.py @@ -0,0 +1,7 @@ +# news/urls.py +from django.urls import path +from .views import user_team_info + +urlpatterns = [ + path('user_team_info/', user_team_info, name='user_team_info'), +] diff --git a/news/views.py b/news/views.py new file mode 100644 index 0000000..31c0b25 --- /dev/null +++ b/news/views.py @@ -0,0 +1,26 @@ +# news/views.py +from django.shortcuts import get_object_or_404 +from rest_framework.decorators import api_view +from rest_framework.response import Response +from accounts.models import CustomUser +from llo.models import SelectedTeam + +@api_view(['GET']) +def user_team_info(request): + user = request.user # 현재 로그인한 사용자 + if user.is_authenticated: + selected_team = user.selected_team + + if selected_team: + logo_url = request.build_absolute_uri(selected_team.logo.url) + response_data = { + 'logo_url': logo_url, + 'team_name': selected_team.team_name, + 'news_text': f"{selected_team.team_name} News" + } + return Response(response_data) + else: + return Response({'error': 'No team selected for the user.'}, status=400) + else: + return Response({'error': 'User not authenticated.'}, status=401) +