-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from breakmagazine/feat/manage
Feat/manage
- Loading branch information
Showing
54 changed files
with
664 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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 BannersConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "banners" |
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,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
18
banners/migrations/0002_rename_image_url_centralbanner_banner.py
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,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.
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,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) |
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,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'] |
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 MainBannerView, CentralBannerView | ||
|
||
urlpatterns = [ | ||
path('main/', MainBannerView.as_view(), name='main-banner'), | ||
path('mid/', CentralBannerView.as_view(), name='central-banner'), | ||
] |
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,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) |
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
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
Empty file.
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 CategoryImagesConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "category_images" |
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,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.
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,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 |
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 CategoryImage | ||
|
||
class CategoryImageSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = CategoryImage | ||
fields = ['category', 'image_url'] |
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,6 @@ | ||
from django.urls import path | ||
from .views import CategoryImageView | ||
|
||
urlpatterns = [ | ||
path('category_images/<str:category>/', CategoryImageView.as_view(), name='category-image-detail'), | ||
] |
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,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.
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 HistoriesConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "histories" |
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,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)), | ||
], | ||
), | ||
] |
Oops, something went wrong.