diff --git a/django/university/urls.py b/django/university/urls.py index a446df1..9e216ca 100644 --- a/django/university/urls.py +++ b/django/university/urls.py @@ -9,6 +9,7 @@ path('course_unit//', views.course_unit_by_id), path('class//', views.classes), path('professors//', views.professor), - path('info/', views.info) + path('info/', views.info), + path('course_unit/hash', views.get_course_unit_hashes) ] diff --git a/django/university/views.py b/django/university/views.py index 956d299..48513bf 100644 --- a/django/university/views.py +++ b/django/university/views.py @@ -120,3 +120,30 @@ def info(request): return JsonResponse(json_data, safe=False) else: return JsonResponse({}, safe=False) + + +""" + Verifies if course units have the correct hash +""" + + +@api_view(['GET']) +def get_course_unit_hashes(request): + + ids_param = request.query_params.get('ids', '') + + try: + course_unit_ids = [int(id) for id in ids_param.split(',') if id] + except ValueError: + return JsonResponse({'error': 'Invalid ID format'}, status=400) + + results = {} + + for course_unit_id in course_unit_ids: + try: + course_unit = CourseUnit.objects.get(id=course_unit_id) + results[course_unit_id] = course_unit.hash + except CourseUnit.DoesNotExist: + results[course_unit_id] = None + + return JsonResponse(results, safe=False) diff --git a/postgres/sql/00_schema_postgres.sql b/postgres/sql/00_schema_postgres.sql index 2413b55..8be090a 100644 --- a/postgres/sql/00_schema_postgres.sql +++ b/postgres/sql/00_schema_postgres.sql @@ -98,7 +98,8 @@ CREATE TABLE "public"."course_unit" ( "semester" integer NOT NULL, "year" smallint NOT NULL, "schedule_url" character varying(2000), - "last_updated" timestamp with time zone NOT NULL + "last_updated" timestamp with time zone NOT NULL, + "hash" character varying(64) );