NIAEFEUP / tts-be

A platform where students can experiment with the possible combination of schedule options they can pick at the start of the semester
https://tts.niaefeup.pt
5 stars 1 forks source link

Refactor: course_units_api now searches courses and course_units through course_unit_year table #53

Closed tomaspalma closed 1 year ago

tomaspalma commented 1 year ago

Closes #51

Note: Currently, as the new modifications to the tables and the scrapper are not on the develop branch yet, when you are testing this, it is most likely that the course_unit_year table is empty on the local version of your database and that is probably the reason why if you run this backend version it will not work correctly as it will return an empty array if you're course_unit_year table is also empty.

Why was this necessary

For future reference

In order to address the planned changes in the database, it was necessary to now retrieve information about course units through the course_unit_year table as the same course unit can have more than one curricular year, instead of risking having more than one entry in the database about the same course unit where the only thing different would be the curricular year, which would happen with the old schema.


How was it done

Previously, in the django views course_units and course_units_by_year what was being retrieved was all the CourseUnit objects that matched the parameters passed to the view and in the course_last_year was searching through the course_units table.

The changes were

How was it tested

This was tested by creating two entries in the course_unit_year table that linked to the same course and course_unit but had different values for the course_year attribute and the result of the course_units api was correct.

image

Note: In reality, this course unit does not have multiple years. It's just that way in this case because it was an hardcoded example.