Fakultas Ilmu Komputer UI

Commit 024f40e3 authored by Joshua Casey's avatar Joshua Casey
Browse files

#23 added company applications and vacancies list api

parent 63144c3b
......@@ -5,7 +5,7 @@ from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from core.lib.permissions import IsAdminOrStudent, IsAdminOrCompany
from core.models import Student
from core.models import Student, Company
from core.models.vacancies import Vacancy, Application
from core.serializers.vacancies import VacancySerializer, ApplicationSerializer
......@@ -66,6 +66,33 @@ class ApplicationViewSet(viewsets.GenericViewSet):
return Response(ApplicationSerializer(application, context={'request': request}).data)
class CompanyApplicationViewSet(viewsets.GenericViewSet):
queryset = Application.objects.all()
def list(self, request, company_id):
"""
Get list of company {company_id}'s applications
---
"""
company = get_object_or_404(Company.objects.all(), pk=company_id)
vacancies = Vacancy.objects.filter(company = company)
applications = Application.objects.filter(vacancy__in = vacancies)
return Response(ApplicationSerializer(applications, many=True, context={'request': request}).data)
class CompanyVacanciesViewSet(viewsets.GenericViewSet):
queryset = Vacancy. objects.all()
def list(self, request, company_id):
"""
Get list of company {company_id}'s vacancies
---
"""
company = get_object_or_404(Company.objects.all(), pk=company_id)
vacancies = Vacancy.objects.filter(company = company)
return Response(VacancySerializer(vacancies, many=True, context={'request': request}).data)
class BookmarkedVacancyByStudentViewSet(viewsets.GenericViewSet):
serializer_class = VacancySerializer
permission_classes = [IsAdminOrStudent]
......
......@@ -23,7 +23,7 @@ from rest_framework_swagger.views import get_swagger_view
from core import apps
from core.views.accounts import StudentViewSet, CompanyViewSet, SupervisorViewSet, UserViewSet, LoginViewSet, CompanyRegisterViewSet
from core.views.vacancies import VacancyViewSet, BookmarkedVacancyByStudentViewSet, ApplicationViewSet
from core.views.vacancies import VacancyViewSet, BookmarkedVacancyByStudentViewSet, ApplicationViewSet, CompanyApplicationViewSet, CompanyVacanciesViewSet
schema_view = get_swagger_view()
router = routers.DefaultRouter()
......@@ -38,7 +38,10 @@ router.register(r'students/(?P<student_id>\d+)/bookmarked-vacancies', Bookmarked
base_name='bookmarked-vacancy-list')
router.register(r'students/(?P<student_id>\d+)/applied-vacancies', ApplicationViewSet,
base_name='applications')
router.register(r'companies/(?P<company_id>\d+)/applications', CompanyApplicationViewSet,
base_name='company-applications')
router.register(r'companies/(?P<company_id>\d+)/vacancies', CompanyVacanciesViewSet,
base_name='company-vacancies')
urlpatterns = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += [
......@@ -49,5 +52,3 @@ urlpatterns += [
url(r'^admin/', admin.site.urls),
url(r'', apps.index, name="index"),
]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment