Skip to content

Commit

Permalink
#63 Feat: Admin 서비스에 잘못된 요청에 대한 커스텀 에러 코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
fnzksxl committed Jul 16, 2024
1 parent 74f345f commit 95380d0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
24 changes: 23 additions & 1 deletion wtnt/admin/team/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
from core.permissions import IsAdminUser
from django.contrib.auth import get_user_model

import core.exception.request as exception
from core.permissions import IsAdminUser
from .service import AdminTeamService

User = get_user_model()
Expand All @@ -19,12 +20,26 @@ def get(self, request):
return Response(data, status=status.HTTP_200_OK)

def patch(self, request, *args, **kwargs):
required_field = ["ids"]
if len(request.data) != len(required_field):
raise exception.InvalidRequestError()
for field in required_field:
if field not in request.data:
raise exception.InvalidRequestError()

admin_service = AdminTeamService(request)
data = admin_service.approve_teams()

return Response(data, status=status.HTTP_202_ACCEPTED)

def delete(self, request, *args, **kwargs):
required_field = ["ids"]
if len(request.data) != len(required_field):
raise exception.InvalidRequestError()
for field in required_field:
if field not in request.data:
raise exception.InvalidRequestError()

admin_service = AdminTeamService(request)
data = admin_service.reject_teams(status=False)

Expand All @@ -39,6 +54,13 @@ def get(self, request):
return admin_service.get_approved_teams()

def delete(self, request, *args, **kwargs):
required_field = ["ids"]
if len(request.data) != len(required_field):
raise exception.InvalidRequestError()
for field in required_field:
if field not in request.data:
raise exception.InvalidRequestError()

admin_service = AdminTeamService(request)
data = admin_service.reject_teams(status=True)

Expand Down
24 changes: 23 additions & 1 deletion wtnt/admin/user/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
from core.permissions import IsAdminUser
from django.contrib.auth import get_user_model

import core.exception.request as exception
from core.permissions import IsAdminUser
from .service import AdminUserService

User = get_user_model()
Expand All @@ -19,12 +20,26 @@ def get(self, request):
return Response(data, status=status.HTTP_200_OK)

def patch(self, request, *args, **kwargs):
required_field = ["ids"]
if len(request.data) != len(required_field):
raise exception.InvalidRequestError()
for field in required_field:
if field not in request.data:
raise exception.InvalidRequestError()

admin_service = AdminUserService(request)
data = admin_service.approve_users()

return Response(data, status=status.HTTP_202_ACCEPTED)

def delete(self, request, *args, **kwargs):
required_field = ["ids"]
if len(request.data) != len(required_field):
raise exception.InvalidRequestError()
for field in required_field:
if field not in request.data:
raise exception.InvalidRequestError()

admin_service = AdminUserService(request)
data = admin_service.reject_users(status=False)

Expand All @@ -39,6 +54,13 @@ def get(self, request):
return admin_service.get_approved_users()

def delete(self, request, *args, **kwargs):
required_field = ["ids"]
if len(request.data) != len(required_field):
raise exception.InvalidRequestError()
for field in required_field:
if field not in request.data:
raise exception.InvalidRequestError()

admin_service = AdminUserService(request)
data = admin_service.reject_users(status=True)

Expand Down

0 comments on commit 95380d0

Please sign in to comment.