From 9a5ac39912defe89e8085e99669da6b8351510e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Palma?= Date: Fri, 6 Sep 2024 16:26:27 +0100 Subject: [PATCH 1/2] feat: professor link table to efficiently store links --- django/university/controllers/ClassController.py | 7 +++++-- postgres/sql/00_schema_postgres.sql | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/django/university/controllers/ClassController.py b/django/university/controllers/ClassController.py index a6d2a5b..1dce02d 100644 --- a/django/university/controllers/ClassController.py +++ b/django/university/controllers/ClassController.py @@ -1,4 +1,4 @@ -from university.models import Class, Professor, Slot, SlotProfessor +from university.models import Class, Professor, Slot, SlotProfessor, ProfessorLink class ClassController: @@ -9,11 +9,14 @@ def get_professors(slot): professors = [] for slot_professor in slot_professors: + professor_link = ProfessorLink.objects.get(pk=slot_professor.link_id) + professor = Professor.objects.get(id=slot_professor['professor_id']) professors.append({ 'id': professor.id, 'acronym': professor.professor_acronym, - 'name': professor.professor_name + 'name': professor.professor_name, + 'link': professor_link.link }) return { diff --git a/postgres/sql/00_schema_postgres.sql b/postgres/sql/00_schema_postgres.sql index 8be090a..d71bf63 100644 --- a/postgres/sql/00_schema_postgres.sql +++ b/postgres/sql/00_schema_postgres.sql @@ -165,6 +165,10 @@ CREATE TABLE "public"."slot_class" ( "class_id" bigint NOT NULL ); +CREATE TABLE "public"."professor_link" ( + id SERIAL PRIMARY KEY, + "link" varchar(256) NOT NULL +); -- -- TOC entry 225 (class 1259 OID 16806) @@ -173,7 +177,8 @@ CREATE TABLE "public"."slot_class" ( CREATE TABLE "public"."slot_professor" ( "slot_id" integer NOT NULL, - "professor_id" integer NOT NULL + "professor_id" integer NOT NULL, + "link_id" integer NOT NULL ); @@ -317,7 +322,7 @@ ALTER TABLE ONLY "public"."slot" -- ALTER TABLE ONLY "public"."slot_professor" - ADD CONSTRAINT "slot_professor_pkey" PRIMARY KEY ("slot_id", "professor_id"); + ADD CONSTRAINT "slot_professor_pkey" PRIMARY KEY ("slot_id", "professor_id", "link_id"); -- From 3ace435e4a93f7d3f0e64eb85cab296d9ab387fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Palma?= Date: Fri, 20 Sep 2024 10:27:32 +0100 Subject: [PATCH 2/2] chore: add foreign key constraint to link_id of slot_professor --- postgres/sql/00_schema_postgres.sql | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/postgres/sql/00_schema_postgres.sql b/postgres/sql/00_schema_postgres.sql index d71bf63..8ec2712 100644 --- a/postgres/sql/00_schema_postgres.sql +++ b/postgres/sql/00_schema_postgres.sql @@ -322,7 +322,7 @@ ALTER TABLE ONLY "public"."slot" -- ALTER TABLE ONLY "public"."slot_professor" - ADD CONSTRAINT "slot_professor_pkey" PRIMARY KEY ("slot_id", "professor_id", "link_id"); + ADD CONSTRAINT "slot_professor_pkey" PRIMARY KEY ("slot_id", "professor_id"); -- @@ -478,6 +478,10 @@ ALTER TABLE ONLY "public"."slot_professor" ALTER TABLE ONLY "public"."slot_professor" ADD CONSTRAINT "slot_professor_slot_id_ddc4b9c2_fk_slot_id" FOREIGN KEY ("slot_id") REFERENCES "public"."slot"("id") DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE ONLY "public"."slot_professor" + ADD CONSTRAINT "slot_professor_professor_link_id" FOREIGN KEY ("link_id") REFERENCES "public"."professor_link"("id") DEFERRABLE INITIALLY DEFERRED; + + -- Completed on 2024-08-13 22:21:25 UTC