Skip to content

Commit

Permalink
Merge pull request #18 from breakmagazine/feat/manage
Browse files Browse the repository at this point in the history
Feat/manage
  • Loading branch information
yjoonjang authored Aug 3, 2024
2 parents aea451b + 4af334b commit 77c72be
Show file tree
Hide file tree
Showing 54 changed files with 664 additions and 0 deletions.
Empty file added banners/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions banners/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 banners/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class BannersConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "banners"
47 changes: 47 additions & 0 deletions banners/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Generated by Django 5.0.3 on 2024-08-03 09:18

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="CentralBanner",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("image_url", models.URLField()),
],
),
migrations.CreateModel(
name="MainBanner",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("banner1", models.URLField()),
("banner2", models.URLField()),
("banner3", models.URLField()),
("banner4", models.URLField()),
("banner5", models.URLField()),
],
),
]
18 changes: 18 additions & 0 deletions banners/migrations/0002_rename_image_url_centralbanner_banner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.3 on 2024-08-03 09:27

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("banners", "0001_initial"),
]

operations = [
migrations.RenameField(
model_name="centralbanner",
old_name="image_url",
new_name="banner",
),
]
Empty file added banners/migrations/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions banners/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.db import models

class MainBanner(models.Model):
banner1 = models.URLField(max_length=200)
banner2 = models.URLField(max_length=200)
banner3 = models.URLField(max_length=200)
banner4 = models.URLField(max_length=200)
banner5 = models.URLField(max_length=200)

class CentralBanner(models.Model):
banner = models.URLField(max_length=200)
12 changes: 12 additions & 0 deletions banners/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from rest_framework import serializers
from .models import MainBanner, CentralBanner

class MainBannerSerializer(serializers.ModelSerializer):
class Meta:
model = MainBanner
fields = ['banner1', 'banner2', 'banner3', 'banner4', 'banner5']

class CentralBannerSerializer(serializers.ModelSerializer):
class Meta:
model = CentralBanner
fields = ['banner']
3 changes: 3 additions & 0 deletions banners/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 banners/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.urls import path
from .views import MainBannerView, CentralBannerView

urlpatterns = [
path('main/', MainBannerView.as_view(), name='main-banner'),
path('mid/', CentralBannerView.as_view(), name='central-banner'),
]
70 changes: 70 additions & 0 deletions banners/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from rest_framework import generics, status
from rest_framework.response import Response
from rest_framework.views import APIView
from .models import MainBanner, CentralBanner
from .serializers import MainBannerSerializer, CentralBannerSerializer
from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiExample


class MainBannerView(APIView):
@extend_schema(
summary="메인 배너 반환",
description="메인 배너 5개를 반환합니다.",
)
def get(self, request):
try:
banner = MainBanner.objects.get(pk=1)
except MainBanner.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)

serializer = MainBannerSerializer(banner)
return Response(serializer.data)

@extend_schema(
summary="메인 배너 업데이트",
description="메인 배너 5개의 URL을 업데이트합니다.",
request=MainBannerSerializer
)
def put(self, request):
try:
banner = MainBanner.objects.get(pk=1)
except MainBanner.DoesNotExist:
banner = MainBanner(pk=1)

serializer = MainBannerSerializer(banner, data=request.data, partial=True)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


class CentralBannerView(APIView):
@extend_schema(
summary="중앙 배너 반환",
description="중앙 배너를 반환합니다.",
)
def get(self, request):
try:
banner = CentralBanner.objects.get(pk=1)
except CentralBanner.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)

serializer = CentralBannerSerializer(banner)
return Response(serializer.data)

@extend_schema(
summary="중앙 배너 업데이트",
description="중앙 배너의 URL을 업데이트합니다.",
request=CentralBannerSerializer
)
def put(self, request):
try:
banner = CentralBanner.objects.get(pk=1)
except CentralBanner.DoesNotExist:
banner = CentralBanner(pk=1)

serializer = CentralBannerSerializer(banner, data=request.data, partial=True)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
5 changes: 5 additions & 0 deletions breakserver/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"breakserver",
"accounts",
"articles",
"banners",
"histories",
"symbolics",
"main_articles",
"category_images",
# django-rest-auth
"rest_framework",
"rest_framework_simplejwt",
Expand Down
5 changes: 5 additions & 0 deletions breakserver/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def preprocessing_filter_spec(endpoints):
path("presigned_url/", get_presigned_url, name="get_presigned_url"),
path("accounts/", include("accounts.urls")),
path("articles/", include("articles.urls")),
path("banners/", include("banners.urls")),
path("symbolic/", include("symbolics.urls")),
path("main_articles/", include("main_articles.urls")),
path("category_images/", include("category_images.urls")),
path("histories/", include("histories.urls")),
# swagger 관련
path("api/schema/", SpectacularAPIView.as_view(), name="schema"),
path(
Expand Down
Empty file added category_images/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions category_images/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 category_images/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class CategoryImagesConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "category_images"
43 changes: 43 additions & 0 deletions category_images/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 5.0.3 on 2024-08-03 15:33

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="CategoryImage",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"category",
models.CharField(
choices=[
("ABOUT", "About"),
("FASHION", "Fashion"),
("FEATURE", "Feature"),
("PHOTOGRAPHY", "Photography"),
("FILM", "Film"),
("ART", "Art"),
],
max_length=50,
unique=True,
),
),
("image_url", models.URLField()),
],
),
]
Empty file.
18 changes: 18 additions & 0 deletions category_images/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.db import models


class CategoryImage(models.Model):
CATEGORY_CHOICES = [
('ABOUT', 'About'),
('FASHION', 'Fashion'),
('FEATURE', 'Feature'),
('PHOTOGRAPHY', 'Photography'),
('FILM', 'Film'),
('ART', 'Art'),
]

category = models.CharField(max_length=50, choices=CATEGORY_CHOICES, unique=True)
image_url = models.URLField(max_length=200)

def __str__(self):
return self.category
7 changes: 7 additions & 0 deletions category_images/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from rest_framework import serializers
from .models import CategoryImage

class CategoryImageSerializer(serializers.ModelSerializer):
class Meta:
model = CategoryImage
fields = ['category', 'image_url']
3 changes: 3 additions & 0 deletions category_images/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.
6 changes: 6 additions & 0 deletions category_images/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path
from .views import CategoryImageView

urlpatterns = [
path('category_images/<str:category>/', CategoryImageView.as_view(), name='category-image-detail'),
]
41 changes: 41 additions & 0 deletions category_images/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
from .models import CategoryImage
from .serializers import CategoryImageSerializer
from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiExample


class CategoryImageView(APIView):
@extend_schema(
summary="카테고리 이미지 반환",
description="지정된 카테고리의 이미지를 반환합니다.",
responses=CategoryImageSerializer
)
def get(self, request, category):
try:
category_image = CategoryImage.objects.get(category=category.upper())
except CategoryImage.DoesNotExist:
return Response({"detail": "해당 카테고리의 이미지를 찾을 수 없습니다."}, status=status.HTTP_404_NOT_FOUND)

serializer = CategoryImageSerializer(category_image)
return Response(serializer.data)

@extend_schema(
summary="카테고리 이미지 업데이트",
description="지정된 카테고리의 이미지를 업데이트합니다. -- 진짜 미안한데 category에 같은거 한번씩 적어주라...",
request=CategoryImageSerializer,
responses=CategoryImageSerializer
)
def put(self, request, category):
category = category.upper()
try:
category_image = CategoryImage.objects.get(category=category)
except CategoryImage.DoesNotExist:
category_image = CategoryImage(category=category)

serializer = CategoryImageSerializer(category_image, data=request.data, partial=True)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Empty file added histories/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions histories/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 histories/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class HistoriesConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "histories"
31 changes: 31 additions & 0 deletions histories/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 5.0.3 on 2024-08-03 15:56

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="History",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("image_url", models.URLField()),
("published_at", models.DateField()),
("publication_number", models.CharField(max_length=20)),
("title", models.CharField(max_length=100)),
],
),
]
Loading

0 comments on commit 77c72be

Please sign in to comment.