Skip to content

Commit

Permalink
Merge pull request #72 from NIAEFEUP/feature/scrappe-date
Browse files Browse the repository at this point in the history
Endpoint for scrapper info created
  • Loading branch information
diogotvf7 authored Jan 28, 2024
2 parents b349dd6 + ac41a08 commit bed3451
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
3 changes: 2 additions & 1 deletion django/university/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
path('course_last_year/<int:course_id>/', views.course_last_year),
path('schedule/<int:course_unit_id>/', views.schedule),
path('statistics/', views.data),
path('professors/<int:schedule>/', views.professor)
path('professors/<int:schedule>/', views.professor),
path('info/', views.info)
]

17 changes: 16 additions & 1 deletion django/university/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -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)
15 changes: 12 additions & 3 deletions mysql/sql/00_schema_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
--

Expand Down Expand Up @@ -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`);
Expand Down

0 comments on commit bed3451

Please sign in to comment.