Added constructors to construct from db info

This is in no way finished. CHECK TODOs!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
This commit is contained in:
TinyAtoms
2019-06-30 00:37:18 -03:00
parent 085cd5af08
commit bf17b82c2e
10 changed files with 136 additions and 124 deletions

View File

@@ -2,35 +2,33 @@
#define CUSTOMER_H
#pragma once
#include "Park_time.h"
#include "data.h"
#include <random>
#include <vector>
using std::vector;
// will make it easy to represent it in the database while making it easy to use while programming
enum class Verhicle_type {
bike = 1,
small_car = 2,
suv = 3,
pickup = 4
};
// will make it easy to represent it in the database while making it easy to use
// while programming
enum class Verhicle_type { bike = 1, small_car = 2, suv = 3, pickup = 4 };
/*
card code is een randomly generated string moeten zijn, die je bv. op een nfc card zou opslaan en zo zou
authenticaten bij je parking spot. We kunnen dit ipv of samen met een password gebruiken.
clock in en out creeert en compleet een park_time object. Voegt het toe aan een vector.
card code is een randomly generated string moeten zijn, die je bv. op een nfc
card zou opslaan en zo zou authenticaten bij je parking spot. We kunnen dit ipv
of samen met een password gebruiken. clock in en out creeert en compleet een
park_time object. Voegt het toe aan een vector.
*/
class Customer {
public:
Customer(string name_, Verhicle_type verhicle_);
Customer(int id_, string name_, string card_code_, Verhicle_type verhicle_,
vector<Park_time> instances); // needed to construct from db
Customer(int id_, string name_, // needed to construct from db
string card_code_,
Verhicle_type verhicle_, // TODO: how init. p_time instances?
vector<Park_time> instances);
~Customer();
int id;
string name;

View File

@@ -1,26 +1,32 @@
#include "Customer.h"
/*
db representation:
int id not null
bool taken not null
int customer_id (null) (many to one, foreign key, whatever)
Dit representeert een parkeerplaats. Het heeft als internal state alleen dat t bezet is of niet.
Dit representeert een parkeerplaats. Het heeft als internal state alleen dat t
bezet is of niet.
*/
class Park_spot {
public:
public:
int id;
bool taken;
Customer* parked;
Park_spot();
~Park_spot();
void clock(Customer* c_customer);
private:
void save_db();
void update_db();
void delete_db();
int auto_increment_db();
void
clock(Customer* c_customer);
private:
void
save_db();
void
update_db();
void
delete_db();
int
auto_increment_db();
};

View File

@@ -2,17 +2,17 @@
#define PARK_TIME_H
#pragma once
#include <chrono>
#include <iostream>
#include <string>
#include <ctime>
#include "data.h"
#include <chrono>
#include <ctime>
#include <iostream>
#include <string>
using namespace std::chrono;
using std::cout;
using std::string;
using std::to_string;
using std::cout;
/*
@@ -20,9 +20,10 @@ Record of who parked at what park_spot and at what time.
*/
class Park_time {
public:
public:
Park_time(int c_id, int s_id);
// Park_time(int c_id, int s_id );
Park_time(int id_, int customer_id_, int spot_id_, int start_,
int duration_);
~Park_time();
int id;
int customer_id;
@@ -30,19 +31,15 @@ public:
int duration;
void clock_out(int c_id, int s_id);
friend std::ostream& operator<<(std::ostream& os, const Park_time & pt);
friend std::ostream& operator<<(std::ostream& os, const Park_time& pt);
private:
private:
high_resolution_clock::time_point start;
high_resolution_clock::time_point end;
void save_db();
void update_db();
int auto_increment_db(); // helper
int start_to_int(); // helper
int start_to_int(); // helper
};
#endif // Park_time

View File

@@ -3,9 +3,10 @@
#pragma once
#include "../thirdparty/SQLiteCpp/include/SQLiteCpp/SQLiteCpp.h"
namespace data {
SQLite::Database start_db();
SQLite::Database
start_db();
static SQLite::Database db = start_db();
}
} // namespace data
#endif