so far, still working
This commit is contained in:
55
headers/Customer.h
Normal file
55
headers/Customer.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef CUSTOMER_H
|
||||
#define CUSTOMER_H
|
||||
#pragma once
|
||||
|
||||
#include "Park_time.h"
|
||||
#include "data.h"
|
||||
|
||||
#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 };
|
||||
|
||||
/*
|
||||
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:
|
||||
int id;
|
||||
string name;
|
||||
string password;
|
||||
Customer(string name_, string password_, Verhicle_type verhicle_);
|
||||
Customer(int id_, string name_, // needed to construct from db
|
||||
string password_,
|
||||
Verhicle_type verhicle_, // TODO: how init. p_time instances?
|
||||
vector<Park_time> instances);
|
||||
void clock_in(int s_id);
|
||||
void clock_out(int s_id);
|
||||
|
||||
void update_db();
|
||||
void delete_db();
|
||||
|
||||
void gen_monthly(); // remove, make it a function in data
|
||||
Verhicle_type verhicle;
|
||||
|
||||
private:
|
||||
vector<Park_time> park_instances;
|
||||
void save_db();
|
||||
int auto_increment_db();
|
||||
};
|
||||
|
||||
static vector<Customer> park_customers;
|
||||
// save the customers that are parked in here
|
||||
// parking_spot uses pointers, so it's better to save the parked customers here
|
||||
// where we know they'll be destroyed at the end of this scope, instead of too
|
||||
// early and end up with dangling pointers
|
||||
|
||||
#endif // CUSTOMER_H
|
29
headers/Park_spot.h
Normal file
29
headers/Park_spot.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#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.
|
||||
*/
|
||||
|
||||
class Park_spot {
|
||||
public:
|
||||
int id;
|
||||
bool taken;
|
||||
int parked_customer;
|
||||
Park_spot();
|
||||
Park_spot(int id_, bool taken_, Customer& parked);
|
||||
void clock(Customer& c_customer);
|
||||
|
||||
private:
|
||||
void save_db();
|
||||
void update_db();
|
||||
void delete_db();
|
||||
int auto_increment_db();
|
||||
};
|
||||
|
||||
static vector<Park_spot> parking_spots; // to save the parking spots in memory
|
44
headers/Park_time.h
Normal file
44
headers/Park_time.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef PARK_TIME_H
|
||||
#define PARK_TIME_H
|
||||
#pragma once
|
||||
|
||||
#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;
|
||||
/*
|
||||
|
||||
|
||||
Record of who parked at what park_spot and at what time.
|
||||
*/
|
||||
|
||||
class Park_time {
|
||||
public:
|
||||
Park_time(int c_id, int s_id);
|
||||
Park_time(int id_, int customer_id_, int spot_id_, int start_,
|
||||
int duration_);
|
||||
int id;
|
||||
int customer_id;
|
||||
int spot_id;
|
||||
int duration;
|
||||
|
||||
void clock_out(int c_id, int s_id);
|
||||
friend std::ostream& operator<<(std::ostream& os, const Park_time& pt);
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
#endif // Park_time
|
@@ -5,8 +5,7 @@
|
||||
#include "encrypt.h"
|
||||
|
||||
namespace data {
|
||||
SQLite::Database
|
||||
start_db();
|
||||
SQLite::Database start_db();
|
||||
static SQLite::Database db = start_db();
|
||||
|
||||
} // namespace data
|
||||
|
Reference in New Issue
Block a user