Skip to content

Commit

Permalink
Merge pull request #359 from codescalers/development_1.1_office_suppe…
Browse files Browse the repository at this point in the history
…rvisor_endpoint

Moved the supervisors endpoint under the user
  • Loading branch information
xmonader authored Feb 8, 2024
2 parents 4b5c0e7 + 4b66560 commit 65480eb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
3 changes: 1 addition & 2 deletions server/cshr/routes/office.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from django.urls import path


from cshr.views.office import OfficeApiView, BaseOfficeApiView, OfficeSupervisorsApiView
from cshr.views.office import OfficeApiView, BaseOfficeApiView

urlpatterns = [
path("", BaseOfficeApiView.as_view()),
path("<str:id>/", OfficeApiView.as_view()),
path("<str:id>/supervisors/", OfficeSupervisorsApiView.as_view()),
]
4 changes: 3 additions & 1 deletion server/cshr/routes/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
BaseSupervisorUserAPIView,
UserSkillsAPIView,
TeamAPIView,
TeamSupervisorsAPIView,
SupervisorsAPIView,
PostUserSkillsAPIView,
GetUsersBirthDatesAPIView,
Expand All @@ -30,7 +31,8 @@
path("admin/office_users/", GetUsersInAdminOfficeAPIView.as_view()),
path("team/", TeamAPIView.as_view()),
path("birthdates/", GetUsersBirthDatesAPIView.as_view()),
path("team/supervisors/", SupervisorsAPIView.as_view()),
path("team/supervisors/", TeamSupervisorsAPIView.as_view()),
path("supervisors/", SupervisorsAPIView.as_view()),
path("supervisor/<str:id>/", SupervisorUserAPIView.as_view()),
path("admin/<str:id>/", AdminUserAPIView.as_view()),
path("<str:id>/", GeneralUserAPIView.as_view()),
Expand Down
7 changes: 6 additions & 1 deletion server/cshr/services/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from typing import List, Union
from cshr.models.office import Office

from cshr.models.users import User, UserSkills
from cshr.models.users import USER_TYPE, User, UserSkills
from django.db.models.query import QuerySet


def get_user_by_id(id: str) -> User:
Expand Down Expand Up @@ -128,3 +129,7 @@ def get_all_skills():
def filter_users_by_birthdates(month: int, day: int) -> List[User]:
"""Filter all users by birthdates"""
return User.objects.filter(birthday__month=month, birthday__day=day)

def get_supervisors() -> QuerySet[User]:
"""Return all supervisors users"""
return User.objects.filter(user_type=USER_TYPE.SUPERVISOR)
17 changes: 0 additions & 17 deletions server/cshr/views/office.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,3 @@ def put(self, request: Request, id: str, format=None) -> Response:
error=serializer.errors, message="Office failed to update"
)
return CustomResponse.not_found(message="Office not found to update")


class OfficeSupervisorsApiView(ListAPIView, GenericAPIView):
"""method to get all Company properties"""

serializer_class = GeneralUserSerializer
permission_class = [IsAdmin | IsSupervisor]

def get_queryset(self) -> Response:
office_id = self.kwargs.get("id")
office = get_office_by_id(office_id)

if office is None:
return []

query_set = get_office_supervisors(office)
return query_set
13 changes: 12 additions & 1 deletion server/cshr/views/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
filter_users_by_birthdates,
get_admin_office_users,
get_all_skills,
get_supervisors,
get_user_by_id,
get_or_create_skill_by_name,
get_all_of_users,
Expand Down Expand Up @@ -64,7 +65,7 @@ def get_queryset(self) -> Response:
return query_set


class SupervisorsAPIView(ListAPIView):
class TeamSupervisorsAPIView(ListAPIView):
permission_classes = [UserIsAuthenticated]
serializer_class = TeamSerializer

Expand Down Expand Up @@ -366,3 +367,13 @@ def get(self, request: Request) -> Response:
return CustomResponse.success(
data=serializer.data, message="Users founded successfully."
)

class SupervisorsAPIView(ListAPIView, GenericAPIView):
"""method to get all Company properties"""

serializer_class = GeneralUserSerializer
permission_class = [IsAdmin | IsSupervisor]

def get_queryset(self) -> Response:
query_set = get_supervisors()
return query_set

0 comments on commit 65480eb

Please sign in to comment.