diff --git a/Park_spot.cpp b/Park_spot.cpp index e64e8e1..7efc6cf 100644 --- a/Park_spot.cpp +++ b/Park_spot.cpp @@ -2,14 +2,15 @@ // constructors -Park_spot::Park_spot() - : parked_customer{0}, id{auto_increment_db() + 1}, taken{false} { +Park_spot::Park_spot(Vehicle_type v_type_) + : parked_customer{0}, id{auto_increment_db() + 1}, taken{false}, v_type{v_type_} { save_db(); } -Park_spot::Park_spot(int id_, bool taken_, int parked) +Park_spot::Park_spot(int id_, bool taken_, int parked,Vehicle_type v_type_) : parked_customer{parked}, id{id_}, + v_type{v_type_}, taken{taken_} // TODO: think about how init parked? {} @@ -48,8 +49,9 @@ void Park_spot::update_db() { void Park_spot::save_db() { //(int id, bool taken, int customer_id) - string statement{"insert into Park_spot values ( , , );"}; + string statement{"insert into Park_spot values ( , , , );"}; // after ( = 28) + statement.insert(36, to_string(int(v_type))); statement.insert(34, "NULL"); statement.insert(32, "0"); statement.insert(30, to_string(id)); diff --git a/data.cpp b/data.cpp index be27c0d..5c000b9 100644 --- a/data.cpp +++ b/data.cpp @@ -24,7 +24,7 @@ SQLite::Database start_db() { // getting errors when using bool, so i used an int instead. db.exec( "create table if not exists Park_spot (id integer primary key, taken " - "int, customer_id int)"); + "int, customer_id int, vehicle_type int)"); db.exec( "create table if not exists Park_time (id integer primary key, " "customer_id int, spot_id int, start int, end int, duration int)"); diff --git a/headers/Park_spot.h b/headers/Park_spot.h index e50dfdc..068fc55 100644 --- a/headers/Park_spot.h +++ b/headers/Park_spot.h @@ -18,9 +18,10 @@ class Park_spot { int id; bool taken; int parked_customer; + Vehicle_type v_type; - Park_spot(); - Park_spot(int id_, bool taken_, int parked); + Park_spot(Vehicle_type v_type_); + Park_spot(int id_, bool taken_, int parked, Vehicle_type v_type_); void clock(Customer& c_customer); private: diff --git a/main.cpp b/main.cpp index 7d88f59..dd7794f 100644 --- a/main.cpp +++ b/main.cpp @@ -70,12 +70,10 @@ For now, it's just here in case you want an easy way to store customers. */ int main() { + // state of db: + // er zijn 10 parkspots, 5 met biketype en 5 met pickup type // er is een customer met id 1(testcustomer) met password "password" - // Customer test { - // "testcustomer", "password", Vehicle_type::bike - // }; - interface(); @@ -89,13 +87,12 @@ concurrency issue. Do not move this. vector populate_spots() { vector spots; SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 0;"); - // query.bind(1, 2); while (query.executeStep()) { int id = query.getColumn(0); int taken = query.getColumn(1); int cid = query.getColumn(2); - // park_customers.push_back(query_customer_with_id(cid)); - spots.push_back({id, taken, cid}); + Vehicle_type vtype = Vehicle_type(int(query.getColumn(3))); + spots.push_back({id, taken, cid, vtype}); } return spots; } \ No newline at end of file diff --git a/test.db3 b/test.db3 index 6e83b13..fc57d5f 100644 Binary files a/test.db3 and b/test.db3 differ