Skip to content

Commit

Permalink
✏️ Fix : 관리자 api endpoint 수정 및 운영 마감 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JongbeomLee623 committed Oct 6, 2024
1 parent 7a7eaab commit 89c2a96
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 8 deletions.
22 changes: 22 additions & 0 deletions accounts/migrations/0002_remove_user_nickname_user_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 5.1.1 on 2024-10-06 14:07

from django.db import migrations, models


class Migration(migrations.Migration):

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

operations = [
migrations.RemoveField(
model_name='user',
name='nickname',
),
migrations.AddField(
model_name='user',
name='name',
field=models.CharField(blank=True, default='테스트', max_length=4),
),
]
18 changes: 18 additions & 0 deletions accounts/migrations/0003_alter_user_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.1 on 2024-10-06 14:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0002_remove_user_nickname_user_name'),
]

operations = [
migrations.AlterField(
model_name='user',
name='name',
field=models.CharField(blank=True, max_length=4),
),
]
2 changes: 1 addition & 1 deletion accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class User(AbstractUser):
max_length=20,
blank=False
)
name = models.CharField(max_length=4, null=False, blank=True, default = '테스트') #, validators=[validate_name]
name = models.CharField(max_length=4, null=False, blank=True) #, validators=[validate_name]

def __str__(self):
return self.name
2 changes: 1 addition & 1 deletion manager/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
booth_waiting_router.register(r'waitings', BoothWaitingViewSet, basename='waitings')

booth_detail_router = routers.SimpleRouter(trailing_slash=False)
booth_detail_router.register(r'booths', BoothDetailViewSet, basename='booths')
booth_detail_router.register(r'booth', BoothDetailViewSet, basename='booth')

urlpatterns = [
path('', include(faq_router.urls)),
Expand Down
24 changes: 18 additions & 6 deletions manager/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import timezone
from rest_framework import mixins, viewsets, filters
from .models import *
from .serializers import *
Expand Down Expand Up @@ -180,7 +181,7 @@ def action(self, request, *args, **kwargs):


# 부스 관리
class BoothDetailViewSet(CustomResponseMixin, viewsets.GenericViewSet, mixins.RetrieveModelMixin, mixins.UpdateModelMixin):
class BoothDetailViewSet(CustomResponseMixin, viewsets.GenericViewSet, mixins.RetrieveModelMixin, mixins.UpdateModelMixin, mixins.ListModelMixin):
authentication_classes = [JWTAuthentication]
permission_classes = [IsAuthenticated, IsAdminUser]

Expand All @@ -195,7 +196,8 @@ def get_queryset(self):

return Booth.objects.filter(id=booth.id)

def update(self, request, *args, **kwargs):
@action(detail=False, methods=['post'], url_path='status')
def update_status(self, request, *args, **kwargs):
admin = self.request.admin
booth = admin.booth

Expand All @@ -206,10 +208,20 @@ def update(self, request, *args, **kwargs):
serializer = BoothDetailSerializer(booth, data=request.data, partial=True)
serializer.is_valid(raise_exception=True) # raise_exception=True로 유효성 검사를 바로 처리
serializer.save()


# status가 finished로 변경되면 대기 중인 팀들을 모두 삭제 처리
if _status == 'finished':
for waiting in Waiting.objects.filter(booth=booth, waiting_status='waiting'):
waiting.set_canceled()
waiting.save()
# 취소 처리 Sms 전송 구현 예정

# 대기 중인 팀들을 모두 삭제 처리
waiting.delete()

return custom_response(
data=serializer.data,
message="Booth information updated successfully.",
message="Booth status updated successfully.",
code=status.HTTP_200_OK
)
except serializers.ValidationError as e:
Expand All @@ -231,7 +243,7 @@ def update(self, request, *args, **kwargs):
)

# 부스 대기 상태 변경 endpoint 2개로 분리
@action(detail=True, methods=['post'], url_path='pause')
@action(detail=False, methods=['post'], url_path='pause')
def pause(self, request, *args, **kwargs):
"""
부스의 대기 상태를 'paused'로 변경.
Expand Down Expand Up @@ -259,7 +271,7 @@ def pause(self, request, *args, **kwargs):
code=status.HTTP_200_OK
)

@action(detail=True, methods=['post'], url_path='resume')
@action(detail=False, methods=['post'], url_path='resume')
def resume(self, request, *args, **kwargs):
"""
부스의 대기 상태를 'operating'으로 변경.
Expand Down

0 comments on commit 89c2a96

Please sign in to comment.