Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…stival_back into ceh-booth
  • Loading branch information
chaeunho1227 committed May 22, 2024
2 parents 07ce677 + f2bfa59 commit 157d7a4
Show file tree
Hide file tree
Showing 16 changed files with 419 additions and 16 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/django_cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ jobs:
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}

build-args: |
SECRET_KEY=${{ secrets.SECRET_KEY }}
DEBUG_VALUE=${{ secrets.DEBUG_VALUE }}
DJANGO_DEPLOY=${{ secrets.DJANGO_DEPLOY }}
# closed에 대한 server deploy
CD:
if: github.event.pull_request.merged == true
Expand Down
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ FROM python:3.11

WORKDIR /app

# yml 빌드 매개 변수
ARG SECRET_KEY
ARG DEBUG_VALUE
ARG DJANGO_DEPLOY

# 환경변수 저장
ENV SECRET_KEY=$SECRET_KEY
ENV DEBUG=$DEBUG_VALUE
ENV DJANGO_DEPLOY=$DJANGO_DEPLOY

COPY ./requirements.txt requirements.txt

RUN pip install --upgrade pip
Expand Down
4 changes: 3 additions & 1 deletion booth/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib import admin
from .models import Booth, BoothOperationTime, BoothLike, BoothImage
from .models import Booth, BoothOperationTime, BoothLike, BoothImage, Comment

class BoothOperationTimeInline(admin.TabularInline):
model = BoothOperationTime
Expand All @@ -23,3 +23,5 @@ def show_operation_times(self, obj):
admin.site.register(Booth, BoothAdmin)
admin.site.register(BoothLike)
admin.site.register(BoothImage)
admin.site.register(Comment)

25 changes: 25 additions & 0 deletions booth/migrations/0003_comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.0.4 on 2024-05-22 21:57

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


class Migration(migrations.Migration):

dependencies = [
('booth', '0002_rename_longtude_booth_longitude_remove_booth_end_at_and_more'),
]

operations = [
migrations.CreateModel(
name='Comment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('writer', models.CharField(max_length=20)),
('content', models.TextField()),
('password', models.CharField(max_length=10)),
('created_at', models.DateTimeField(auto_now_add=True)),
('booth', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='booth.booth')),
],
),
]
14 changes: 12 additions & 2 deletions booth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,15 @@ def __str__(self):
return f'{self.booth}/{self.key}'

class BoothImage(BaseImage):
booth = models.ForeignKey(Booth, on_delete=models.CASCADE, related_name='boothimages')
image = models.ImageField(upload_to=image_upload_path, blank=True, null=True)
booth=models.ForeignKey(Booth, on_delete=models.CASCADE, related_name='boothimages')
image = models.ImageField(upload_to=image_upload_path, blank=True, null=True)

class Comment(models.Model):
booth=models.ForeignKey(Booth, on_delete=models.CASCADE, related_name='comments')
writer=models.CharField(max_length=20)
content=models.TextField()
password=models.CharField(max_length=10, null=False, blank=False)
created_at=models.DateTimeField(auto_now_add=True)

def __str__(self):
return f'{self.booth}/{self.content[:20]}'
27 changes: 22 additions & 5 deletions booth/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from datetime import datetime
from rest_framework import serializers
from.models import Booth, BoothImage, BoothLike

from.models import Booth, BoothImage, BoothLike, Comment
from datetime import datetime, date
from django.core.exceptions import ObjectDoesNotExist


def trans_datetime_to_str(self, instance):
operation_times = instance.operation_times.all()
if not operation_times:
Expand Down Expand Up @@ -145,8 +148,22 @@ class LikeSerializer(serializers.ModelSerializer):
class Meta:
model = BoothLike
fields = [
'id',
'booth',
'key'
]
'id',
'booth',
'key'
]

class CommentSerializer(serializers.ModelSerializer):
writer = serializers.CharField()
password = serializers.CharField(write_only=True)
content = serializers.CharField()

def create(self, validated_data):
booth = Booth.objects.get(id=self.context.get("view").kwargs.get("id"))
validated_data["booth"] = booth
return super().create(validated_data)

class Meta:
model = Comment
fields = ['id', 'writer', 'password','content', 'created_at']

6 changes: 5 additions & 1 deletion booth/urls.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from django.urls import path, include
from rest_framework import routers

from .views import BoothViewSet
from .views import BoothViewSet, CommentViewSet

app_name = 'booth'

booth_router = routers.SimpleRouter(trailing_slash=False)
booth_router.register('booth', BoothViewSet, basename='booth')

comment_router = routers.SimpleRouter(trailing_slash=False)
comment_router.register('comment', CommentViewSet, basename='comment')

urlpatterns = [
path('', include(booth_router.urls)),
path('booth/<int:id>/', include(comment_router.urls)),
path('', include(comment_router.urls)),
]
27 changes: 23 additions & 4 deletions booth/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import secrets
import secrets, requests

from decouple import config

Expand All @@ -10,9 +10,10 @@
from rest_framework.decorators import action
from rest_framework.response import Response

from .models import Booth, BoothLike, TYPE_CHOICES
from .models import Booth, BoothLike, TYPE_CHOICES, Comment

from .serializers import BoothListSerializer, BoothSerializer, BoothLocationSerializer, LikeSerializer, CommentSerializer

from .serializers import BoothListSerializer, BoothSerializer, BoothLocationSerializer, LikeSerializer
# Create your views here.

DEPLOY = config('DJANGO_DEPLOY', default=False, cast=bool)
Expand Down Expand Up @@ -116,4 +117,22 @@ def top3(self, request):
queryset = self.filter_queryset(self.get_queryset())
top3 = queryset.order_by('-like_cnt')[:3]
top3_serializer = BoothListSerializer(top3, many=True, context = {'request': request})
return Response( top3_serializer.data )
return Response( top3_serializer.data )

class CommentViewSet(mixins.ListModelMixin, mixins.CreateModelMixin, mixins.DestroyModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):

serializer_class = CommentSerializer

def get_queryset(self, *args, **kwargs):
queryset = Comment.objects.filter(
booth__id=self.kwargs.get("id")
)
return queryset

def destroy(self, request, *args, **kwargs):
instance = self.get_object()
password = request.data.get('password')
if password == instance.password:
self.perform_destroy(instance)
return Response(status=status.HTTP_204_NO_CONTENT)
return Response(status=400)
1 change: 1 addition & 0 deletions festival/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
path('api/v1/', include('booth.urls')),
path('api/v1/', include('notice.urls')),
path('api/v1/', include('promo.urls')),
path('api/v1/', include('timetable.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
9 changes: 8 additions & 1 deletion notice/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@ class Meta:
# 공지 리스트
class NotificationListSerializer(serializers.ModelSerializer):
thumbnail = serializers.SerializerMethodField()
short_description = serializers.SerializerMethodField()

def get_thumbnail(self, instance):
request = self.context.get('request')
notification_image = instance.notificationimage_set.first()
if notification_image:
return request.build_absolute_uri(notification_image.image.url)
return None

def get_short_description(self, instance):
if len(instance.description) <= 23:
return instance.description
else:
return instance.description[:23] + "..."

class Meta:
model = Notification
fields = ['id', 'title', 'description', 'created_at', 'thumbnail']
fields = ['id', 'title', 'short_description','description', 'created_at', 'thumbnail']

# 공지 디테일
class NotificationDetailSerializer(serializers.ModelSerializer):
Expand Down
8 changes: 7 additions & 1 deletion timetable/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
from django.contrib import admin

from .models import *
# Register your models here.

admin.site.register(Performance)
admin.site.register(Artist)
admin.site.register(Music)
admin.site.register(ArtistImage)
admin.site.register(MusicImage)
66 changes: 66 additions & 0 deletions timetable/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Generated by Django 5.0.4 on 2024-05-22 03:14

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


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Artist',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('date', models.DateField()),
],
),
migrations.CreateModel(
name='Performance',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('operator', models.CharField(max_length=100)),
('location', models.CharField(max_length=100)),
('start_at', models.DateTimeField()),
('end_at', models.DateTimeField()),
('date', models.DateField()),
],
),
migrations.CreateModel(
name='ArtistImage',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('image', models.ImageField(blank=True, null=True, upload_to=core.models.image_upload_path)),
('artist', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='timetable.artist')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Music',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('ytb_url', models.URLField(blank=True)),
('artist', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='timetable.artist')),
],
),
migrations.CreateModel(
name='MusicImage',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('image', models.ImageField(blank=True, null=True, upload_to=core.models.image_upload_path)),
('music', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='timetable.music')),
],
options={
'abstract': False,
},
),
]
31 changes: 31 additions & 0 deletions timetable/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
from django.db import models
from core.models import BaseImage

# Create your models here.
class Performance(models.Model):
operator = models.CharField(max_length=100)
location = models.CharField(max_length=100)
start_at = models.DateTimeField()
end_at = models.DateTimeField()
date = models.DateField()

def __str__(self):
return self.operator

class Artist(models.Model):
name = models.CharField(max_length=100)
date = models.DateField()

def __str__(self):
return self.name

class Music(models.Model):
title = models.CharField(max_length=100)
artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
ytb_url = models.URLField(max_length=200, blank=True)

def __str__(self):
return self.title

class ArtistImage(BaseImage):
artist = models.ForeignKey(Artist, on_delete=models.CASCADE)

class MusicImage(BaseImage):
music = models.OneToOneField(Music, on_delete=models.CASCADE)
Loading

0 comments on commit 157d7a4

Please sign in to comment.