From 5d161c7443a754a30aa47edb5471773ffdb9203a Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Sun, 30 Jun 2024 20:30:54 +0200 Subject: [PATCH 01/21] Add files via upload --- DBHandler/DBHandler.cpp | 25 ++++++++++++++++++ DBHandler/DBHandler.hpp | 14 +++++++++++ DBHandler/DBLogin.cpp | 40 +++++++++++++++++++++++++++++ DBHandler/DBLogin.hpp | 18 +++++++++++++ DBHandler/DBPlan.cpp | 56 +++++++++++++++++++++++++++++++++++++++++ DBHandler/DBPlan.hpp | 28 +++++++++++++++++++++ script.sql | 54 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 235 insertions(+) create mode 100644 DBHandler/DBHandler.cpp create mode 100644 DBHandler/DBHandler.hpp create mode 100644 DBHandler/DBLogin.cpp create mode 100644 DBHandler/DBLogin.hpp create mode 100644 DBHandler/DBPlan.cpp create mode 100644 DBHandler/DBPlan.hpp create mode 100644 script.sql diff --git a/DBHandler/DBHandler.cpp b/DBHandler/DBHandler.cpp new file mode 100644 index 0000000..58d50ab --- /dev/null +++ b/DBHandler/DBHandler.cpp @@ -0,0 +1,25 @@ +#include "DBHandler.hpp" + +#include +//host = localhost port = 5432 dbname = postgres user = postgres password = **** + + +DBHandler::DBHandler(std::string connStr) : connectionObject(connStr.c_str()) { + try { + if (connectionObject.is_open()) { + std::cout << "Databased connected" << std::endl; + } + else + std::cout << "Failed to connect to Databased" << std::endl; + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } +}; + + + + + + + diff --git a/DBHandler/DBHandler.hpp b/DBHandler/DBHandler.hpp new file mode 100644 index 0000000..71f9db7 --- /dev/null +++ b/DBHandler/DBHandler.hpp @@ -0,0 +1,14 @@ +#ifndef DBHANDLER_HPP_ +#define DBHANDLER_HPP_ +#include +#include + +class DBHandler { +protected: + pqxx::connection connectionObject; + +public: + DBHandler(std::string connStr); +}; + +#endif \ No newline at end of file diff --git a/DBHandler/DBLogin.cpp b/DBHandler/DBLogin.cpp new file mode 100644 index 0000000..e942725 --- /dev/null +++ b/DBHandler/DBLogin.cpp @@ -0,0 +1,40 @@ +#include "DBLogin.hpp" +#include + +DBLogin::DBLogin(std::string connStr) : DBHandler(connStr) {}; + + + +/* + +return 1 if admin | 0 if not admin | -1 if failed + +*/ + +int DBLogin::checkValidLogin(int id, std::string pw) { + + try { + pqxx::work worker(connectionObject); + + std::string query = + "SELECT admin FROM studenten_veranstalterr WHERE id = $1 AND passwort = $2"; + + pqxx::result response = worker.exec_params(query, id, pw); + + if (response.affected_rows() > 0) { + + std::cout << response[0][0] << std::endl; + if (response[0][0].is_null()) + return 0; + return response[0][0].as(); + + } + + return -1; +} +catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; +} + +} + diff --git a/DBHandler/DBLogin.hpp b/DBHandler/DBLogin.hpp new file mode 100644 index 0000000..f29e0c0 --- /dev/null +++ b/DBHandler/DBLogin.hpp @@ -0,0 +1,18 @@ +#ifndef _DBLOGIN_HPP_ +#define _DBLOGIN_HPP_ +#include "DBHandler.hpp" + +class DBLogin : public DBHandler { +public: + DBLogin(std::string connStr); + /* + +return 1 if admin | 0 if not admin | -1 if failed + +*/ + int checkValidLogin(int id, std::string pw); +}; + + + +#endif \ No newline at end of file diff --git a/DBHandler/DBPlan.cpp b/DBHandler/DBPlan.cpp new file mode 100644 index 0000000..f3d4284 --- /dev/null +++ b/DBHandler/DBPlan.cpp @@ -0,0 +1,56 @@ +#include "DBPlan.hpp" + +DBPlan::DBPlan(std::string connStr) : DBHandler(connStr) {}; + + +void DBPlan::meldeKrank(int id) { + + try { + pqxx::work worker(connectionObject); + std::string query = + "INSERT INTO krank (veranstalter_ID) VALUES($1);"; + + pqxx::result response = worker.exec_params(query, id); + worker.commit(); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + + } + } + + + void DBPlan::meldeGesund(int id) { + try { + pqxx::work worker(connectionObject); + std::string query = + "DELETE FROM krank WHERE veranstalter_ID = $1 ;"; + + pqxx::result response = worker.exec_params(query, id); + worker.commit(); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + } + + + + + + void DBPlan:: deleteVeranstalter(int id) { + try { + pqxx::work worker(connectionObject); + std::string query = + "DELETE FROM Veranstalterrrr WHERE ID = $1"; + + pqxx::result response = worker.exec_params(query, id); + worker.commit(); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + } + + +}; \ No newline at end of file diff --git a/DBHandler/DBPlan.hpp b/DBHandler/DBPlan.hpp new file mode 100644 index 0000000..e138c1d --- /dev/null +++ b/DBHandler/DBPlan.hpp @@ -0,0 +1,28 @@ +#ifndef _DBPLAN_HPP_ +#define _DBPLAN_HPP_ + + +#include "DBHandler.hpp" +#include +#include + +class DBPlan : public DBHandler { +public: + DBPlan(std::string connStr); + void meldeKrank(int id); + void meldeGesund(int id); + bool deleteVeranstaltung(int id); + bool hinzufuegenVeranstaltung(); //Zu Liste mit Veranstaltungen oder direkt in den Einsatzplan? + + + void deleteVeranstalter(int id); + bool hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, bool admin); + std::vector < std::vector> getVeranstalter(); + + bool deleteStudent(int id); + bool hinzufuegenStudent(std::string email, std::string name, std::string pw); + std::vector < std::vector> getStudenten(); + +}; + +#endif \ No newline at end of file diff --git a/script.sql b/script.sql new file mode 100644 index 0000000..c0a9f72 --- /dev/null +++ b/script.sql @@ -0,0 +1,54 @@ +CREATE SEQUENCE global_id_seq; + +CREATE TABLE Studenten ( + matrikelnummer INTEGER PRIMARY KEY DEFAULT nextval('global_id_seq'), + "name VARCHAR(30) NOT NULL, + "email VARCHAR(30) NOT NULL, + "passwort VARCHAR(30) NOT NULL); + + + "CREATE TABLE Veranstalter ( + ID INTEGER PRIMARY KEY DEFAULT nextval('global_id_seq'), + name VARCHAR(30), + email VARCHAR(30), + passwort VARCHAR(30), + admin BOOLEAN NOT NULL DEFAULT(FALSE) + + ); + + +CREATE TABLE krank ( + veranstalter_ID INTEGER, + FOREIGN KEY (veranstalter_ID) REFERENCES veranstalterrrr(ID) ON DELETE CASCADE); + + + + CREATE VIEW studenten_veranstalterr AS + SELECT matrikelnummer AS id, passwort, NULL AS admin FROM Studenten + UNION ALL + SELECT ID, passwort, admin FROM Veranstalterrrr; + + + + CREATE TABLE Veranstaltung ( + ID SERIAL PRIMARY KEY, + ort VARCHAR(30) NOT NULL, + raum VARCHAR(30) NOT NULL, + name VARCHAR(30) NOT NULL ); + + + + + CREATE TABLE Uhrzeit ( + ID SERIAL PRIMARY KEY, + anfangszeit TIME NOT NULL, + endzeit TIME NOT NULL ); + + + + INSERT INTO Uhrzeit (anfangszeit, endzeit) VALUES + ('08:00:00', '10:00:00'), + ('10:00:00', '12:00:00'), + ('12:00:00', '14:00:00'), + ('14:00:00', '16:00:00'), + ('16:00:00', '18:00:00'); \ No newline at end of file From 0546e2b18982e31c75e06872b9281eb81bdaa0f9 Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Mon, 1 Jul 2024 13:25:29 +0200 Subject: [PATCH 02/21] Update script.sql added some promps --- script.sql | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/script.sql b/script.sql index c0a9f72..27c144d 100644 --- a/script.sql +++ b/script.sql @@ -51,4 +51,52 @@ CREATE TABLE krank ( ('10:00:00', '12:00:00'), ('12:00:00', '14:00:00'), ('14:00:00', '16:00:00'), - ('16:00:00', '18:00:00'); \ No newline at end of file + ('16:00:00', '18:00:00'); + + + CREATE TABLE Veranstalter_Veranstaltung_Uhrzeit ( + uhrzeit_ID INTEGER REFERENCES Uhrzeit(ID), + tag INTEGER NOT NULL, + veranstalter_ID INTEGER REFERNECES Veranstalter(ID), + veranstaltung_ID INTEGER REFERENCES Veranstaltung(ID), + PRIMARY KEY(uhrzeit_ID, tag) + ); + + + INSERT INTO Veranstalter (name, email, passwort, admin) VALUES + ('tech_guru', 'admin@example.com', 'password123', 1), +('code_master', 'user1@example.com', 'password1', 0), +('binary_hero', 'user2@example.com', 'password2', 0), +('debug_ninja', 'user3@example.com', 'password3', 0), +('data_wizard', 'user4@example.com', 'password4', 0), +('script_samurai', 'user5@example.com', 'password5', 0), +('dev_genius', 'user6@example.com', 'password6', 0), +('cyber_maven', 'user7@example.com', 'password7', 0), +('net_knight', 'user8@example.com', 'password8', 0), +('bit_boss', 'user9@example.com', 'password9', 0), +('sys_sensei', 'user10@example.com', 'password10', 0), +('crypto_champ', 'user11@example.com', 'password11', 0), +('cloud_conqueror', 'user12@example.com', 'password12', 0), +('hack_whiz', 'user13@example.com', 'password13', 0), +('matrix_mage', 'user14@example.com', 'password14', 0), +('app_artisan', 'user15@example.com', 'password15', 0), +('ai_architect', 'user16@example.com', 'password16', 0), +('tech_titan', 'user17@example.com', 'password17', 0), +('proto_pro', 'user18@example.com', 'password18', 0), +('alg_adept', 'user19@example.com', 'password19', 0), +('data_diver', 'user20@example.com', 'password20', 0), +('web_warrior', 'user21@example.com', 'password21', 0), +('os_overlord', 'user22@example.com', 'password22', 0), +('kernel_keeper', 'user23@example.com', 'password23', 0); + + INSERT INTO Veranstaltung (ort, raum, name, dauer) VALUES + ('A', '101', 'Grundlagen der Programmierung', 2), +('B', '202', 'Algorithmen und Datenstrukturen', 4), +('A', '103', 'Netzwerkgrundlagen', 2), +('B', '204', 'Betriebssystemkonzepte', 4), +('A', '105', 'Softwareentwicklung', 2), +('B', '206', 'Intelligente Systeme', 4), +('A', '107', 'Datenbanksysteme', 2), +('B', '208', 'Webtechnologien', 2), +('A', '109', 'Computergrafikgrundlagen', 2), +('B', '210', 'Maschinelles Lernen', 2); From 77125362f6beb4ab1e2cfc6273cc8a5c7c59fc79 Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Mon, 1 Jul 2024 13:32:27 +0200 Subject: [PATCH 03/21] Update script.sql bugfix --- script.sql | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/script.sql b/script.sql index 27c144d..05540e8 100644 --- a/script.sql +++ b/script.sql @@ -64,30 +64,30 @@ CREATE TABLE krank ( INSERT INTO Veranstalter (name, email, passwort, admin) VALUES - ('tech_guru', 'admin@example.com', 'password123', 1), -('code_master', 'user1@example.com', 'password1', 0), -('binary_hero', 'user2@example.com', 'password2', 0), -('debug_ninja', 'user3@example.com', 'password3', 0), -('data_wizard', 'user4@example.com', 'password4', 0), -('script_samurai', 'user5@example.com', 'password5', 0), -('dev_genius', 'user6@example.com', 'password6', 0), -('cyber_maven', 'user7@example.com', 'password7', 0), -('net_knight', 'user8@example.com', 'password8', 0), -('bit_boss', 'user9@example.com', 'password9', 0), -('sys_sensei', 'user10@example.com', 'password10', 0), -('crypto_champ', 'user11@example.com', 'password11', 0), -('cloud_conqueror', 'user12@example.com', 'password12', 0), -('hack_whiz', 'user13@example.com', 'password13', 0), -('matrix_mage', 'user14@example.com', 'password14', 0), -('app_artisan', 'user15@example.com', 'password15', 0), -('ai_architect', 'user16@example.com', 'password16', 0), -('tech_titan', 'user17@example.com', 'password17', 0), -('proto_pro', 'user18@example.com', 'password18', 0), -('alg_adept', 'user19@example.com', 'password19', 0), -('data_diver', 'user20@example.com', 'password20', 0), -('web_warrior', 'user21@example.com', 'password21', 0), -('os_overlord', 'user22@example.com', 'password22', 0), -('kernel_keeper', 'user23@example.com', 'password23', 0); + ('tech_guru', 'admin@example.com', 'password123', TRUE), +('code_master', 'user1@example.com', 'password1', FALSE), +('binary_hero', 'user2@example.com', 'password2', FALSE), +('debug_ninja', 'user3@example.com', 'password3', FALSE), +('data_wizard', 'user4@example.com', 'password4', FALSE), +('script_samurai', 'user5@example.com', 'password5', FALSE), +('dev_genius', 'user6@example.com', 'password6', FALSE), +('cyber_maven', 'user7@example.com', 'password7', FALSE), +('net_knight', 'user8@example.com', 'password8', FALSE), +('bit_boss', 'user9@example.com', 'password9', FALSE), +('sys_sensei', 'user10@example.com', 'password10', FALSE), +('crypto_champ', 'user11@example.com', 'password11', FALSE), +('cloud_conqueror', 'user12@example.com', 'password12', FALSE), +('hack_whiz', 'user13@example.com', 'password13', FALSE), +('matrix_mage', 'user14@example.com', 'password14', FALSE), +('app_artisan', 'user15@example.com', 'password15', FALSE), +('ai_architect', 'user16@example.com', 'password16', FALSE), +('tech_titan', 'user17@example.com', 'password17', FALSE), +('proto_pro', 'user18@example.com', 'password18', FALSE), +('alg_adept', 'user19@example.com', 'password19', FALSE), +('data_diver', 'user20@example.com', 'password20', FALSE), +('web_warrior', 'user21@example.com', 'password21', FALSE), +('os_overlord', 'user22@example.com', 'password22', FALSE), +('kernel_keeper', 'user23@example.com', 'password23', FALSE); INSERT INTO Veranstaltung (ort, raum, name, dauer) VALUES ('A', '101', 'Grundlagen der Programmierung', 2), From 50d650d4fa3c6143143d546e2b3f47b3ea4531df Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Mon, 1 Jul 2024 14:09:49 +0200 Subject: [PATCH 04/21] Update script.sql --- script.sql | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/script.sql b/script.sql index 05540e8..116d0ed 100644 --- a/script.sql +++ b/script.sql @@ -100,3 +100,34 @@ CREATE TABLE krank ( ('B', '208', 'Webtechnologien', 2), ('A', '109', 'Computergrafikgrundlagen', 2), ('B', '210', 'Maschinelles Lernen', 2); + + +INSERT INTO Veranstalter_Veranstaltung_Uhrzeit (uhrzeit_ID, tag, veranstaltung_ID) VALUES +(1, 1, 1), +(2, 1, 2), +(3, 1, 2), +(4, 1, 3), + +(1, 2, 4), +(2, 2, 4), +(3, 2, 5), +(4, 2, 6), +(5, 2, 6), + +(1, 3, 7), +(2, 3, 8), +(3, 3, 9), +(4, 3, 10), +(5, 3, 1), + +(1, 4, 2), +(2, 4, 2), +(3, 4, 3), +(4, 4, 4), +(5, 4, 4), + +(1, 5, 5), +(2, 5, 6), +(3, 5, 6), +(4, 5, 7), +(5, 5, 8); From 921fc738206c49647fba9caf1e44f48a37738aa4 Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Mon, 1 Jul 2024 14:10:47 +0200 Subject: [PATCH 05/21] Update script.sql --- script.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script.sql b/script.sql index 116d0ed..d5836ef 100644 --- a/script.sql +++ b/script.sql @@ -23,10 +23,10 @@ CREATE TABLE krank ( - CREATE VIEW studenten_veranstalterr AS + CREATE VIEW studenten_veranstalter AS SELECT matrikelnummer AS id, passwort, NULL AS admin FROM Studenten UNION ALL - SELECT ID, passwort, admin FROM Veranstalterrrr; + SELECT ID, passwort, admin FROM Veranstalter; From c01bba3459f50590c7adc87149db6b6bcda6cf88 Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Mon, 1 Jul 2024 17:49:30 +0200 Subject: [PATCH 06/21] Update DBPlan.cpp --- DBHandler/DBPlan.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/DBHandler/DBPlan.cpp b/DBHandler/DBPlan.cpp index f3d4284..c4cf818 100644 --- a/DBHandler/DBPlan.cpp +++ b/DBHandler/DBPlan.cpp @@ -42,7 +42,7 @@ void DBPlan::meldeKrank(int id) { try { pqxx::work worker(connectionObject); std::string query = - "DELETE FROM Veranstalterrrr WHERE ID = $1"; + "DELETE FROM Veranstalter WHERE ID = $1"; pqxx::result response = worker.exec_params(query, id); worker.commit(); @@ -53,4 +53,82 @@ void DBPlan::meldeKrank(int id) { } -}; \ No newline at end of file +}; + +void DBPlan::deleteVeranstaltung(int id) { + try { + pqxx::work worker(connObject); + std::string query = + "DELETE FROM Veranstaltung WHERE ID = $1;"; + + pqxx::result response = worker.exec_params(query, id); + worker.commit(); + + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + +} + + +void DBPlan::hinzufuegenVeranstaltung(std::string name, int dauer, std::string ort, std::string raum) { + try { + pqxx::work worker(connObject); + std::string query = + "INSERT INTO Veranstaltung (name, dauer, ort, raum) VALUES ($1, $2, $3, $4);"; + pqxx::result response = worker.exec_params(query, name, dauer, ort, raum); + worker.commit(); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + +} + + +void DBPlan:: hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, bool admin) { + try { + pqxx::work worker(connObject); + std::string query = + "INSERT INTO Veranstaltung (email, name, pw, admin) VALUES ($1, $2, $3, $4);"; + pqxx::result response = worker.exec_params(query, email, name, pw, admin); + worker.commit(); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + +} + + +void DBPlan::deleteStudent(int id) { + try { + pqxx::work worker(connObject); + std::string query = + "DELETE FROM studenten WHERE ID = $1;"; + pqxx::result response = worker.exec_params(query, id); + worker.commit(); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + +} + + +void DBPlan:: hinzufuegenStudent(std::string email, std::string name, std::string pw) { + + try { + pqxx::work worker(connObject); + std::string query = + "INSERT INTO studenten (email, name, pw) VALUES ($1, $2, $3);"; + pqxx::result response = worker.exec_params(query, email, name, pw); + worker.commit(); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + + +} From c2cfc4f7043bf9ea0ff6073e4ff6a39e6694fbe0 Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Mon, 1 Jul 2024 17:50:38 +0200 Subject: [PATCH 07/21] Update DBPlan.hpp --- DBHandler/DBPlan.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/DBHandler/DBPlan.hpp b/DBHandler/DBPlan.hpp index e138c1d..9208ca9 100644 --- a/DBHandler/DBPlan.hpp +++ b/DBHandler/DBPlan.hpp @@ -11,18 +11,18 @@ public: DBPlan(std::string connStr); void meldeKrank(int id); void meldeGesund(int id); - bool deleteVeranstaltung(int id); - bool hinzufuegenVeranstaltung(); //Zu Liste mit Veranstaltungen oder direkt in den Einsatzplan? + void deleteVeranstaltung(int id); + void hinzufuegenVeranstaltung(); //Zu Liste mit Veranstaltungen oder direkt in den Einsatzplan? void deleteVeranstalter(int id); - bool hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, bool admin); + void hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, bool admin); std::vector < std::vector> getVeranstalter(); - bool deleteStudent(int id); - bool hinzufuegenStudent(std::string email, std::string name, std::string pw); + void deleteStudent(int id); + void hinzufuegenStudent(std::string email, std::string name, std::string pw); std::vector < std::vector> getStudenten(); }; -#endif \ No newline at end of file +#endif From 6a6a2e3638a6d614e56b1b31ff8788ea356e94e7 Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Wed, 3 Jul 2024 10:14:17 +0200 Subject: [PATCH 08/21] Update DBPlan.hpp --- DBHandler/DBPlan.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DBHandler/DBPlan.hpp b/DBHandler/DBPlan.hpp index 9208ca9..c945c37 100644 --- a/DBHandler/DBPlan.hpp +++ b/DBHandler/DBPlan.hpp @@ -17,11 +17,11 @@ public: void deleteVeranstalter(int id); void hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, bool admin); - std::vector < std::vector> getVeranstalter(); + std::vector getVeranstalter(); void deleteStudent(int id); void hinzufuegenStudent(std::string email, std::string name, std::string pw); - std::vector < std::vector> getStudenten(); + std::vector getStudenten(); }; From 0b4a39ae85a538786749896f9684a564a680d364 Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Wed, 3 Jul 2024 10:21:03 +0200 Subject: [PATCH 09/21] Update script.sql --- script.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.sql b/script.sql index d5836ef..ad2e00f 100644 --- a/script.sql +++ b/script.sql @@ -19,7 +19,7 @@ CREATE TABLE Studenten ( CREATE TABLE krank ( veranstalter_ID INTEGER, - FOREIGN KEY (veranstalter_ID) REFERENCES veranstalterrrr(ID) ON DELETE CASCADE); + FOREIGN KEY (veranstalter_ID) REFERENCES veranstalter(ID) ON DELETE CASCADE); From 2139dacdc19187d3b20146a804cbb0d91a636583 Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Thu, 4 Jul 2024 16:30:56 +0200 Subject: [PATCH 10/21] Update DBPlan.hpp --- DBHandler/DBPlan.hpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/DBHandler/DBPlan.hpp b/DBHandler/DBPlan.hpp index c945c37..ecc6e97 100644 --- a/DBHandler/DBPlan.hpp +++ b/DBHandler/DBPlan.hpp @@ -7,21 +7,36 @@ #include class DBPlan : public DBHandler { +private: + std::string getDauer(std::string tag, std::string stunde); + void addFirstOfDayTwo(std::string tag); + void addTwoHour(std::string tag, std::string stunde); + void addFirstOfDayFour(std::string tag); + void upperHour(std::string tag, std::string stunde); + void addFourHour(std::string tag, std::string stunde); + + void updateStandort(std::string tag, std::string stunde); public: DBPlan(std::string connStr); - void meldeKrank(int id); - void meldeGesund(int id); - void deleteVeranstaltung(int id); - void hinzufuegenVeranstaltung(); //Zu Liste mit Veranstaltungen oder direkt in den Einsatzplan? + void meldeKrank(std::string id, std::string zeit); + void meldeGesund(std::string id); + void deleteVeranstaltung(std::string id); + void hinzufuegenVeranstaltung(std::string name, std::string dauer, std::string ort, std::string raum); - void deleteVeranstalter(int id); - void hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, bool admin); - std::vector getVeranstalter(); + void deleteVeranstalter(std::string id); + void hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, std::string admin); + - void deleteStudent(int id); + void deleteStudent(std::string id); void hinzufuegenStudent(std::string email, std::string name, std::string pw); - std::vector getStudenten(); + + + void createPlan(); + void incarbeitszeit(std::string tag, std::string stunde, std::string amount); + + + void clear(); }; From 5260b92651bbea7a7559580543381945b9bd6be6 Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Thu, 4 Jul 2024 16:31:45 +0200 Subject: [PATCH 11/21] Update DBPlan.cpp --- DBHandler/DBPlan.cpp | 304 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 254 insertions(+), 50 deletions(-) diff --git a/DBHandler/DBPlan.cpp b/DBHandler/DBPlan.cpp index c4cf818..4f1957a 100644 --- a/DBHandler/DBPlan.cpp +++ b/DBHandler/DBPlan.cpp @@ -1,9 +1,10 @@ #include "DBPlan.hpp" -DBPlan::DBPlan(std::string connStr) : DBHandler(connStr) {}; +DBPlan::DBPlan(std::string connStr) : DBHandler(connStr) { +}; -void DBPlan::meldeKrank(int id) { +void DBPlan::meldeKrank(std::string id, std::string zeit) { try { pqxx::work worker(connectionObject); @@ -13,51 +14,51 @@ void DBPlan::meldeKrank(int id) { pqxx::result response = worker.exec_params(query, id); worker.commit(); } - catch (const std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; - } } +} - void DBPlan::meldeGesund(int id) { - try { - pqxx::work worker(connectionObject); - std::string query = - "DELETE FROM krank WHERE veranstalter_ID = $1 ;"; - - pqxx::result response = worker.exec_params(query, id); - worker.commit(); - } - catch (const std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; - } - } - - - - - - void DBPlan:: deleteVeranstalter(int id) { - try { - pqxx::work worker(connectionObject); - std::string query = - "DELETE FROM Veranstalter WHERE ID = $1"; - - pqxx::result response = worker.exec_params(query, id); - worker.commit(); - } - catch (const std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; - } - } - - -}; - -void DBPlan::deleteVeranstaltung(int id) { +void DBPlan::meldeGesund(std::string id) { try { - pqxx::work worker(connObject); + pqxx::work worker(connectionObject); + std::string query = + "DELETE FROM krank WHERE veranstalter_ID = $1 ;"; + + pqxx::result response = worker.exec_params(query, id); + worker.commit(); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } +} + + + + + +void DBPlan::deleteVeranstalter(std::string id) { + try { + pqxx::work worker(connectionObject); + std::string query = + "DELETE FROM Veranstalter WHERE ID = $1"; + + pqxx::result response = worker.exec_params(query, id); + worker.commit(); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } +} + + + + +void DBPlan::deleteVeranstaltung(std::string id) { + try { + pqxx::work worker(connectionObject); std::string query = "DELETE FROM Veranstaltung WHERE ID = $1;"; @@ -72,9 +73,9 @@ void DBPlan::deleteVeranstaltung(int id) { } -void DBPlan::hinzufuegenVeranstaltung(std::string name, int dauer, std::string ort, std::string raum) { +void DBPlan::hinzufuegenVeranstaltung(std::string name, std::string dauer, std::string ort, std::string raum) { try { - pqxx::work worker(connObject); + pqxx::work worker(connectionObject); std::string query = "INSERT INTO Veranstaltung (name, dauer, ort, raum) VALUES ($1, $2, $3, $4);"; pqxx::result response = worker.exec_params(query, name, dauer, ort, raum); @@ -87,9 +88,9 @@ void DBPlan::hinzufuegenVeranstaltung(std::string name, int dauer, std::string o } -void DBPlan:: hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, bool admin) { +void DBPlan::hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, std::string admin) { try { - pqxx::work worker(connObject); + pqxx::work worker(connectionObject); std::string query = "INSERT INTO Veranstaltung (email, name, pw, admin) VALUES ($1, $2, $3, $4);"; pqxx::result response = worker.exec_params(query, email, name, pw, admin); @@ -102,9 +103,9 @@ void DBPlan:: hinzufuegenVeranstalter(std::string email, std::string name, std:: } -void DBPlan::deleteStudent(int id) { +void DBPlan::deleteStudent(std::string id) { try { - pqxx::work worker(connObject); + pqxx::work worker(connectionObject); std::string query = "DELETE FROM studenten WHERE ID = $1;"; pqxx::result response = worker.exec_params(query, id); @@ -117,10 +118,10 @@ void DBPlan::deleteStudent(int id) { } -void DBPlan:: hinzufuegenStudent(std::string email, std::string name, std::string pw) { +void DBPlan::hinzufuegenStudent(std::string email, std::string name, std::string pw) { try { - pqxx::work worker(connObject); + pqxx::work worker(connectionObject); std::string query = "INSERT INTO studenten (email, name, pw) VALUES ($1, $2, $3);"; pqxx::result response = worker.exec_params(query, email, name, pw); @@ -132,3 +133,206 @@ void DBPlan:: hinzufuegenStudent(std::string email, std::string name, std::strin } + + + +std::string DBPlan::getDauer(std::string tag, std::string stunde) { + try { + + pqxx::work worker(connectionObject); + std::string query = + "SELECT dauer FROM Veranstaltung WHERE ID = (SELECT Veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2);"; + pqxx::result response = worker.exec_params(query, stunde, tag); + worker.commit(); + + + return response[0][0].c_str(); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } +} + + + + + + + + + + +void DBPlan::addFirstOfDayTwo(std::string tag) { + try { + pqxx::work worker(connectionObject); + std::string query = + "UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT ID FROM Veranstalter WHERE arbeitszeit <= 16 LIMIT 1) " + "WHERE uhrzeit_id = 1 AND tag = $1;"; + pqxx::result response = worker.exec_params(query, tag); + worker.commit(); + + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } +} + +void DBPlan::addTwoHour(std::string tag, std::string stunde) { + try { + + std::string prevStunde = std::to_string(std::stoi(stunde) - 1); + + std::cout << " prevStunde: " << prevStunde << " Tag: " << tag << " stunde " << stunde << std::endl; + pqxx::work worker(connectionObject); + std::string query = + "UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter " + "WHERE arbeitszeit <= 16 " + "AND(standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) " + "AND ID != (SELECT veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) " + "ORDER BY random() LIMIT 1) " + "WHERE uhrzeit_id = $3 AND tag = $4;"; + pqxx::result response = worker.exec_params(query, prevStunde, tag, stunde, tag); + worker.commit(); + + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } +} + +void DBPlan::addFirstOfDayFour(std::string tag) { + try { + pqxx::work worker(connectionObject); + std::string query = + "UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT ID FROM Veranstalter WHERE arbeitszeit <= 14 LIMIT 1) " + "WHERE uhrzeit_id = 1 AND tag = $1;"; + pqxx::result response = worker.exec_params(query, tag); + worker.commit(); + + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } +} + +void DBPlan::addFourHour(std::string tag, std::string stunde) { + try { + + std::string prevStunde = std::to_string(std::stoi(stunde) - 1); + pqxx::work worker(connectionObject); + std::string query = + "UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter " + "WHERE arbeitszeit <= 14 " + "AND(standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) " + "AND ID != (SELECT veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) " + "ORDER BY random() LIMIT 1) " + "WHERE uhrzeit_id = $3 AND tag = $4;"; + pqxx::result response = worker.exec_params(query, prevStunde, tag, stunde, tag); + worker.commit(); + + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } +} + +void DBPlan::upperHour(std::string tag, std::string stunde) { + try { + + std::string nextStunde = std::to_string(std::stoi(stunde) + 1); + + std::cout << "tag: " << tag << " stunde: " << stunde << " prevStunde " << nextStunde << std::endl; + pqxx::work worker(connectionObject); + std::string query = + "UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)" + "WHERE uhrzeit_id = $3 AND tag = $2;"; + pqxx::result response = worker.exec_params(query, stunde, tag, nextStunde); + worker.commit(); + + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } +} + + +void DBPlan::updateStandort(std::string tag, std::string stunde) { + try { + + + pqxx::work worker(connectionObject); + std::string query = + "UPDATE Veranstalter SET standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT Veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) WHERE ID = (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2);"; + pqxx::result response = worker.exec_params(query, stunde, tag); + worker.commit(); + + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } +} + +void DBPlan::incarbeitszeit(std::string tag, std::string stunde, std::string amount) { + try { + + + pqxx::work worker(connectionObject); + + std::string query = + "UPDATE Veranstalter SET arbeitszeit = arbeitszeit + $1 WHERE ID = (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $2 AND tag = $3);"; + + pqxx::result response = worker.exec_params(query,amount, stunde, tag); + worker.commit(); + + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } +} + +void DBPlan::createPlan() { + + + + try { + for (int tag = 1; tag < 6; tag++) { + std::string tagStr = std::to_string(tag); + for (int stunde = 1; stunde < 6; stunde++) { + std::string stundeStr = std::to_string(stunde); + //get dauer of next class + + if (std::stoi(getDauer(tagStr, stundeStr)) == 2) { + if (stunde == 1) { + addFirstOfDayTwo(tagStr); + } + else { + addTwoHour(tagStr, stundeStr); + } + updateStandort(tagStr, stundeStr); + incarbeitszeit(tagStr, stundeStr, "2"); + } + else { + if (stunde == 1) { + addFirstOfDayFour(tagStr); + + } + else { + addFourHour(tagStr, stundeStr); + } + upperHour(tagStr, stundeStr); + incarbeitszeit(tagStr, stundeStr, "4"); + updateStandort(tagStr, stundeStr); + stunde++; + } + + } + + } + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + +} + + From bfc032c39fe5bcde540e87e6538e01f4e3ccd630 Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Thu, 4 Jul 2024 20:24:00 +0200 Subject: [PATCH 12/21] Update DBPlan.cpp --- DBHandler/DBPlan.cpp | 91 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 9 deletions(-) diff --git a/DBHandler/DBPlan.cpp b/DBHandler/DBPlan.cpp index 4f1957a..73d0c01 100644 --- a/DBHandler/DBPlan.cpp +++ b/DBHandler/DBPlan.cpp @@ -4,15 +4,87 @@ DBPlan::DBPlan(std::string connStr) : DBHandler(connStr) { }; -void DBPlan::meldeKrank(std::string id, std::string zeit) { +void DBPlan::vertretung(std::string tag, std::string stunde, std::string dauer) { + try { + std::string prevStunde = std::to_string(std::stoi(stunde) - 1); + std::string cap = std::to_string(18 - std::stoi(dauer)); + std::string nextStunde; + std::string nextTag = tag; + std::string prevTag = tag; + if (dauer == "4") { + + nextStunde = std::to_string(std::stoi(stunde) + 2); + std::cout << nextStunde << std::endl; + } + else { + nextStunde = std::to_string(std::stoi(stunde) + 1); + std::cout << nextStunde << std::endl; + } + + if (prevStunde == "0") { + prevStunde = "5"; + prevTag = std::to_string(std::stoi(tag) - 1); + if (prevTag == "0") { + prevTag = "5"; + } + } + + if (nextStunde == "6") { + nextStunde = "1"; + nextTag = std::to_string(std::stoi(tag)+1); + if (nextTag == "6") { + nextTag = "1"; + } + } + + pqxx::work worker(connectionObject); + + + std::string query = + "UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = " + "(SELECT ID FROM Veranstalter WHERE ID != (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2) " + "AND ID != (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $3 AND tag = $4) LIMIT 1) WHERE uhrzeit_id = $5 AND tag = $6; "; + + + pqxx::result response = worker.exec_params(query, prevStunde, prevTag, nextStunde, nextTag, stunde, tag); + + worker.commit(); + + + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + + } +} + +void DBPlan::sucheVertretung(std::string tag, std::string stunde) { + std::string dauer = getDauer(tag, stunde); + vertretung(tag, stunde, dauer); + incarbeitszeit(tag, stunde, dauer); + + if (dauer == "4") { + upperHour(tag, stunde); + } + + + +} + +void DBPlan::meldeKrank(std::string id, std::string tag, std::string stunde) { try { + pqxx::work worker(connectionObject); std::string query = - "INSERT INTO krank (veranstalter_ID) VALUES($1);"; + "UPDATE Veranstalter SET krank = TRUE WHERE ID = $1"; pqxx::result response = worker.exec_params(query, id); worker.commit(); + + sucheVertretung(tag, stunde); + meldeGesund(id); + } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; @@ -25,7 +97,7 @@ void DBPlan::meldeGesund(std::string id) { try { pqxx::work worker(connectionObject); std::string query = - "DELETE FROM krank WHERE veranstalter_ID = $1 ;"; + "UPDATE Veranstalter SET krank = FALSE WHERE ID = $1"; pqxx::result response = worker.exec_params(query, id); worker.commit(); @@ -138,11 +210,12 @@ void DBPlan::hinzufuegenStudent(std::string email, std::string name, std::string std::string DBPlan::getDauer(std::string tag, std::string stunde) { try { - pqxx::work worker(connectionObject); std::string query = "SELECT dauer FROM Veranstaltung WHERE ID = (SELECT Veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2);"; + pqxx::result response = worker.exec_params(query, stunde, tag); + worker.commit(); @@ -166,7 +239,7 @@ void DBPlan::addFirstOfDayTwo(std::string tag) { try { pqxx::work worker(connectionObject); std::string query = - "UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT ID FROM Veranstalter WHERE arbeitszeit <= 16 LIMIT 1) " + "UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT ID FROM Veranstalter WHERE arbeitszeit <= 16 AND krank = FALSE LIMIT 1) " "WHERE uhrzeit_id = 1 AND tag = $1;"; pqxx::result response = worker.exec_params(query, tag); worker.commit(); @@ -186,7 +259,7 @@ void DBPlan::addTwoHour(std::string tag, std::string stunde) { pqxx::work worker(connectionObject); std::string query = "UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter " - "WHERE arbeitszeit <= 16 " + "WHERE arbeitszeit <= 16 AND krank = FALSE " "AND(standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) " "AND ID != (SELECT veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) " "ORDER BY random() LIMIT 1) " @@ -204,7 +277,7 @@ void DBPlan::addFirstOfDayFour(std::string tag) { try { pqxx::work worker(connectionObject); std::string query = - "UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT ID FROM Veranstalter WHERE arbeitszeit <= 14 LIMIT 1) " + "UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT ID FROM Veranstalter WHERE arbeitszeit <= 14 AND krank = FALSE LIMIT 1) " "WHERE uhrzeit_id = 1 AND tag = $1;"; pqxx::result response = worker.exec_params(query, tag); worker.commit(); @@ -222,7 +295,7 @@ void DBPlan::addFourHour(std::string tag, std::string stunde) { pqxx::work worker(connectionObject); std::string query = "UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter " - "WHERE arbeitszeit <= 14 " + "WHERE arbeitszeit <= 14 AND krank = FALSE " "AND(standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) " "AND ID != (SELECT veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) " "ORDER BY random() LIMIT 1) " @@ -241,7 +314,6 @@ void DBPlan::upperHour(std::string tag, std::string stunde) { std::string nextStunde = std::to_string(std::stoi(stunde) + 1); - std::cout << "tag: " << tag << " stunde: " << stunde << " prevStunde " << nextStunde << std::endl; pqxx::work worker(connectionObject); std::string query = "UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)" @@ -336,3 +408,4 @@ void DBPlan::createPlan() { } + From 79d6acf34cde2859b8d9d00e21f6f312f9003199 Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Thu, 4 Jul 2024 20:26:24 +0200 Subject: [PATCH 13/21] Update DBPlan.cpp --- DBHandler/DBPlan.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/DBHandler/DBPlan.cpp b/DBHandler/DBPlan.cpp index 73d0c01..60c74c3 100644 --- a/DBHandler/DBPlan.cpp +++ b/DBHandler/DBPlan.cpp @@ -1,3 +1,9 @@ +/* TO DO +deleteVeranstalter() und deleteVeranstaltung() Foreignkey Constraint fixen +Funktion getEinsatzplan() erstellen +*/ + + #include "DBPlan.hpp" DBPlan::DBPlan(std::string connStr) : DBHandler(connStr) { From f20b2f6425bcdb7c5d339069fa5db7332d6a52d5 Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Thu, 4 Jul 2024 20:27:31 +0200 Subject: [PATCH 14/21] Update DBPlan.cpp --- DBHandler/DBPlan.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DBHandler/DBPlan.cpp b/DBHandler/DBPlan.cpp index 60c74c3..b3b82ae 100644 --- a/DBHandler/DBPlan.cpp +++ b/DBHandler/DBPlan.cpp @@ -1,6 +1,9 @@ /* TO DO deleteVeranstalter() und deleteVeranstaltung() Foreignkey Constraint fixen -Funktion getEinsatzplan() erstellen +Funktion getEinsatzplan() erstellen : psql prompt: SELECT tag, u.anfangszeit, u.endzeit, o.ort, o.name, v.name FROM Veranstalter_Veranstaltung_Uhrzeit LEFT JOIN Veranstalter v ON Veranstalter_Veranstaltung_Uhrzeit.veranstalter_ID = v.ID + LEFT JOIN Uhrzeit u ON Veranstalter_Veranstaltung_Uhrzeit.uhrzeit_ID = u.ID + LEFT JOIN Veranstaltung o ON Veranstalter_Veranstaltung_Uhrzeit.veranstaltung_ID = o.ID + ORDER BY tag, uhrzeit_ID; */ From 85d1601889e14336cb750e646eee11de56d65e9e Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Sat, 6 Jul 2024 10:08:12 +0200 Subject: [PATCH 15/21] Update DBPlan.hpp --- DBHandler/DBPlan.hpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/DBHandler/DBPlan.hpp b/DBHandler/DBPlan.hpp index ecc6e97..263b1a4 100644 --- a/DBHandler/DBPlan.hpp +++ b/DBHandler/DBPlan.hpp @@ -8,21 +8,27 @@ class DBPlan : public DBHandler { private: + //Functions needed for creation and updating of the plan std::string getDauer(std::string tag, std::string stunde); void addFirstOfDayTwo(std::string tag); void addTwoHour(std::string tag, std::string stunde); void addFirstOfDayFour(std::string tag); void upperHour(std::string tag, std::string stunde); void addFourHour(std::string tag, std::string stunde); - + void sucheVertretung(std::string tag, std::string stunde); + void vertretung(std::string tag, std::string stunde, std::string dauer); + void deleteVeranstalterForeign(std::string id); + void deleteVeranstaltungForeign(std::string id); void updateStandort(std::string tag, std::string stunde); + void incarbeitszeit(std::string tag, std::string stunde, std::string amount); public: DBPlan(std::string connStr); - void meldeKrank(std::string id, std::string zeit); + + void meldeKrank(std::string id, std::string tag, std::string stunde); void meldeGesund(std::string id); void deleteVeranstaltung(std::string id); void hinzufuegenVeranstaltung(std::string name, std::string dauer, std::string ort, std::string raum); - + void deleteVeranstalter(std::string id); void hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, std::string admin); @@ -33,10 +39,11 @@ public: void createPlan(); - void incarbeitszeit(std::string tag, std::string stunde, std::string amount); + + //Each string in form of (tag , anfangszeit , endzeit , Ort , Veranstaltung , Mitarbeiter , mitarbeiterID , ) + std::vector getPlan(); - void clear(); }; From 8837e0d61d5a446fa469356ae0769eafed7487a7 Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Sat, 6 Jul 2024 10:09:05 +0200 Subject: [PATCH 16/21] Update DBPlan.cpp --- DBHandler/DBPlan.cpp | 83 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 13 deletions(-) diff --git a/DBHandler/DBPlan.cpp b/DBHandler/DBPlan.cpp index b3b82ae..9a3f0bb 100644 --- a/DBHandler/DBPlan.cpp +++ b/DBHandler/DBPlan.cpp @@ -1,12 +1,3 @@ -/* TO DO -deleteVeranstalter() und deleteVeranstaltung() Foreignkey Constraint fixen -Funktion getEinsatzplan() erstellen : psql prompt: SELECT tag, u.anfangszeit, u.endzeit, o.ort, o.name, v.name FROM Veranstalter_Veranstaltung_Uhrzeit LEFT JOIN Veranstalter v ON Veranstalter_Veranstaltung_Uhrzeit.veranstalter_ID = v.ID - LEFT JOIN Uhrzeit u ON Veranstalter_Veranstaltung_Uhrzeit.uhrzeit_ID = u.ID - LEFT JOIN Veranstaltung o ON Veranstalter_Veranstaltung_Uhrzeit.veranstaltung_ID = o.ID - ORDER BY tag, uhrzeit_ID; -*/ - - #include "DBPlan.hpp" DBPlan::DBPlan(std::string connStr) : DBHandler(connStr) { @@ -119,8 +110,24 @@ void DBPlan::meldeGesund(std::string id) { +void DBPlan::deleteVeranstalterForeign(std::string id) { + try { + pqxx::work worker(connectionObject); + std::string query = + "UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = NULL WHERE Veranstalter_ID = $1;"; + + pqxx::result response = worker.exec_params(query, id); + worker.commit(); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } +} void DBPlan::deleteVeranstalter(std::string id) { + + deleteVeranstalterForeign(id); + try { pqxx::work worker(connectionObject); std::string query = @@ -135,17 +142,30 @@ void DBPlan::deleteVeranstalter(std::string id) { } - - -void DBPlan::deleteVeranstaltung(std::string id) { +void DBPlan::deleteVeranstaltungForeign(std::string id) { try { pqxx::work worker(connectionObject); std::string query = - "DELETE FROM Veranstaltung WHERE ID = $1;"; + "UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstaltung_ID = NULL WHERE Veranstalter_ID = $1;"; pqxx::result response = worker.exec_params(query, id); worker.commit(); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } +} +void DBPlan::deleteVeranstaltung(std::string id) { + deleteVeranstaltungForeign(id); + + try { + pqxx::work worker(connectionObject); + std::string query = + "DELETE FROM Veranstaltung WHERE ID = $1"; + + pqxx::result response = worker.exec_params(query, id); + worker.commit(); } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; @@ -418,3 +438,40 @@ void DBPlan::createPlan() { +std::vector DBPlan::getPlan() { + try { + + std::vector plan; + + pqxx::work worker(connectionObject); + + std::string query = + "SELECT tag, u.anfangszeit, u.endzeit, o.ort, o.name, v.name, v.ID FROM Veranstalter_Veranstaltung_Uhrzeit LEFT JOIN Veranstalter v ON Veranstalter_Veranstaltung_Uhrzeit.veranstalter_ID = v.ID " + "LEFT JOIN Uhrzeit u ON Veranstalter_Veranstaltung_Uhrzeit.uhrzeit_ID = u.ID " + "LEFT JOIN Veranstaltung o ON Veranstalter_Veranstaltung_Uhrzeit.veranstaltung_ID = o.ID " + "ORDER BY tag, uhrzeit_ID;"; + + pqxx::result response = worker.exec(query); + worker.commit(); + + for (const auto& row : response) { + std::string rowstring; + for (const auto& col : row) { + rowstring.append(col.c_str()); + rowstring.append(" , "); + } + plan.push_back(rowstring); + + } + + return plan; + + + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } +} + + + From 696f8f724fc68deea747bc45f9fe7b7debfc74ea Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Sat, 6 Jul 2024 10:10:57 +0200 Subject: [PATCH 17/21] Update DBLogin.cpp --- DBHandler/DBLogin.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/DBHandler/DBLogin.cpp b/DBHandler/DBLogin.cpp index e942725..344e8b0 100644 --- a/DBHandler/DBLogin.cpp +++ b/DBHandler/DBLogin.cpp @@ -11,30 +11,31 @@ return 1 if admin | 0 if not admin | -1 if failed */ -int DBLogin::checkValidLogin(int id, std::string pw) { - +int DBLogin::checkValidLogin(std::string id, std::string pw) { + try { - pqxx::work worker(connectionObject); + pqxx::work worker(connectionObject); - std::string query = - "SELECT admin FROM studenten_veranstalterr WHERE id = $1 AND passwort = $2"; + std::string query = + "SELECT admin FROM studenten_veranstalter WHERE id = $1 AND passwort = $2"; - pqxx::result response = worker.exec_params(query, id, pw); + pqxx::result response = worker.exec_params(query, id, pw); - if (response.affected_rows() > 0) { + if (response.affected_rows() > 0) { - std::cout << response[0][0] << std::endl; - if (response[0][0].is_null()) - return 0; - return response[0][0].as(); + + if (response[0][0].is_null()) + return 0; + return response[0][0].as(); + } + + return -1; + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; } - return -1; -} -catch (const std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; } -} From 97eecd3ad2e81b1da1294bb422d093213ee19b9c Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Sat, 6 Jul 2024 10:11:30 +0200 Subject: [PATCH 18/21] Update DBLogin.hpp --- DBHandler/DBLogin.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DBHandler/DBLogin.hpp b/DBHandler/DBLogin.hpp index f29e0c0..e348fed 100644 --- a/DBHandler/DBLogin.hpp +++ b/DBHandler/DBLogin.hpp @@ -10,9 +10,9 @@ public: return 1 if admin | 0 if not admin | -1 if failed */ - int checkValidLogin(int id, std::string pw); + int checkValidLogin(std::string id, std::string pw); }; -#endif \ No newline at end of file +#endif From e91613690a0475b6319df2335e586ad91059c02e Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Sat, 6 Jul 2024 10:13:40 +0200 Subject: [PATCH 19/21] Update script.sql --- script.sql | 87 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 34 deletions(-) diff --git a/script.sql b/script.sql index ad2e00f..c58a44b 100644 --- a/script.sql +++ b/script.sql @@ -1,25 +1,51 @@ + +DROP VIEW studenten_veranstalter; + +DROP TABLE Veranstalter_Veranstaltung_Uhrzeit; +DROP TABLE Studenten; +DROP TABLE Veranstalter; +DROP TABLE Uhrzeit; +DROP TABLE veranstaltung; +DROP SEQUENCE global_id_seq; + + + + + CREATE SEQUENCE global_id_seq; CREATE TABLE Studenten ( - matrikelnummer INTEGER PRIMARY KEY DEFAULT nextval('global_id_seq'), - "name VARCHAR(30) NOT NULL, - "email VARCHAR(30) NOT NULL, - "passwort VARCHAR(30) NOT NULL); + matrikelnummer INTEGER PRIMARY KEY DEFAULT nextval('global_id_seq'), + name VARCHAR(30) NOT NULL, + email VARCHAR(30) NOT NULL, + passwort VARCHAR(30) NOT NULL +); - "CREATE TABLE Veranstalter ( - ID INTEGER PRIMARY KEY DEFAULT nextval('global_id_seq'), - name VARCHAR(30), - email VARCHAR(30), - passwort VARCHAR(30), - admin BOOLEAN NOT NULL DEFAULT(FALSE) - - ); +CREATE OR REPLACE FUNCTION random_between_two() +RETURNS VARCHAR AS $$ +BEGIN + IF random() < 0.5 THEN + RETURN 'A'; + ELSE + RETURN 'B'; + END IF; +END; +$$ LANGUAGE plpgsql; + + +CREATE TABLE Veranstalter ( + ID INTEGER PRIMARY KEY DEFAULT nextval('global_id_seq'), + name VARCHAR(30), + email VARCHAR(30), + passwort VARCHAR(30), + arbeitszeit INTEGER DEFAULT 0, + standort VARCHAR(30) DEFAULT random_between_two(), + krank BOOLEAN DEFAULT FALSE, + admin BOOLEAN NOT NULL DEFAULT FALSE +); -CREATE TABLE krank ( - veranstalter_ID INTEGER, - FOREIGN KEY (veranstalter_ID) REFERENCES veranstalter(ID) ON DELETE CASCADE); @@ -33,8 +59,10 @@ CREATE TABLE krank ( CREATE TABLE Veranstaltung ( ID SERIAL PRIMARY KEY, ort VARCHAR(30) NOT NULL, - raum VARCHAR(30) NOT NULL, - name VARCHAR(30) NOT NULL ); + raum INTEGER NOT NULL, + name VARCHAR(90) NOT NULL, + dauer INTEGER NOT NULL + ); @@ -54,10 +82,10 @@ CREATE TABLE krank ( ('16:00:00', '18:00:00'); - CREATE TABLE Veranstalter_Veranstaltung_Uhrzeit ( + CREATE TABLE Veranstalter_Veranstaltung_Uhrzeit ( uhrzeit_ID INTEGER REFERENCES Uhrzeit(ID), tag INTEGER NOT NULL, - veranstalter_ID INTEGER REFERNECES Veranstalter(ID), + veranstalter_ID INTEGER REFERENCES Veranstalter(ID), veranstaltung_ID INTEGER REFERENCES Veranstaltung(ID), PRIMARY KEY(uhrzeit_ID, tag) ); @@ -75,19 +103,8 @@ CREATE TABLE krank ( ('net_knight', 'user8@example.com', 'password8', FALSE), ('bit_boss', 'user9@example.com', 'password9', FALSE), ('sys_sensei', 'user10@example.com', 'password10', FALSE), -('crypto_champ', 'user11@example.com', 'password11', FALSE), -('cloud_conqueror', 'user12@example.com', 'password12', FALSE), -('hack_whiz', 'user13@example.com', 'password13', FALSE), -('matrix_mage', 'user14@example.com', 'password14', FALSE), -('app_artisan', 'user15@example.com', 'password15', FALSE), -('ai_architect', 'user16@example.com', 'password16', FALSE), -('tech_titan', 'user17@example.com', 'password17', FALSE), -('proto_pro', 'user18@example.com', 'password18', FALSE), -('alg_adept', 'user19@example.com', 'password19', FALSE), -('data_diver', 'user20@example.com', 'password20', FALSE), -('web_warrior', 'user21@example.com', 'password21', FALSE), -('os_overlord', 'user22@example.com', 'password22', FALSE), -('kernel_keeper', 'user23@example.com', 'password23', FALSE); +('crypto_champ', 'user11@example.com', 'password11', FALSE); + INSERT INTO Veranstaltung (ort, raum, name, dauer) VALUES ('A', '101', 'Grundlagen der Programmierung', 2), @@ -104,9 +121,10 @@ CREATE TABLE krank ( INSERT INTO Veranstalter_Veranstaltung_Uhrzeit (uhrzeit_ID, tag, veranstaltung_ID) VALUES (1, 1, 1), -(2, 1, 2), -(3, 1, 2), +(2, 1, 7), +(3, 1, 8), (4, 1, 3), +(5, 1, 10), (1, 2, 4), (2, 2, 4), @@ -131,3 +149,4 @@ INSERT INTO Veranstalter_Veranstaltung_Uhrzeit (uhrzeit_ID, tag, veranstaltung_I (3, 5, 6), (4, 5, 7), (5, 5, 8); + From 8d7a3acd09ae84f6636e811aa7e897e48c18de7c Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Sat, 6 Jul 2024 10:14:03 +0200 Subject: [PATCH 20/21] Update script.sql --- script.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/script.sql b/script.sql index c58a44b..dc2a8b4 100644 --- a/script.sql +++ b/script.sql @@ -1,6 +1,5 @@ DROP VIEW studenten_veranstalter; - DROP TABLE Veranstalter_Veranstaltung_Uhrzeit; DROP TABLE Studenten; DROP TABLE Veranstalter; From 1c8fa4c7c4544d36aff8bb1b2fac650c7b0f7561 Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Sat, 6 Jul 2024 10:18:09 +0200 Subject: [PATCH 21/21] Create README --- README | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..316fe18 --- /dev/null +++ b/README @@ -0,0 +1,2 @@ +Code written with libpqxx-version 7.4.1 +install-guide: http://en.wiki.imlint.org/Pqxx_tutorial