Documentation added
This commit is contained in:
@@ -9,17 +9,29 @@
|
||||
|
||||
using std::vector;
|
||||
|
||||
// will make it easy to represent it in the database while making it easy to use
|
||||
// while programming
|
||||
/*
|
||||
enum classes make it easy to represent categories.
|
||||
So you can use something like Verhicle_type::car instead of 2. but under the
|
||||
hood, it's still an int. This is here so you won't have to have global variables
|
||||
for these categories, or worse, use magic numbers in the code.
|
||||
|
||||
*/
|
||||
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.
|
||||
Customer constructors do the same stuff as all the other constructors.
|
||||
clock_in and out create and modify park_time objects and store them to
|
||||
park_instances. Technically, now that we have a working db, we don't need it.
|
||||
TODO: fix this.
|
||||
|
||||
*/
|
||||
gen_monthly just prints out all the park_time objects in park_instances.
|
||||
It should (and can safely) be removed, but it's here as a quick example of
|
||||
report generation It has no logic to speak of that only generates report of
|
||||
ptime objects of this month.
|
||||
TODO: remove when have seperate report generation functions.
|
||||
|
||||
save, update, delete and auto increment are the same as in park_time.
|
||||
*/
|
||||
|
||||
class Customer {
|
||||
public:
|
||||
@@ -27,9 +39,7 @@ class Customer {
|
||||
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?
|
||||
Customer(int id_, string name_, string password_, Verhicle_type verhicle_,
|
||||
vector<Park_time> instances);
|
||||
void clock_in(int s_id);
|
||||
void clock_out(int s_id);
|
||||
@@ -37,7 +47,7 @@ class Customer {
|
||||
void update_db();
|
||||
void delete_db();
|
||||
|
||||
void gen_monthly(); // remove, make it a function in data
|
||||
void gen_monthly();
|
||||
Verhicle_type verhicle;
|
||||
|
||||
private:
|
||||
@@ -46,5 +56,4 @@ class Customer {
|
||||
int auto_increment_db();
|
||||
};
|
||||
|
||||
|
||||
#endif // CUSTOMER_H
|
@@ -17,6 +17,28 @@ using std::to_string;
|
||||
|
||||
|
||||
Record of who parked at what park_spot and at what time.
|
||||
public interface-------------------------------------------
|
||||
|
||||
The constructors. one for creating new customers, the other one used by the
|
||||
query functions to construct the object from information stored in the database.
|
||||
|
||||
clock_out is the function that gets called from customer.clock_out().
|
||||
It verifies that the customer is clocking out at the correct parkspot, and saves
|
||||
the current time of clocking out in end. It also calculates duration so it
|
||||
doesn't have to be calculated more than once.
|
||||
|
||||
operator<< is << overload, can(should) be used for report generation.
|
||||
|
||||
|
||||
// implementation stuff------------------------
|
||||
start and end are time points representing when someone clocks in and out. they're from the chrono namespace.
|
||||
|
||||
save and update save and update info in the database.
|
||||
auto_increment pulls the highest id stored in the db, to be used in the constructor.
|
||||
|
||||
start_to_int() is used to convert the start timepoint to an integer that can be saved in the database
|
||||
SQL datetime and chrono datetime don't seem the most compatible.
|
||||
|
||||
*/
|
||||
|
||||
class Park_time {
|
||||
|
@@ -4,17 +4,57 @@
|
||||
|
||||
#include "Park_spot.h"
|
||||
|
||||
#include <array>
|
||||
/*these are the functions that search the database and create objects from it.
|
||||
|
||||
query_parktimes_for_customer searches for the parktimes that are needed in
|
||||
customer initialisaiton. generally, i see no use outside of that.
|
||||
|
||||
query_customer_with_name searches for customer data by name.
|
||||
|
||||
query_customer_with_id does what the above does, but with id.
|
||||
|
||||
|
||||
populate_spots is used to query for all the park_spots and return them as
|
||||
objects.
|
||||
|
||||
The design desision to use vector<T> instead of <T> is for the following
|
||||
reasons:
|
||||
|
||||
1. some of these can potentially return more than one object. For example, 2
|
||||
customers who have the same name.
|
||||
|
||||
2. I have no clue how many of you have done error handling in c++
|
||||
(try/catch/finally).
|
||||
Ya boi is nice and doesn't want to bombard you with more new concepts than needed.
|
||||
so now you'd do
|
||||
|
||||
vector<Customer> test = query_customer_with_name("Testman");
|
||||
|
||||
if (!test.size()) {print no customers found, do stuff}
|
||||
else if (test.size() > 1) { do stuff to get the right one if you only need one
|
||||
}
|
||||
|
||||
instead of
|
||||
try {
|
||||
customer test = query_customer_with_name("Testman");
|
||||
}
|
||||
catch(someException.probablycalled_not_found) {do_Stuff};
|
||||
catch(...) {
|
||||
do stuff
|
||||
}
|
||||
finally{
|
||||
do more stuff
|
||||
}
|
||||
|
||||
3. Ya boi needs to brush up on how to create custom exceptions class, and it will complicate code furhter.
|
||||
|
||||
*/
|
||||
|
||||
vector<Park_time> query_parktimes_for_customer(int cid);
|
||||
|
||||
vector<Customer> query_customer_with_name(string name);
|
||||
Customer query_customer_with_id(int id);
|
||||
|
||||
// vector<Park_spot> query_all_parking_spots(); // used for initializing the parking spots at start of the program
|
||||
vector<Park_spot> populate_spots();
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // CUSTOMER_H
|
@@ -5,8 +5,13 @@
|
||||
#include "encrypt.h"
|
||||
|
||||
namespace data {
|
||||
SQLite::Database start_db();
|
||||
|
||||
/*
|
||||
start_db is the function that opens the database, and
|
||||
if the necesary tables are not there, creates them.
|
||||
db is the database, and is static to avoid multiple redefinition errors.
|
||||
*/
|
||||
SQLite::Database start_db();
|
||||
static SQLite::Database db = start_db();
|
||||
|
||||
} // namespace data
|
||||
|
@@ -2,12 +2,20 @@
|
||||
#define ENCRYPT_H
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <sodium.h>
|
||||
#include <iostream>
|
||||
#include <sodium.h>
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
/*
|
||||
hash_password takes the password, and encrypts it. This needs to be done,
|
||||
because storing passwords in plaintext is BAD!
|
||||
|
||||
verify_password takes in a password and the hashed password, and then does magic encryption stuff(no, not
|
||||
really. It basically hashes the password with the same salt and other
|
||||
parameters) and to see if the password stored and the given password match.
|
||||
*/
|
||||
|
||||
string hash_password(string password);
|
||||
bool verify_password(string hashed_password, string unhashed_password);
|
||||
|
Reference in New Issue
Block a user