Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] #18 부스 디테일 API 구현 #28

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions booth/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin
from .models import Booth
from .models import Booth, BoothDetail
# Register your models here.

admin.site.register(Booth)
admin.site.register(Booth)
admin.site.register(BoothDetail)
29 changes: 29 additions & 0 deletions booth/migrations/0002_boothdetail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 5.1.1 on 2024-09-26 18:08

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('booth', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='BoothDetail',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('detail_description', models.TextField(blank=True)),
('entrace_fee', models.IntegerField(default=0)),
('menus', models.TextField(blank=True)),
('tabling_link', models.TextField(blank=True)),
('insta_id', models.CharField(blank=True, max_length=50)),
('insta_link', models.TextField(blank=True)),
('image', models.ImageField(blank=True, null=True, upload_to='booth/')),
('like_count', models.IntegerField(default=0)),
('booth', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='details', to='booth.booth')),
],
),
]
18 changes: 17 additions & 1 deletion booth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,20 @@ class Booth(models.Model):
end_time = models.TimeField()

def __str__(self):
return self.name
return self.name

class BoothDetail(models.Model):
id = models.AutoField(primary_key=True) # 부스 디테일의 고유 id
booth = models.OneToOneField(Booth, on_delete=models.CASCADE, related_name='details') # 부스 id를 왜래키로 참조
detail_description = models.TextField(blank=True) # 부스 상세 설명
entrace_fee = models.IntegerField(default=0) # 입장료
menus = models.TextField(blank=True) # 메뉴 정보
tabling_link = models.TextField(blank=True) # 테이블링 서비스로 이동하는 링크
insta_id = models.CharField(max_length=50, blank=True) # 인스타그램 아이디
insta_link = models.TextField(blank=True) # 인스타그램 링크
image = models.ImageField(upload_to="booth/", blank=True, null=True) # 부스 이미지
like_count = models.IntegerField(default=0) # 부스 좋아요

def save(self, *args, **kwargs):
self.like_count = self.booth.like_count
super().save(*args, **kwargs)
7 changes: 7 additions & 0 deletions booth/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ class Meta:
class BoothSerializer(serializers.ModelSerializer):
class Meta:
model = Booth
fields = '__all__'

class BoothDetailSerializer(serializers.ModelSerializer):
booth = serializers.PrimaryKeyRelatedField(queryset=Booth.objects.all())

class Meta:
model = BoothDetail
fields = '__all__'
10 changes: 7 additions & 3 deletions booth/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from rest_framework.routers import SimpleRouter
from .views import BoothViewSet
from .views import BoothViewSet, BoothDetailViewSet, BoothDetailListViewSet

app_name = 'booth'

router = SimpleRouter(trailing_slash=False)
router.register(r'booth', BoothViewSet, basename='booth')

urlpatterns = [
path('api/v1/', include(router.urls)), # 'api/v1/' 경로로 ViewSet 엔드포인트 등록
]
path('v1/', include(router.urls)), # 'api/v1/' 경로로 ViewSet 엔드포인트 등록
path('v1/booth/detail/', BoothDetailListViewSet.as_view(), name='booth-detail-list'),
path('v1/booth/detail/<int:id>/', BoothDetailViewSet.as_view(), name='booth_detail'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
16 changes: 10 additions & 6 deletions booth/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.shortcuts import render
from rest_framework import viewsets
from rest_framework import viewsets, mixins, generics
from rest_framework.response import Response
from rest_framework import status
from .models import Booth
from .serializers import BoothSerializer
from .models import Booth, BoothDetail
from .serializers import BoothSerializer, BoothDetailSerializer
# Create your views here.
from django_filters.rest_framework import DjangoFilterBackend
import django_filters
Expand Down Expand Up @@ -53,7 +53,11 @@ def get_queryset(self):

return queryset

class BoothDetailViewSet(generics.RetrieveUpdateAPIView):
queryset = BoothDetail.objects.all()
serializer_class = BoothDetailSerializer
lookup_field = 'id'




class BoothDetailListViewSet(generics.ListCreateAPIView):
queryset = BoothDetail.objects.all()
serializer_class = BoothDetailSerializer
4 changes: 3 additions & 1 deletion project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
BASE_DIR = Path(__file__).resolve().parent.parent

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

env = environ.Env(DEBUG=(bool, False))
environ.Env.read_env(os.path.join(BASE_DIR, '.env'))
Expand Down Expand Up @@ -48,7 +50,7 @@
'rest_framework',
'corsheaders',
'timetable',
'booth',
'booth', # 부스 테이블 앱
]

MIDDLEWARE = [
Expand Down
2 changes: 1 addition & 1 deletion project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
urlpatterns = [
path('admin/', admin.site.urls),
path('api/v1/', include('timetable.urls')),
path('', include('booth.urls')), # booth 앱의 URL을 포함
path('api/', include('booth.urls')), # booth 앱의 URL을 포함
]
Loading