From 17729bce411482f66ccbf9ee7c4a68cf7a82dfa9 Mon Sep 17 00:00:00 2001 From: Jakub K Date: Thu, 7 Mar 2024 23:49:55 +0100 Subject: [PATCH] ApiView - test --- deployment.yml | 2 +- jobposting/urls.py | 1 + jobposting/views.py | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/deployment.yml b/deployment.yml index 360561a..b1e2696 100644 --- a/deployment.yml +++ b/deployment.yml @@ -19,7 +19,7 @@ spec: - containerPort: 8000 volumeMounts: - name: static-storage - mountPath: /usr/scr/app/staticfiles # Ścieżka, gdzie Django oczekuje plików statycznych + mountPath: /usr/scr/app/staticfiles - name: static-media mountPath: /usr/scr/app/media volumes: diff --git a/jobposting/urls.py b/jobposting/urls.py index 6fe1d95..00bc339 100644 --- a/jobposting/urls.py +++ b/jobposting/urls.py @@ -14,4 +14,5 @@ router.register(r'skills', views.SkillViewset) urlpatterns = [ # ... path('', include(router.urls)), + path('skill/', views.SkillAPIView.as_view(), name='skill-list'), ] \ No newline at end of file diff --git a/jobposting/views.py b/jobposting/views.py index 27960aa..df60c0d 100644 --- a/jobposting/views.py +++ b/jobposting/views.py @@ -18,6 +18,7 @@ from jobposting.serializers import ( SkillSerializer ) + class MyUserViewSet(viewsets.ModelViewSet): # authentication_classes = [OAuth2Authentication, authentication.SessionAuthentication] # permission_classes = [permissions.IsAuthenticated|TokenHasReadWriteScope] @@ -28,6 +29,7 @@ class MyUserViewSet(viewsets.ModelViewSet): permission_classes = [] ### # # permission_classes = [permissions.IsAuthenticated] + class JobListingViewSet(viewsets.ModelViewSet): # authentication_classes = [OAuth2Authentication, authentication.SessionAuthentication] # permission_classes = [permissions.IsAuthenticated|TokenHasReadWriteScope] # test only @@ -66,6 +68,7 @@ class CompanyLogoViewSet(viewsets.ModelViewSet): authentication_classes = [] permission_classes = [] + class SkillViewset(viewsets.ModelViewSet): # authentication_classes = [OAuth2Authentication, authentication.SessionAuthentication] # permission_classes = [permissions.IsAuthenticated|TokenHasReadWriteScope] @@ -73,4 +76,35 @@ class SkillViewset(viewsets.ModelViewSet): serializer_class = SkillSerializer required_scope = ['main'] authentication_classes = [] - permission_classes = [] \ No newline at end of file + permission_classes = [] + + +class JobLisingMainView(APIView): + authentication_classes = [] + permission_classes = [] + + def get(self, request, format=None): + num_of_offers = request.query_params.get('num_of_offers') + try: + num_of_offers = int(num_of_offers) + except ValueError: + return Response({'error': 'Invalid number format'}, + status=status.HTTP_400_BAD_REQUEST) + job_listings = JobListing.objects.all()[:num_of_offers] + serializer = JobListingSerializer(job_listings, many=True) + return Response(serializer.data) + +class SkillMainView(APIView): + authentication_classes = [] + permission_classes = [] + + def get(self, request, format=None): + num_of_skills = request.query_params.get('num_of_skills') + try: + num_of_skills = int(num_of_skills) + except ValueError: + return Response({'error': 'Invalid number format'}, + status=status.HTTP_400_BAD_REQUEST) + skills = Skill.objects.all()[:num_of_skills] + serializer = SkillSerializer(skills, many=True) + return Response(serializer.data)