Add files via upload
This commit is contained in:
25
DBHandler/DBHandler.cpp
Normal file
25
DBHandler/DBHandler.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "DBHandler.hpp"
|
||||
|
||||
#include <iostream>
|
||||
//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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
14
DBHandler/DBHandler.hpp
Normal file
14
DBHandler/DBHandler.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef DBHANDLER_HPP_
|
||||
#define DBHANDLER_HPP_
|
||||
#include <pqxx/pqxx>
|
||||
#include <string>
|
||||
|
||||
class DBHandler {
|
||||
protected:
|
||||
pqxx::connection connectionObject;
|
||||
|
||||
public:
|
||||
DBHandler(std::string connStr);
|
||||
};
|
||||
|
||||
#endif
|
||||
40
DBHandler/DBLogin.cpp
Normal file
40
DBHandler/DBLogin.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#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(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<bool>();
|
||||
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
18
DBHandler/DBLogin.hpp
Normal file
18
DBHandler/DBLogin.hpp
Normal file
@@ -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
|
||||
56
DBHandler/DBPlan.cpp
Normal file
56
DBHandler/DBPlan.cpp
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
28
DBHandler/DBPlan.hpp
Normal file
28
DBHandler/DBPlan.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef _DBPLAN_HPP_
|
||||
#define _DBPLAN_HPP_
|
||||
|
||||
|
||||
#include "DBHandler.hpp"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
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<std::string>> getVeranstalter();
|
||||
|
||||
bool deleteStudent(int id);
|
||||
bool hinzufuegenStudent(std::string email, std::string name, std::string pw);
|
||||
std::vector < std::vector<std::string>> getStudenten();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user