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

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

Merged
merged 4 commits into from
Apr 25, 2023

Conversation

tomaspalma
Copy link
Member

@tomaspalma tomaspalma commented Feb 23, 2023

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

  • Instead of using the CourseUnit model, the model used is now the CourseMetadata

  • It now concatenates the dictionary of a certain course unit metadata instance and the dictionary of a the course unit
    whose id is the same as in the course unit metadata

  • In the course_last_year view now it searches the max course_year going through the course_unit_year table and not through the course_unit one.

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.

@tomaspalma tomaspalma marked this pull request as ready for review February 25, 2023 14:14
@tomaspalma tomaspalma marked this pull request as draft March 3, 2023 00:08
@tomaspalma tomaspalma marked this pull request as ready for review March 4, 2023 19:30
Copy link
Contributor

@SergioEstevao11 SergioEstevao11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the endpoints with the new database schema: update the course_year parameter to get this information from a JOIN between the tables couse_unit & course_unit_year

@Jumaruba Jumaruba merged commit 40b1bc6 into develop Apr 25, 2023
@tomaspalma tomaspalma deleted the refactor/course_unit_api-51 branch September 20, 2024 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change course_unit API
3 participants