Skip to content

Commit

Permalink
Merge pull request #64 from whatTeamNaeTeam/feat-custom_error_code_2
Browse files Browse the repository at this point in the history
Feat custom error code 2
  • Loading branch information
fnzksxl authored Jul 16, 2024
2 parents 74efb48 + 95380d0 commit d45147f
Show file tree
Hide file tree
Showing 25 changed files with 274 additions and 144 deletions.
13 changes: 7 additions & 6 deletions wtnt/admin/team/service.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.contrib.auth import get_user_model

import core.exception.notfound as notfound_exception
import core.exception.team as team_exception
from admin.serializers import ApproveTeamSerializer
from core.exceptions import NotFoundError, KeywordNotMatchError
from core.pagenations import ListPagenationSize10
from core.service import BaseService
from core.utils.s3 import S3Utils
Expand All @@ -18,15 +19,15 @@ def get_not_approved_team(self):
return serializer.data

except Team.DoesNotExist:
raise NotFoundError()
raise notfound_exception.TeamNotFoundError()

def approve_teams(self):
team_ids = [int(id) for id in self.request.data.get("ids").split(",")]
cnt = Team.objects.filter(id__in=team_ids).update(is_approved=True)
if cnt:
return {"detail": "Success to update teams"}
else:
raise NotFoundError()
raise notfound_exception.TeamNotFoundError()

def reject_teams(self, status):
team_ids = [int(id) for id in self.request.data.get("ids").split(",")]
Expand All @@ -38,7 +39,7 @@ def reject_teams(self, status):
if cnt:
return {"detail": "Success to reject teams"}
else:
raise NotFoundError()
raise notfound_exception.TeamNotFoundError()

def get_approved_teams(self):
queryset = Team.objects.filter(is_approved=True).order_by("id")
Expand All @@ -59,10 +60,10 @@ def serach_teams(self):
leader_ids = User.objects.search_by_name(name=keyword).values_list("id", flat=True)
queryset = Team.objects.search_by_leader_ids(leader_ids=leader_ids)
else:
raise KeywordNotMatchError
raise team_exception.TeamKeywordNotMatchError()

if not queryset:
raise NotFoundError()
raise notfound_exception.TeamNotFoundError()

paginated = self.paginate_queryset(queryset, self.request, view=self)
serializer = ApproveTeamSerializer(paginated, many=True)
Expand Down
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
18 changes: 9 additions & 9 deletions wtnt/admin/user/service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib.auth import get_user_model

from core.exceptions import NotFoundError, KeywordNotMatchError
import core.exception.notfound as notfound_exception
import core.exception.team as team_exception
from core.pagenations import ListPagenationSize10
from core.service import BaseService
from core.utils.s3 import S3Utils
Expand All @@ -11,21 +12,20 @@

class AdminUserService(BaseService, ListPagenationSize10):
def get_not_approved_users(self):
try:
queryset = User.objects.filter(is_approved=False, is_superuser=False)
queryset = User.objects.filter(is_approved=False, is_superuser=False)
if queryset:
serializer = ApproveUserSerializer(queryset, many=True)
return serializer.data

except User.DoesNotExist:
raise NotFoundError()
raise notfound_exception.UserNotFoundError()

def approve_users(self):
user_ids = [int(id) for id in self.request.data.get("ids").split(",")]
cnt = User.objects.filter(id__in=user_ids).update(is_approved=True)
if cnt:
return {"detail": "Success to update users"}
else:
raise NotFoundError()
raise notfound_exception.UserNotFoundError()

def reject_users(self, status):
user_ids = [int(id) for id in self.request.data.get("ids").split(",")]
Expand All @@ -36,7 +36,7 @@ def reject_users(self, status):
if cnt:
return {"detail": "Success to reject users"}
else:
raise NotFoundError()
raise notfound_exception.UserNotFoundError()

def get_approved_users(self):
queryset = User.objects.filter(is_approved=True, is_superuser=False).order_by("student_num")
Expand All @@ -56,10 +56,10 @@ def search_users(self):
elif search_filter == "position":
queryset = User.objects.search_by_position(position=keyword)
else:
raise KeywordNotMatchError()
raise team_exception.TeamKeywordNotMatchError()

if not queryset:
raise NotFoundError()
raise notfound_exception.UserNotFoundError()

paginated = self.paginate_queryset(queryset, self.request, view=self)
serializer = ApproveUserSerializer(paginated, many=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
5 changes: 5 additions & 0 deletions wtnt/core/exception/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ class EmailTimeoutError(APIException):
class EmailCodeNotMatchAfterAuthError(APIException):
status_code = 400
default_detail = {"message": "인증 시 사용된 코드(이메일)와 Body의 코드(이메일)가 일치하지 않습니다.", "code": "0132"}


class EmailCeleryError(APIException):
status_code = 400
default_detail = {"message": "이메일 발송 도중 문제가 발생했습니다.", "code": "0133"}
5 changes: 5 additions & 0 deletions wtnt/core/exception/notfound.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ class TechNotFoundError(APIException):
class ApplyNotFoundError(APIException):
status_code = 404
default_detail = {"message": "해당하는 지원이 존재하지 않습니다.", "code": "0003"}


class TeamUserNotFoundError(APIException):
status_code = 404
default_detail = {"message": "해당하는 팀원이 존재하지 않습니다.", "code": "0004"}
6 changes: 6 additions & 0 deletions wtnt/core/exception/request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from rest_framework.exceptions import APIException


class InvalidRequestError(APIException):
status_code = 400
default_detail = {"message": "요청의 형식이 잘못되었습니다.", "code": "0010"}
5 changes: 5 additions & 0 deletions wtnt/core/exception/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ class TeamNameLengthError(APIException):
default_detail = {"message": "팀 이름이 공백이거나 길이가 맞지 않습니다.", "code": "0200"}


class TeamNameDuplicateError(APIException):
status_code = 400
default_detail = {"message": "팀 이름이 중복됩니다.", "code": "0201"}


class TeamGenreNotValidError(APIException):
status_code = 400
default_detail = {"message": "프로젝트의 유형이 올바르지 않습니다.", "code": "0210"}
Expand Down
101 changes: 0 additions & 101 deletions wtnt/core/exceptions.py

This file was deleted.

Loading

0 comments on commit d45147f

Please sign in to comment.