Skip to content

Commit a7ebab6

Browse files
authored
Merge pull request #28 from golony6449/feature/golony/status
각 기능의 Open 여부를 조회하는 status API 추가
2 parents a948eac + 965c87a commit a7ebab6

File tree

11 files changed

+110
-0
lines changed

11 files changed

+110
-0
lines changed

pyconkr/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"constance.backends.database",
4545
# apps
4646
"sponsor",
47+
"status",
4748
# swagger
4849
"drf_spectacular",
4950
]

pyconkr/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323
)
2424

2525
import sponsor.routers
26+
import status.urls
2627

2728
urlpatterns = [
2829
path("api-auth/", include("rest_framework.urls")),
2930
path("summernote/", include("django_summernote.urls")),
3031
path("admin/", admin.site.urls),
3132
path("sponsors/", include(sponsor.routers.get_router().urls)),
33+
path("status/", include(status.urls)),
3234
]
3335

3436
if settings.DEBUG is True:

status/__init__.py

Whitespace-only changes.

status/admin.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from django.contrib import admin
2+
3+
from status.models import Status
4+
5+
6+
class StatusAdmin(admin.ModelAdmin):
7+
list_display = ("name", "open_at", "close_at")
8+
list_editable = (
9+
"open_at",
10+
"close_at",
11+
)
12+
ordering = ("open_at",)
13+
search_fields = ("name",)
14+
15+
16+
admin.site.register(Status, StatusAdmin)

status/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class StatusConfig(AppConfig):
5+
default_auto_field = "django.db.models.BigAutoField"
6+
name = "status"

status/migrations/0001_initial.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Generated by Django 4.1.5 on 2023-02-24 17:43
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
initial = True
9+
10+
dependencies = []
11+
12+
operations = [
13+
migrations.CreateModel(
14+
name="Status",
15+
fields=[
16+
(
17+
"id",
18+
models.BigAutoField(
19+
auto_created=True,
20+
primary_key=True,
21+
serialize=False,
22+
verbose_name="ID",
23+
),
24+
),
25+
("name", models.CharField(max_length=100)),
26+
("open_at", models.DateTimeField()),
27+
("close_at", models.DateTimeField()),
28+
],
29+
),
30+
]

status/migrations/__init__.py

Whitespace-only changes.

status/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.db import models
2+
3+
4+
class Status(models.Model):
5+
name = models.CharField(max_length=100)
6+
open_at = models.DateTimeField()
7+
close_at = models.DateTimeField()

status/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

status/urls.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""pyconkr URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/4.1/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: path('', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.urls import include, path
14+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15+
"""
16+
from django.contrib import admin
17+
from django.urls import include, path
18+
19+
from status.views import StatusView
20+
21+
urlpatterns = [
22+
path("<str:name>", StatusView.as_view()),
23+
]

status/views.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import datetime
2+
3+
from pytz import timezone
4+
from rest_framework.response import Response
5+
from rest_framework.views import APIView
6+
7+
from status.models import Status
8+
9+
10+
class StatusView(APIView):
11+
def get(self, request, name: str):
12+
status = Status.objects.get(name=name)
13+
now = datetime.datetime.now(tz=timezone("Asia/Seoul"))
14+
15+
flag = None
16+
17+
if status.open_at < now < status.close_at:
18+
flag = True
19+
else:
20+
flag = False
21+
22+
return Response({"name": name, "open": flag})

0 commit comments

Comments
 (0)