-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f36647
commit 724dd50
Showing
25 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
'llo', | ||
'news', | ||
'video', | ||
'stadium', | ||
] | ||
|
||
# Authentication backends | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class StadiumConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'stadium' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 3.2.16 on 2024-01-23 18:49 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Stadium', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('team_name', models.CharField(max_length=255)), | ||
('stadium', models.CharField(max_length=255)), | ||
('stadium_image', models.ImageField(blank=True, null=True, upload_to='stadium_images/')), | ||
], | ||
), | ||
] |
Empty file.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.db import models | ||
from accounts.models import CustomUser | ||
|
||
class Stadium(models.Model): | ||
team_name = models.CharField(max_length=255) | ||
stadium = models.CharField(max_length=255) | ||
stadium_image = models.ImageField(upload_to='stadium_images/', null=True, blank=True) | ||
|
||
def __str__(self): | ||
return self.team_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from rest_framework import serializers | ||
from .models import Stadium | ||
|
||
class StadiumSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Stadium | ||
fields = ('team_name', 'stadium', 'stadium_image') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.urls import path | ||
from .views import StadiumAPIView, StadiumUploadAPIView | ||
|
||
urlpatterns = [ | ||
path('', StadiumAPIView.as_view(), name='get-stadium'), | ||
path('upload/', StadiumUploadAPIView.as_view(), name='upload-stadium'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from rest_framework.views import APIView | ||
from rest_framework.response import Response | ||
from rest_framework import status | ||
from .models import Stadium | ||
from .serializers import StadiumSerializer | ||
|
||
from rest_framework.views import APIView | ||
from rest_framework.response import Response | ||
from rest_framework import status | ||
from rest_framework.permissions import IsAuthenticated | ||
from django.http import Http404 | ||
|
||
from .models import Stadium | ||
from .serializers import StadiumSerializer | ||
|
||
class StadiumAPIView(APIView): | ||
permission_classes = [IsAuthenticated] | ||
|
||
def get(self, request): | ||
user = request.user | ||
|
||
if user.selected_team: | ||
selected_team_id = user.selected_team.id | ||
stadium_data = Stadium.objects.filter(id=selected_team_id).values('team_name', 'stadium', 'stadium_image').first() | ||
|
||
if stadium_data: | ||
return Response(stadium_data, status=status.HTTP_200_OK) | ||
|
||
return Response({'detail': 'No selected team.'}, status=status.HTTP_403_FORBIDDEN) | ||
|
||
def post(self, request): | ||
user = request.user | ||
|
||
if user.selected_team: | ||
team_name = request.data.get('team_name') | ||
stadium_name = request.data.get('stadium') | ||
stadium_image = request.data.get('stadium_image') | ||
|
||
# 이미지 파일 저장 | ||
stadium = Stadium.objects.create(team_name=team_name, stadium=stadium_name, stadium_image=stadium_image) | ||
|
||
return Response({'detail': f'Stadium information for {team_name} added successfully.'}, status=status.HTTP_201_CREATED) | ||
|
||
return Response({'detail': 'No selected team.'}, status=status.HTTP_403_FORBIDDEN) | ||
|
||
class StadiumUploadAPIView(APIView): | ||
permission_classes = [IsAuthenticated] | ||
|
||
def post(self, request): | ||
team_name = request.data.get('team_name') | ||
stadium_name = request.data.get('stadium') | ||
stadium_image = request.data.get('stadium_image') | ||
|
||
try: | ||
# 이미지 파일 저장 | ||
stadium = Stadium.objects.get(team_name=team_name) | ||
stadium.stadium_image = stadium_image | ||
stadium.save() | ||
except Stadium.DoesNotExist: | ||
raise Http404(f"Stadium matching query does not exist for team '{team_name}'.") | ||
|
||
return Response({'detail': f'Stadium information for {team_name} updated successfully.'}, status=status.HTTP_200_OK) | ||
|
||
|
Binary file not shown.