Fakultas Ilmu Komputer UI

Commit dd5f7565 authored by Farhan Farasdak's avatar Farhan Farasdak
Browse files

[#140382397] #11 Vacancy API endpoint

parent 77e9a5d3
from django.contrib import admin
from core.models import Application
from core.models import Vacancy
from core.models.vacancies import Application, Vacancy
from core.models.accounts import Company, Supervisor, Student
admin.site.register(Company)
......
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-24 11:38
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0002_auto_20170320_1650'),
]
operations = [
migrations.AddField(
model_name='student',
name='bookmarked_vacancies',
field=models.ManyToManyField(to='core.Vacancy'),
),
]
# __init__.py
from core.models.accounts import Supervisor
from core.models.accounts import Student
from core.models.accounts import Company
from core.models.vacancies import Vacancy
from core.models.accounts import Student
from core.models.accounts import Supervisor
from core.models.vacancies import Application
from core.models.vacancies import Vacancy
import os
import uuid
from django.db import models
from django.contrib.auth.models import User
from django.core.validators import MinValueValidator, MaxValueValidator
from django.db import models
def get_file_path(instance, filename):
extension = filename.split('.')[-1].lower()
......@@ -42,6 +41,7 @@ class Student(models.Model):
npm = models.IntegerField(validators=[MinValueValidator(100000000), MaxValueValidator(9999999999)], unique=True)
resume = models.FileField(upload_to=get_file_path, null=True, blank=True)
phone_number = models.CharField(max_length=100, blank=True, db_index=True)
bookmarked_vacancies = models.ManyToManyField('core.Vacancy')
@property
def name(self):
......
import os
import uuid
from django.db import models
from core.models.accounts import Company, Student
......
from rest_framework import serializers
from core.models.vacancies import Vacancy, Application
class VacancySerializer(serializers.ModelSerializer):
class Meta:
model = Vacancy
fields = '__all__'
class ApplicationSerializer(serializers.ModelSerializer):
class Meta:
model = Application
fields = '__all__'
from unittest import TestCase
class TestStudentViewSet(TestCase):
def test_vacancies(self):
self.fail()
def test_insert_vacancies(self):
self.fail()
from unittest import TestCase
class TestUserViewSet(TestCase):
def test_me(self):
self.fail()
from django.contrib.auth.models import User
from rest_framework import status
from rest_framework import viewsets
from rest_framework.decorators import list_route
from rest_framework.decorators import list_route, detail_route
from rest_framework.response import Response
from core.models.accounts import Student, Company, Supervisor
from core.models import Vacancy
from core.models.accounts import Student, Company, Supervisor, get_display_name
from core.serializers.accounts import UserSerializer, StudentSerializer, CompanySerializer, SupervisorSerializer
......@@ -22,6 +24,18 @@ class StudentViewSet(viewsets.ModelViewSet):
queryset = Student.objects.all()
serializer_class = StudentSerializer
@detail_route(methods=['get'], url_path='vacancies')
def vacancies(self, request, pk):
student = Student.objects.get(pk=pk)
return Response(get_display_name(student))
@detail_route(methods=['post'], url_path='vacancies')
def insert_vacancies(self, request, pk):
vacancy = Vacancy.objects.get(request.data.id)
student = self.request.user.student
student.bookmarked_vacancies.add(vacancy)
return Response(vacancy, status=status.HTTP_200_OK)
class CompanyViewSet(viewsets.ModelViewSet):
queryset = Company.objects.all()
......
from rest_framework import viewsets
from core.models.vacancies import Vacancy, Application
from core.serializers.vacancies import VacancySerializer, ApplicationSerializer
class VacancyViewSet(viewsets.ModelViewSet):
queryset = Vacancy.objects.all()
serializer_class = VacancySerializer
class ApplicationViewSet(viewsets.ModelViewSet):
queryset = Application.objects.all()
serializer_class = ApplicationSerializer
......@@ -23,6 +23,7 @@ from rest_framework_swagger.views import get_swagger_view
from core import apps
from core.views.accounts import StudentViewSet, CompanyViewSet, SupervisorViewSet, UserViewSet
from core.views.vacancies import VacancyViewSet, ApplicationViewSet
schema_view = get_swagger_view()
router = routers.DefaultRouter()
......@@ -30,6 +31,8 @@ router.register(r'users', UserViewSet)
router.register(r'students', StudentViewSet)
router.register(r'companies', CompanyViewSet)
router.register(r'supervisors', SupervisorViewSet)
router.register(r'vacancies', VacancyViewSet)
router.register(r'applications', ApplicationViewSet)
urlpatterns = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += [
......
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