def post(self, request): serializer = VacancySerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response({'error': serializer.errors}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def put(self, request, vacancy_id): vacancy = self.get_object(vacancy_id) serializer = VacancySerializer(instance=vacancy, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response({'error': serializer.errors})
def vacancy_list(request): if request.method == 'GET': vacancies = Vacancy.objects.all() serializer = VacancySerializer(vacancies, many=True) return Response(serializer.data) elif request.method == 'POST': serializer = VacancySerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response({'error': serializer.errors}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def company_vacancies(request, company_id): try: vacancies = Vacancy.objects.filter(company_id=company_id) except Vacancy.DoesNotExist as e: return Response({'error': str(e)}) if request.method == 'GET': serializer = VacancySerializer(vacancies, many=True) return Response(serializer.data) elif request.method == 'PUT': serializer = VacancySerializer(instance=vacancies, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response({'error': serializer.errors}) elif request.method == 'DELETE': vacancies.delete() return Response({'deleted': True})
def vacancy_detail(request, vacancy_id): try: vacancy = Vacancy.objects.get(id=vacancy_id) except Company.DoesNotExist as e: return Response({'error': str(e)}) if request.method == 'GET': serializer = VacancySerializer(vacancy) return Response(serializer.data) elif request.method == 'PUT': serializer = VacancySerializer(instance=vacancy, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response({'error': serializer.errors}) elif request.method == 'DELETE': vacancy.delete() return Response({'deleted': True})
def get(self, request, company_id): vacancies = Vacancy.objects.filter(company_id=company_id) serializer = VacancySerializer(vacancies, many=True) return Response(serializer.data)
def get(self, request, vacancy_id): vacancy = self.get_object(vacancy_id) serializer = VacancySerializer(vacancy) return Response(serializer.data)
def get(self, request): vacancies = Vacancy.objects.all() serializer = VacancySerializer(vacancies, many=True) return Response(serializer.data)