Skip to content

Commit

Permalink
Merge pull request #65 from whatTeamNaeTeam/develop-0.0.4
Browse files Browse the repository at this point in the history
Develop 0.0.4 into Main
  • Loading branch information
fnzksxl authored Jul 23, 2024
2 parents 5ceea33 + 9e67173 commit 648e6ca
Show file tree
Hide file tree
Showing 56 changed files with 1,064 additions and 270 deletions.
Binary file modified requirements.txt
Binary file not shown.
2 changes: 1 addition & 1 deletion wtnt/admin/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ class ApproveTeamSerializer(serializers.ModelSerializer):

class Meta:
model = Team
fields = ["id", "name", "created_at", "is_approved", "genre"]
fields = ["id", "title", "created_at", "is_approved", "genre"]
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
6 changes: 3 additions & 3 deletions wtnt/admin/team/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
)

urlpatterns = [
path("manage", TeamManageView.as_view()),
path("list", TeamDeleteView.as_view()),
path("search", TeamSearchView.as_view()),
path("manage", TeamManageView.as_view(), name="admin-team-manage"),
path("list", TeamDeleteView.as_view(), name="admin-team-list"),
path("search", TeamSearchView.as_view(), name="admin-team-search"),
]
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 rest_framework.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
3 changes: 0 additions & 3 deletions wtnt/admin/tests.py

This file was deleted.

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
6 changes: 3 additions & 3 deletions wtnt/admin/user/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
)

urlpatterns = [
path("manage", UserManageView.as_view()),
path("list", UserDeleteView.as_view()),
path("search", UserSearchView.as_view()),
path("manage", UserManageView.as_view(), name="admin-user-manage"),
path("list", UserDeleteView.as_view(), name="admin-user-list"),
path("search", UserSearchView.as_view(), name="admin-user-search"),
]
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 rest_framework.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
60 changes: 60 additions & 0 deletions wtnt/core/authenticator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from typing import Optional, Set, TypeVar

from django.contrib.auth.models import AbstractBaseUser
from rest_framework import HTTP_HEADER_ENCODING
from rest_framework_simplejwt.authentication import JWTAuthentication
from rest_framework_simplejwt.tokens import Token
import core.exception.token as exception
from rest_framework_simplejwt.settings import api_settings
from rest_framework_simplejwt.exceptions import TokenError
from rest_framework_simplejwt.models import TokenUser

AUTH_HEADER_TYPES = api_settings.AUTH_HEADER_TYPES

AUTH_HEADER_TYPE_BYTES: Set[bytes] = {h.encode(HTTP_HEADER_ENCODING) for h in AUTH_HEADER_TYPES}

AuthUser = TypeVar("AuthUser", AbstractBaseUser, TokenUser)


class CustomJWTAuthentication(JWTAuthentication):
def get_raw_token(self, header: bytes) -> Optional[bytes]:
parts = header.split()

if len(parts) == 0:
# Empty AUTHORIZATION header sent
raise exception.NoTokenInAuthorizationHeaderError()

if parts[0] not in AUTH_HEADER_TYPE_BYTES:
# Assume the header does not contain a JSON web token
raise exception.NoTokenInAuthorizationHeaderError()

if len(parts) != 2:
raise exception.AuthenticationHeaderSpaceError()

return parts[1]

def get_validated_token(self, raw_token: bytes) -> Token:
for AuthToken in api_settings.AUTH_TOKEN_CLASSES:
try:
return AuthToken(raw_token)
except TokenError:
raise exception.AccessTokenExpiredError()

def get_user(self, validated_token: Token) -> AuthUser:
"""
Attempts to find and return a user using the given validated token.
"""
try:
user_id = validated_token[api_settings.USER_ID_CLAIM]
except KeyError:
raise exception.TokenWithNoUserDataError()

try:
user = self.user_model.objects.get(**{api_settings.USER_ID_FIELD: user_id})
except self.user_model.DoesNotExist:
raise exception.UserNotFoundInTokenDataError()

if not user.is_active:
raise exception.UserInactiveInTokenDataError()

return user
11 changes: 11 additions & 0 deletions wtnt/core/exception/apply.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from rest_framework.exceptions import APIException


class ClosedApplyError(APIException):
status_code = 400
default_detail = {"message": "마감된 지원입니다.", "code": "0500"}


class DuplicatedApplyError(APIException):
status_code = 400
default_detail = {"message": "중복된 지원입니다.", "code": "0501"}
51 changes: 51 additions & 0 deletions wtnt/core/exception/login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from rest_framework.exceptions import APIException


class UserNameNotValidError(APIException):
status_code = 400
default_detail = {"message": "이름에 공백, 특수문자 또는 숫자가 포함되어 있습니다.", "code": "0100"}


class UserNameTooLongError(APIException):
status_code = 400
default_detail = {"message": "이름이 너무 짧거나 깁니다.", "code": "0101"}


class StudentNumNotValidError(APIException):
status_code = 400
default_detail = {"message": "학번에 공백,특수문자 또는 문자가 포함되어 있습니다.", "code": "0110"}


class StudentNumTooLongError(APIException):
status_code = 400
default_detail = {"message": "학번이 너무 짧거나 깁니다.", "code": "0111"}


class StudentNumDuplicatedError(APIException):
status_code = 400
default_detail = {"message": "중복된 학번입니다.", "code": "0112"}


class PositionNotValidError(APIException):
status_code = 400
default_detail = {"message": "포지션 기입이 올바르지 않습니다.", "code": "0120"}


class EmailCodeNotMatchError(APIException):
status_code = 400
default_detail = {"message": "이메일 인증 코드 또는 첨부된 이메일이 일치하지 않습니다.", "code": "0130"}


class EmailTimeoutError(APIException):
status_code = 400
default_detail = {"message": "이메일 인증 시간이 초과되었습니다.", "code": "0131"}


class EmailCodeNotMatchAfterAuthError(APIException):
status_code = 400
default_detail = {"message": "인증 시 사용된 코드(이메일)와 Body의 코드(이메일)가 일치하지 않습니다.", "code": "0132"}


class EmailCeleryError(APIException):
status_code = 400
default_detail = {"message": "이메일 발송 도중 문제가 발생했습니다.", "code": "0133"}
26 changes: 26 additions & 0 deletions wtnt/core/exception/notfound.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from rest_framework.exceptions import APIException


class UserNotFoundError(APIException):
status_code = 404
default_detail = {"message": "해당하는 유저가 존재하지 않습니다.", "code": "0000"}


class TeamNotFoundError(APIException):
status_code = 404
default_detail = {"message": "해당하는 팀이 존재하지 않습니다.", "code": "0001"}


class TechNotFoundError(APIException):
status_code = 404
default_detail = {"message": "해당하는 기술스택이 존재하지 않습니다.", "code": "0002"}


class ApplyNotFoundError(APIException):
status_code = 404
default_detail = {"message": "해당하는 지원이 존재하지 않습니다.", "code": "0003"}


class TeamUserNotFoundError(APIException):
status_code = 404
default_detail = {"message": "해당하는 팀원이 존재하지 않습니다.", "code": "0004"}
Loading

0 comments on commit 648e6ca

Please sign in to comment.