Skip to content

Commit

Permalink
stadium app add
Browse files Browse the repository at this point in the history
  • Loading branch information
Hwang-Jaeryeong committed Jan 23, 2024
1 parent 0f36647 commit 724dd50
Show file tree
Hide file tree
Showing 25 changed files with 125 additions and 0 deletions.
Binary file modified madcamp_week4_BE/__pycache__/settings.cpython-311.pyc
Binary file not shown.
Binary file modified madcamp_week4_BE/__pycache__/urls.cpython-311.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions madcamp_week4_BE/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
'llo',
'news',
'video',
'stadium',
]

# Authentication backends
Expand Down
1 change: 1 addition & 0 deletions madcamp_week4_BE/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
path('llo/', include('llo.urls')),
path('news/', include('news.urls')),
path('video/', include('video.urls')),
path('stadium/', include('stadium.urls')),
]
Binary file added media/stadium_images/anfield.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added stadium/__init__.py
Empty file.
Binary file added stadium/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file added stadium/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file added stadium/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file added stadium/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file added stadium/__pycache__/serializers.cpython-311.pyc
Binary file not shown.
Binary file added stadium/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file added stadium/__pycache__/views.cpython-311.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions stadium/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions stadium/apps.py
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'
23 changes: 23 additions & 0 deletions stadium/migrations/0001_initial.py
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 added stadium/migrations/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions stadium/models.py
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
7 changes: 7 additions & 0 deletions stadium/serializers.py
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')
3 changes: 3 additions & 0 deletions stadium/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
7 changes: 7 additions & 0 deletions stadium/urls.py
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'),
]
64 changes: 64 additions & 0 deletions stadium/views.py
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 modified video/__pycache__/urls.cpython-311.pyc
Binary file not shown.

0 comments on commit 724dd50

Please sign in to comment.