fix styling, refactor some variables, simplified some code
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
#include "DBHandler.hpp"
|
||||
|
||||
#include <iostream>
|
||||
//"host = localhost port = 5432 dbname = postgres user = postgres password = AlbertBridge1?"
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
14
src/Core/DBHandler/DBHandler/DBHandler.cpp
Normal file
14
src/Core/DBHandler/DBHandler/DBHandler.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "DBHandler.hpp"
|
||||
|
||||
DBHandler::DBHandler(std::string connStr) :
|
||||
connectionObject(connStr.c_str( )) {
|
||||
try {
|
||||
if (connectionObject.is_open( ))
|
||||
fmt::print("Databased connected");
|
||||
else
|
||||
fmt::print("Failed to connect to Databased");
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
};
|
||||
@@ -1,7 +1,8 @@
|
||||
#ifndef DBHANDLER_HPP_
|
||||
#define DBHANDLER_HPP_
|
||||
#pragma onc
|
||||
|
||||
#include <pqxx/pqxx>
|
||||
#include <string>
|
||||
#include <fmt/core.h>
|
||||
|
||||
class DBHandler {
|
||||
protected:
|
||||
@@ -10,5 +11,3 @@ protected:
|
||||
public:
|
||||
DBHandler(std::string connStr);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,40 +0,0 @@
|
||||
#include "DBLogin.hpp"
|
||||
#include <iostream>
|
||||
|
||||
DBLogin::DBLogin(std::string connStr) : DBHandler(connStr) {};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
return 1 if admin | 0 if not admin | -1 if failed
|
||||
|
||||
*/
|
||||
|
||||
int DBLogin::checkValidLogin(std::string id, std::string pw) {
|
||||
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
std::string query =
|
||||
"SELECT admin FROM studenten_veranstalter WHERE id = $1 AND passwort = $2";
|
||||
|
||||
pqxx::result response = worker.exec_params(query, id, pw);
|
||||
|
||||
if (response.affected_rows() > 0) {
|
||||
|
||||
|
||||
if (response[0][0].is_null())
|
||||
return 0;
|
||||
return response[0][0].as<bool>();
|
||||
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#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(std::string id, std::string pw);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
26
src/Core/DBHandler/DBLogin/DBLogin.cpp
Normal file
26
src/Core/DBHandler/DBLogin/DBLogin.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "DBLogin.hpp"
|
||||
|
||||
DBLogin::DBLogin(std::string connStr) : DBHandler(connStr) { };
|
||||
|
||||
int DBLogin::checkValidLogin(std::string id, std::string pw) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
std::string query =
|
||||
"SELECT admin FROM studenten_veranstalter WHERE id = $1 AND passwort = $2";
|
||||
|
||||
pqxx::result response = worker.exec_params(query, id, pw);
|
||||
|
||||
if (response.affected_rows( ) > 0) {
|
||||
if (response[0][0].is_null( ))
|
||||
return 0;
|
||||
return response[0][0].as<bool>( );
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::printf("ERROR: %s", e.what( ));
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
18
src/Core/DBHandler/DBLogin/DBLogin.hpp
Normal file
18
src/Core/DBHandler/DBLogin/DBLogin.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <fmt/printf.h>
|
||||
|
||||
#include "../DBHandler/DBHandler.hpp"
|
||||
|
||||
class DBLogin : public DBHandler {
|
||||
public:
|
||||
DBLogin(std::string connStr);
|
||||
|
||||
/**
|
||||
* @brief Tries to login the user
|
||||
* @param id user id
|
||||
* @param pw user password
|
||||
* @return returns 1 if admin and 0 if not
|
||||
*/
|
||||
int checkValidLogin(std::string id, std::string pw);
|
||||
};
|
||||
@@ -1,483 +0,0 @@
|
||||
#include "DBPlan.hpp"
|
||||
|
||||
DBPlan::DBPlan(std::string connStr) : DBHandler(connStr) {
|
||||
};
|
||||
|
||||
|
||||
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 =
|
||||
"UPDATE Veranstalter SET krank = TRUE WHERE ID = $1";
|
||||
|
||||
pqxx::result response = worker.exec_params(query, id);
|
||||
worker.commit();
|
||||
|
||||
sucheVertretung(tag, stunde);
|
||||
meldeGesund(id);
|
||||
versendeEmails();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DBPlan::meldeGesund(std::string id) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"UPDATE Veranstalter SET krank = FALSE 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::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();
|
||||
versendeEmails();
|
||||
}
|
||||
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 =
|
||||
"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::deleteVeranstaltungForeign(std::string id) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstaltung_ID = NULL WHERE Veranstalter_ID = $1;";
|
||||
|
||||
pqxx::result response = worker.exec_params(query, id);
|
||||
worker.commit();
|
||||
versendeEmails();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DBPlan::hinzufuegenVeranstaltung(std::string name, std::string dauer, std::string ort, std::string raum) {
|
||||
try {
|
||||
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);
|
||||
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, std::string admin) {
|
||||
try {
|
||||
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);
|
||||
worker.commit();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DBPlan::deleteStudent(std::string id) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
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(connectionObject);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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 AND krank = FALSE 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 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) "
|
||||
"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 AND krank = FALSE 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 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) "
|
||||
"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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<std::string> DBPlan::getPlan() {
|
||||
try {
|
||||
|
||||
std::vector<std::string> 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;
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::versendeEmails() {
|
||||
std::cout << "Der Einsatzplan wurde geupdated" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
#ifndef _DBPLAN_HPP_
|
||||
#define _DBPLAN_HPP_
|
||||
|
||||
|
||||
#include "DBHandler.hpp"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
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);
|
||||
void versendeEmails();
|
||||
public:
|
||||
DBPlan(std::string connStr);
|
||||
|
||||
//deletes prof from plan and searches new one
|
||||
void meldeKrank(std::string id, std::string tag, std::string stunde);
|
||||
//currently directly used after meldeKrank, so Mitarbeiter is only sick for specific hour
|
||||
void meldeGesund(std::string id);
|
||||
|
||||
//Deletes Veranstaltung from relation Veranstaltung and from Einsatzplan
|
||||
void deleteVeranstaltung(std::string id);
|
||||
//Adds Veranstaltung to relation Veranstaltung
|
||||
void hinzufuegenVeranstaltung(std::string name, std::string dauer, std::string ort, std::string raum);
|
||||
|
||||
//Deletes Veranstlater from relattion Veranstalter and from Einsatzplan
|
||||
void deleteVeranstalter(std::string id);
|
||||
//Add Veranstalter to relation Veranstalter
|
||||
void hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, std::string admin);
|
||||
|
||||
|
||||
void deleteStudent(std::string id);
|
||||
void hinzufuegenStudent(std::string email, std::string name, std::string pw);
|
||||
|
||||
|
||||
void createPlan();
|
||||
|
||||
//Each string in form of (tag , anfangszeit , endzeit , Ort , Veranstaltung , Mitarbeiter , mitarbeiterID , )
|
||||
std::vector<std::string> getPlan();
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
376
src/Core/DBHandler/DBPlan/DBPlan.cpp
Normal file
376
src/Core/DBHandler/DBPlan/DBPlan.cpp
Normal file
@@ -0,0 +1,376 @@
|
||||
#include "DBPlan.hpp"
|
||||
|
||||
DBPlan::DBPlan(std::string connStr) : DBHandler(connStr) { };
|
||||
|
||||
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);
|
||||
else
|
||||
nextStunde = std::to_string(std::stoi(stunde) + 1);
|
||||
fmt::print(nextStunde);
|
||||
|
||||
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 = R"(
|
||||
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; )";
|
||||
|
||||
worker.exec_params(query, prevStunde, prevTag, nextStunde, nextTag, stunde, tag);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
worker.exec_params("UPDATE Veranstalter SET krank = TRUE WHERE ID = $1", id);
|
||||
worker.commit( );
|
||||
|
||||
sucheVertretung(tag, stunde);
|
||||
meldeGesund(id);
|
||||
versendeEmails( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::meldeGesund(std::string id) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
worker.exec_params("UPDATE Veranstalter SET krank = FALSE WHERE ID = $1", id);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::deleteVeranstalterForeign(std::string id) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
worker.exec_params("UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = NULL WHERE Veranstalter_ID = $1;", id);
|
||||
worker.commit( );
|
||||
versendeEmails( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::deleteVeranstalter(std::string id) {
|
||||
deleteVeranstalterForeign(id);
|
||||
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
worker.exec_params("DELETE FROM Veranstalter WHERE ID = $1", id);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::deleteVeranstaltungForeign(std::string id) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
worker.exec_params("UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstaltung_ID = NULL WHERE Veranstalter_ID = $1;", id);
|
||||
worker.commit( );
|
||||
versendeEmails( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::deleteVeranstaltung(std::string id) {
|
||||
deleteVeranstaltungForeign(id);
|
||||
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
worker.exec_params("DELETE FROM Veranstaltung WHERE ID = $1", id);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::hinzufuegenVeranstaltung(std::string name, std::string dauer, std::string ort, std::string raum) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
worker.exec_params("INSERT INTO Veranstaltung (name, dauer, ort, raum) VALUES ($1, $2, $3, $4);", name, dauer, ort, raum);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, std::string admin) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
worker.exec_params("INSERT INTO Veranstalter (email, name, passwort, admin) VALUES ($1, $2, $3, $4);", email, name, pw, admin);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::deleteStudent(std::string id) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
worker.exec_params("DELETE FROM studenten WHERE ID = $1;", id);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::hinzufuegenStudent(std::string email, std::string name, std::string pw) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
worker.exec_params("INSERT INTO studenten (email, name, pw) VALUES ($1, $2, $3);", email, name, pw);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
std::string DBPlan::getDauer(std::string tag, std::string stunde) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
pqxx::result response = worker.exec_params(
|
||||
"SELECT dauer FROM Veranstaltung WHERE ID = (SELECT Veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2);",
|
||||
stunde,
|
||||
tag
|
||||
);
|
||||
|
||||
worker.commit( );
|
||||
return response[0][0].c_str( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
|
||||
void DBPlan::addFirstOfDayTwo(std::string tag) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(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;)";
|
||||
worker.exec_params(query, tag);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::addTwoHour(std::string tag, std::string stunde) {
|
||||
try {
|
||||
std::string prevStunde = std::to_string(std::stoi(stunde) - 1);
|
||||
|
||||
fmt::printf("PrevStunde: %s\n Tag: %s\n Stunde: %s \n", prevStunde, tag, stunde);
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter
|
||||
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)
|
||||
WHERE uhrzeit_id = $3 AND tag = $4;)";
|
||||
worker.exec_params(query, prevStunde, tag, stunde, tag);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::addFirstOfDayFour(std::string tag) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(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;)";
|
||||
worker.exec_params(query, tag);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
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 =
|
||||
R"(UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter
|
||||
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)
|
||||
WHERE uhrzeit_id = $3 AND tag = $4;)";
|
||||
worker.exec_params(query, prevStunde, tag, stunde, tag);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::upperHour(std::string tag, std::string stunde) {
|
||||
try {
|
||||
std::string nextStunde = std::to_string(std::stoi(stunde) + 1);
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(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;)";
|
||||
worker.exec_params(query, stunde, tag, nextStunde);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
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);";
|
||||
worker.exec_params(query, stunde, tag);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
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);";
|
||||
|
||||
worker.exec_params(query, amount, stunde, tag);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
stunde == 1 ? addFirstOfDayTwo(tagStr) : addTwoHour(tagStr, stundeStr);
|
||||
updateStandort(tagStr, stundeStr);
|
||||
incarbeitszeit(tagStr, stundeStr, "2");
|
||||
} else {
|
||||
stunde == 1 ? addFirstOfDayFour(tagStr) : addFourHour(tagStr, stundeStr);
|
||||
upperHour(tagStr, stundeStr);
|
||||
incarbeitszeit(tagStr, stundeStr, "4");
|
||||
updateStandort(tagStr, stundeStr);
|
||||
stunde++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> DBPlan::getPlan( ) {
|
||||
try {
|
||||
std::vector<std::string> plan;
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
std::string query =
|
||||
R"(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) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
return std::vector<std::string>{ "" };
|
||||
}
|
||||
|
||||
void DBPlan::versendeEmails( ) {
|
||||
fmt::print("Der Einsatzplan wurde geändert");
|
||||
}
|
||||
107
src/Core/DBHandler/DBPlan/DBPlan.hpp
Normal file
107
src/Core/DBHandler/DBPlan/DBPlan.hpp
Normal file
@@ -0,0 +1,107 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/printf.h>
|
||||
|
||||
#include "../DBHandler/DBHandler.hpp"
|
||||
|
||||
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);
|
||||
void versendeEmails( );
|
||||
|
||||
public:
|
||||
DBPlan(std::string connStr);
|
||||
|
||||
/**
|
||||
* @brief Deletes prof from plan and searches new one
|
||||
*
|
||||
* @param id
|
||||
* @param tag
|
||||
* @param stunde
|
||||
*/
|
||||
void meldeKrank(std::string id, std::string tag, std::string stunde);
|
||||
|
||||
/**
|
||||
* @brief Currently directly used after meldeKrank, so Mitarbeiter is only sick for specific hour
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
void meldeGesund(std::string id);
|
||||
|
||||
/**
|
||||
* @brief Deletes Veranstaltung from relation Veranstaltung and from Einsatzplan
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
void deleteVeranstaltung(std::string id);
|
||||
|
||||
/**
|
||||
* @brief Adds Veranstaltung to relation Veranstaltung
|
||||
*
|
||||
* @param name
|
||||
* @param dauer
|
||||
* @param ort
|
||||
* @param raum
|
||||
*/
|
||||
void hinzufuegenVeranstaltung(std::string name, std::string dauer, std::string ort, std::string raum);
|
||||
|
||||
/**
|
||||
* @brief Deletes Veranstlater from relattion Veranstalter and from Einsatzplan
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
void deleteVeranstalter(std::string id);
|
||||
|
||||
/**
|
||||
* @brief Add Veranstalter to relation Veranstalter
|
||||
*
|
||||
* @param email
|
||||
* @param name
|
||||
* @param pw
|
||||
* @param admin
|
||||
*/
|
||||
void hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, std::string admin);
|
||||
|
||||
/**
|
||||
* @brief Deletes a student from the database
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
void deleteStudent(std::string id);
|
||||
|
||||
/**
|
||||
* @brief Adds a new student
|
||||
*
|
||||
* @param email
|
||||
* @param name
|
||||
* @param pw
|
||||
*/
|
||||
void hinzufuegenStudent(std::string email, std::string name, std::string pw);
|
||||
|
||||
/**
|
||||
* @brief Create a Plan object
|
||||
*
|
||||
*/
|
||||
void createPlan( );
|
||||
|
||||
/**
|
||||
* @brief Each string in form of (tag , anfangszeit , endzeit , Ort , Veranstaltung , Mitarbeiter , mitarbeiterID , )
|
||||
*
|
||||
* @return std::vector<std::string>
|
||||
*/
|
||||
std::vector<std::string> getPlan( );
|
||||
};
|
||||
32
src/Core/config/config.hpp
Normal file
32
src/Core/config/config.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
|
||||
inline static const std::map<std::string, std::string>& load_config(const std::string& filename) {
|
||||
static std::map<std::string, std::string> config;
|
||||
static bool is_loaded{ false };
|
||||
static std::string fn{ "" };
|
||||
|
||||
if (!is_loaded || fn != filename) {
|
||||
std::ifstream file(filename);
|
||||
std::string line;
|
||||
|
||||
while (std::getline(file, line)) {
|
||||
std::istringstream line_stream(line);
|
||||
std::string key;
|
||||
if (std::getline(line_stream, key, '=')) {
|
||||
std::string value;
|
||||
if (std::getline(line_stream, value)) {
|
||||
config[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is_loaded = true;
|
||||
fn = filename;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
Reference in New Issue
Block a user