Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix class/ endpoint to return all professors #102

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions django/university/controllers/ClassController.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
from university.models import Class, SlotClass, Slot, SlotProfessor
from university.models import Class, Professor, Slot, SlotProfessor


class ClassController:
@staticmethod
def get_professors(slot_obj):
try:
professor = slot_obj.slotprofessor.professor
professors = [
{'id': professor.id, 'acronym': professor.professor_acronym, 'name': professor.professor_name}]
except SlotProfessor.DoesNotExist:
professors = []
def get_professors(slot):
slot_professors = SlotProfessor.objects.filter(slot_id=slot.id).values()

professors = []

for slot_professor in slot_professors:
professor = Professor.objects.get(id=slot_professor['professor_id'])
professors.append({
'id': professor.id,
'acronym': professor.professor_acronym,
'name': professor.professor_name
thePeras marked this conversation as resolved.
Show resolved Hide resolved
})

return {
'id': slot_obj.id,
'lesson_type': slot_obj.lesson_type,
'day': slot_obj.day,
'start_time': float(slot_obj.start_time),
'duration': float(slot_obj.duration),
'location': slot_obj.location,
'is_composed': slot_obj.is_composed,
'id': slot.id,
'lesson_type': slot.lesson_type,
'day': slot.day,
'start_time': float(slot.start_time),
'duration': float(slot.duration),
'location': slot.location,
'is_composed': slot.is_composed,
'professors': professors
}

Expand All @@ -30,8 +35,7 @@ def get_classes(course_unit_id: int):
result = []
for class_obj in classes:
slot_ids = [sc.slot_id for sc in class_obj.slotclass_set.all()]
slots = Slot.objects.filter(id__in=slot_ids).prefetch_related(
'slotprofessor__professor')
slots = Slot.objects.filter(id__in=slot_ids)

slot_list = list(map(ClassController.get_professors, slots))

Expand Down