WIP refractoring
This commit is contained in:
58
old/headers/Customer.h
Normal file
58
old/headers/Customer.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifndef CUSTOMER_H
|
||||
#define CUSTOMER_H
|
||||
#pragma once
|
||||
#include "../thirdparty/SQLiteCpp/include/SQLiteCpp/SQLiteCpp.h"
|
||||
#include "Park_time.h"
|
||||
#include <ctime>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
// enum type is basically een manier om categories te representen als een integer in the background, maar om t in code
|
||||
// aan te geven als de actual category.
|
||||
enum class Verhicle_type {
|
||||
small = 1,
|
||||
medium = 2,
|
||||
large = 3,
|
||||
};
|
||||
|
||||
/*
|
||||
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_, SQLite::Database& db);
|
||||
Customer(int id_, string name_, string card_code_, Verhicle_type verhicle_,
|
||||
vector<Park_time> instances); // needed to construct from db
|
||||
// potentially: add a destructor that calls update_db() before being destroyed
|
||||
int id;
|
||||
string name;
|
||||
string card_code;
|
||||
|
||||
void clock_in(int s_id);
|
||||
void clock_out(int s_id);
|
||||
|
||||
void update_db(SQLite::Database& database);
|
||||
void delete_db(SQLite::Database& database);
|
||||
|
||||
// void gen_weekly(); TODO: this
|
||||
void gen_monthly();
|
||||
|
||||
private:
|
||||
Verhicle_type verhicle;
|
||||
vector<Park_time> park_instances;
|
||||
|
||||
string gen_cardcode();
|
||||
|
||||
void save_db(SQLite::Database& database);
|
||||
int auto_increment_db(SQLite::Database& database);
|
||||
};
|
||||
|
||||
#endif // CUSTOMER_H
|
21
old/headers/Park_spot.h
Normal file
21
old/headers/Park_spot.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#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;
|
||||
Customer* parked; //TODO: think about memory management
|
||||
Park_spot(int id_);
|
||||
void clock(Customer* c_customer);
|
||||
private:
|
||||
};
|
44
old/headers/Park_time.h
Normal file
44
old/headers/Park_time.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef PARK_TIME_H
|
||||
#define PARK_TIME_H
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
/*
|
||||
db repr of Park_time
|
||||
int id (not null, auto increment)
|
||||
int customer_id (not null) (many to one or something like that)
|
||||
int spot_id (not null, many to one or something like that)
|
||||
int duration
|
||||
datetime start (not null)
|
||||
datetime end
|
||||
|
||||
Dit is gewoon een record van hoe lang, wie en waar iemand parkeert. Basically, een component van
|
||||
de internal state van customer.
|
||||
*/
|
||||
|
||||
class Park_time {
|
||||
public:
|
||||
int id;
|
||||
int customer_id;
|
||||
int spot_id;
|
||||
int duration;
|
||||
Park_time(int c_id, int s_id);
|
||||
void clock_out(int c_id, int s_id);
|
||||
friend std::ostream& operator<<(std::ostream& os, const Park_time & pt);
|
||||
void debug();
|
||||
|
||||
private:
|
||||
high_resolution_clock::time_point start;
|
||||
high_resolution_clock::time_point end;
|
||||
//TODO: discuss pros cons of using chrono, ctime, or 3th party lib
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // Park_time
|
Reference in New Issue
Block a user