Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #110 from SELab-2/schedule-api
Browse files Browse the repository at this point in the history
Schedule api
  • Loading branch information
JasperJanin authored Mar 16, 2023
2 parents 6a9efc1 + 9ca034a commit a7770d4
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 23 deletions.
18 changes: 18 additions & 0 deletions backend/drtrottoir/migrations/0015_alter_customuser_buildings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.7 on 2023-03-16 19:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('drtrottoir', '0014_photo_image_alter_photo_visit'),
]

operations = [
migrations.AlterField(
model_name='customuser',
name='buildings',
field=models.ManyToManyField(related_name='owners', to='drtrottoir.building'),
),
]
2 changes: 1 addition & 1 deletion backend/drtrottoir/models/custom_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CustomUser(AbstractBaseUser):
last_name = models.CharField(verbose_name="last name", max_length=256, default='default')
region = models.ForeignKey(Region, verbose_name="Region of the user", on_delete=models.SET_NULL, null=True)
role = models.IntegerField(choices=Roles.choices, default=Roles.STUDENT)
buildings = models.ManyToManyField(Building, related_name='users')
buildings = models.ManyToManyField(Building, related_name='owners')

objects = CustomUserManager()

Expand Down
7 changes: 6 additions & 1 deletion backend/drtrottoir/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
from .building_in_tour_serializer import BuildingInTourSerializer
from .user_partial import UserPartialSerializer
from .visit_serializer import VisitSerializer
from .schedule_serializer import ScheduleSerializer
from .tour_partial import TourPartialSerializer
from .photo_serializer import PhotoSerializer
from .waste_serializer import WasteSerializer
from .waste_partial import WastePartialSerializer
from .register_serializer import RegisterSerializer
from .building_in_tour_partial import BuildingInTourPartialSerializer
from .tour_partial import TourPartialSerializer


__all__ = [
Expand All @@ -21,6 +22,10 @@
UserSerializer,
UserPartialSerializer,
VisitSerializer,
ScheduleSerializer,
RegisterSerializer,
TourSerializer,
BuildingInTourSerializer,
PhotoSerializer,
WasteSerializer,
WastePartialSerializer,
Expand Down
2 changes: 1 addition & 1 deletion backend/drtrottoir/serializers/building_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BuildingSerializer(serializers.HyperlinkedModelSerializer):
source='region.region_name',
read_only=True
)
users = UserPartialSerializer(many=True)
owners = UserPartialSerializer(many=True)

class Meta:
model = Building
Expand Down
12 changes: 12 additions & 0 deletions backend/drtrottoir/serializers/schedule_serializer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from drtrottoir.models import Schedule
from rest_framework import serializers


class ScheduleSerializer(serializers.HyperlinkedModelSerializer):
"""
A serializer for schedules, showing tour info
"""

class Meta:
model = Schedule
fields = ['url', 'date', 'student', 'tour', 'comment']
40 changes: 20 additions & 20 deletions backend/drtrottoir/serializers/tour_partial.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from drtrottoir.models import Tour
from rest_framework import serializers


class TourPartialSerializer(serializers.HyperlinkedModelSerializer):
"""
A serializer for buildings, not showing recursive relations
"""
region_name = serializers.CharField(
source='region.region_name',
read_only=True
)

class Meta:
model = Tour
fields = [
'url',
'name',
'region_name'
]
from drtrottoir.models import Tour
from rest_framework import serializers


class TourPartialSerializer(serializers.HyperlinkedModelSerializer):
"""
A serializer for buildings, not showing recursive relations
"""
region_name = serializers.CharField(
source='region.region_name',
read_only=True
)

class Meta:
model = Tour
fields = [
'url',
'name',
'region_name'
]
2 changes: 2 additions & 0 deletions backend/drtrottoir/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
BuildingInTourViewSet,
VisitViewSet,
UserViewSet,
ScheduleViewSet,
WasteViewSet,
RegisterView,
PhotoViewSet,
Expand All @@ -28,6 +29,7 @@
router.register(r'building_in_tour', BuildingInTourViewSet)
router.register(r'visit', VisitViewSet)
router.register(r'user', UserViewSet)
router.register(r'schedule', ScheduleViewSet)
router.register(r'photo', PhotoViewSet)
router.register(r'waste', WasteViewSet)

Expand Down
2 changes: 2 additions & 0 deletions backend/drtrottoir/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .building_in_tour_viewset import BuildingInTourViewSet
from .visit_viewset import VisitViewSet
from .user_viewset import UserViewSet
from .schedule_viewset import ScheduleViewSet
from .photo_viewset import PhotoViewSet
from .register_view import RegisterView
from .me_view import MeView
Expand All @@ -14,6 +15,7 @@
RegionViewSet,
VisitViewSet,
UserViewSet,
ScheduleViewSet,
PhotoViewSet,
RegisterView,
WasteViewSet,
Expand Down
15 changes: 15 additions & 0 deletions backend/drtrottoir/views/schedule_viewset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticated
from drtrottoir.models import Schedule
from drtrottoir.permissions import SuperPermissionOrReadOnly
from drtrottoir.serializers import ScheduleSerializer


class ScheduleViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows regions to be viewed or edited.
"""

queryset = Schedule.objects.all()
serializer_class = ScheduleSerializer
permission_classes = [IsAuthenticated & SuperPermissionOrReadOnly]

0 comments on commit a7770d4

Please sign in to comment.