Skip to content

Commit

Permalink
Merge pull request #95 from NIAEFEUP/feature/hashCheckEndpoint
Browse files Browse the repository at this point in the history
Feature/hash check endpoint
  • Loading branch information
jose-carlos-sousa authored Aug 15, 2024
2 parents 493a746 + a2d0cbb commit 4094561
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
3 changes: 2 additions & 1 deletion django/university/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
path('course_unit/<int:course_unit_id>/', views.course_unit_by_id),
path('class/<int:course_unit_id>/', views.classes),
path('professors/<int:slot>/', views.professor),
path('info/', views.info)
path('info/', views.info),
path('course_unit/hash', views.get_course_unit_hashes)
]

27 changes: 27 additions & 0 deletions django/university/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion postgres/sql/00_schema_postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);


Expand Down

0 comments on commit 4094561

Please sign in to comment.