From ac41a083b324ad4c5f7bf47dab0c2762c23ae41d Mon Sep 17 00:00:00 2001 From: diogotvf7 Date: Sun, 28 Jan 2024 15:55:21 +0000 Subject: [PATCH] Endpoint for scrapper info created --- django/university/urls.py | 3 ++- django/university/views.py | 17 ++++++++++++++++- mysql/sql/00_schema_mysql.sql | 15 ++++++++++++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/django/university/urls.py b/django/university/urls.py index 946408c..64087b7 100644 --- a/django/university/urls.py +++ b/django/university/urls.py @@ -10,6 +10,7 @@ path('course_last_year//', views.course_last_year), path('schedule//', views.schedule), path('statistics/', views.data), - path('professors//', views.professor) + path('professors//', views.professor), + path('info/', views.info) ] diff --git a/django/university/views.py b/django/university/views.py index 1a327b1..104e12f 100644 --- a/django/university/views.py +++ b/django/university/views.py @@ -7,6 +7,7 @@ from university.models import ScheduleProfessor from university.models import CourseMetadata from university.models import Statistics +from university.models import Info from django.http import JsonResponse from django.core import serializers from rest_framework.decorators import api_view @@ -131,7 +132,6 @@ def data(request): """ Returns all the professors of a class of the schedule id """ - @api_view(["GET"]) def professor(request, schedule): schedule_professors = list(ScheduleProfessor.objects.filter(schedule=schedule).values()) @@ -144,3 +144,18 @@ def professor(request, schedule): 'professor_name': professor.professor_name }) return JsonResponse(professors, safe=False) + + +""" + Returns the contents of the info table +""" +@api_view(["GET"]) +def info(request): + info = Info.objects.first() + if info: + json_data = { + 'date': timezone.localtime(info.date).strftime('%Y-%m-%d %H:%M:%S') + } + return JsonResponse(json_data, safe=False) + else: + return JsonResponse({}, safe=False) diff --git a/mysql/sql/00_schema_mysql.sql b/mysql/sql/00_schema_mysql.sql index 76c5bc8..3c691d5 100644 --- a/mysql/sql/00_schema_mysql.sql +++ b/mysql/sql/00_schema_mysql.sql @@ -71,9 +71,6 @@ CREATE TABLE `course_metadata` ( `ects` float(4) NOT NULL ) ENGINE=InnoDB CHARSET = utf8 COLLATE = utf8_general_ci; - - - -- -------------------------------------------------------- -- -- Table structure for table `schedule` @@ -117,8 +114,18 @@ CREATE TABLE `professor` ( `professor_name` varchar(100) ) ENGINE=InnoDB CHARSET = utf8 COLLATE = utf8_general_ci; +-- -------------------------------------------------------- + +-- +-- Table structure for table `info` +-- + +CREATE TABLE `info` ( + `date` datetime +) ENGINE=InnoDB CHARSET = utf8 COLLATE = utf8_general_ci; -- -------------------------------------------------------- + -- Table structure for table `statistics` -- @@ -146,6 +153,8 @@ alter TABLE course_metadata ADD FOREIGN KEY (`course_id`) REFERENCES `course`(`i alter TABLE schedule ADD PRIMARY KEY (`id`); alter TABLE schedule ADD FOREIGN KEY (`course_unit_id`) REFERENCES `course_unit`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; +alter TABLE info ADD PRIMARY KEY (`date`); + alter TABLE statistics ADD PRIMARY KEY (`course_unit_id`); alter TABLE professor ADD PRIMARY KEY (`sigarra_id`);