diff --git a/.gitignore b/.gitignore index bee8a64..6ecb113 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ __pycache__ +src/app/sessions/ diff --git a/mysql/sql/init.sql b/mysql/sql/init.sql index c858803..b9903fa 100644 --- a/mysql/sql/init.sql +++ b/mysql/sql/init.sql @@ -1,20 +1,143 @@ -CREATE TABLE `db`.`users` ( - `userid` INT AUTO_INCREMENT, - `username` VARCHAR(45) NULL, - `password` VARCHAR(45) NULL, - PRIMARY KEY (`userid`) +CREATE TABLE users ( + userid INT UNSIGNED AUTO_INCREMENT, + username VARCHAR(45) UNIQUE NOT NULL, + password VARCHAR(45) NOT NULL, + full_name VARCHAR(200) NOT NULL, + company VARCHAR(50), + phone_number VARCHAR(50), + street_address VARCHAR(50), + city VARCHAR(50), + state VARCHAR(50), + postal_code VARCHAR(50), + country VARCHAR(50), + PRIMARY KEY (userid) ); -CREATE TABLE `db`.`guestbook` ( - `entryid` INT AUTO_INCREMENT, - `text` VARCHAR(255) NULL, - PRIMARY KEY (`entryid`) + +CREATE TABLE guestbook ( + entryid INT UNSIGNED AUTO_INCREMENT, + text VARCHAR(255) NOT NULL, + PRIMARY KEY (entryid) +); + +/* +* Project tables +*/ + +CREATE TABLE teams ( + teamid INT UNSIGNED AUTO_INCREMENT, + team_name VARCHAR(200) NOT NULL, + write_permission BOOLEAN, + PRIMARY KEY (teamid) ); -insert into users values (NULL, "admin", "password"); -insert into users values (NULL, "bernt", "inge"); +CREATE TABLE teams_users ( + teamid INT UNSIGNED NOT NULL, + userid INT UNSIGNED NOT NULL, + PRIMARY KEY (teamid, userid), + FOREIGN KEY (teamid) REFERENCES teams(teamid), + FOREIGN KEY (userid) REFERENCES users(userid) +); + +CREATE TABLE project_category ( + categoryid INT UNSIGNED AUTO_INCREMENT, + category_name VARCHAR(200) UNIQUE NOT NULL, + PRIMARY KEY (categoryid) +); + +CREATE TABLE users_categories ( + userid INT UNSIGNED NOT NULL, + categoryid INT UNSIGNED NOT NULL, + PRIMARY KEY (userid, categoryid), + FOREIGN KEY (userid) REFERENCES users(userid), + FOREIGN KEY (categoryid) REFERENCES project_category(categoryid) +); + +CREATE TABLE projects ( + projectid INT UNSIGNED AUTO_INCREMENT, + categoryid INT UNSIGNED NOT NULL, + userid INT UNSIGNED NOT NULL, + title VARCHAR(200) NOT NULL, + project_description VARCHAR(500) NOT NULL, + project_status VARCHAR(16) NOT NULL, -- This should be either open, in progress or finished + PRIMARY KEY (projectid), + FOREIGN KEY (categoryid) REFERENCES project_category(categoryid), + FOREIGN KEY (userid) REFERENCES users(userid) +); + +CREATE TABLE projects_users ( + projectid INT UNSIGNED NOT NULL, + userid INT UNSIGNED NOT NULL, + read_permission BOOLEAN, + write_permission BOOLEAN, + modify_permission BOOLEAN, + PRIMARY KEY (projectid, userid), + FOREIGN KEY (projectid) REFERENCES projects(projectid), + FOREIGN KEY (userid) REFERENCES users(userid) +); + +CREATE TABLE tasks ( + taskid INT UNSIGNED AUTO_INCREMENT, + projectid INT NOT NULL, + teamid INT UNSIGNED NOT NULL, + title VARCHAR(200) NOT NULL, + task_description VARCHAR(500), + budget INT, + task_status VARCHAR(64), -- This should be Waiting for delivery, Delivered and waiting for acceptance, Delivery has been accepted, awaiting payment, Payment for delivery is done or Declined delivery, please revise + feedback VARCHAR(500), + PRIMARY KEY (taskid), + FOREIGN KEY (teamid) REFERENCES teams(teamid) +); + +CREATE TABLE task_files ( + fileid INT NOT NULL AUTO_INCREMENT, + taskid INT UNSIGNED NOT NULL, + filename VARCHAR(45) NOT NULL, + PRIMARY KEY (fileid), + FOREIGN KEY (taskid) REFERENCES tasks(taskid) +); + +CREATE TABLE delivery ( + deliveryid INT UNSIGNED AUTO_INCREMENT, + taskid INT UNSIGNED NOT NULL, + userid INT UNSIGNED NOT NULL, + filename VARCHAR(45) NOT NULL, + comment VARCHAR(500), + delivery_time DATETIME DEFAULT CURRENT_TIMESTAMP, + responding_userid INT NOT NULL, + responding_time DATETIME, + delivery_status VARCHAR(16), -- Should be Accepted, Pending or Declined + feedback VARCHAR(500), + PRIMARY KEY (deliveryid), + FOREIGN KEY (taskid) REFERENCES tasks(taskid), + FOREIGN KEY (userid) REFERENCES users(userid) +); + +CREATE TABLE task_offer ( + offerid INT UNSIGNED AUTO_INCREMENT, + taskid INT UNSIGNED NOT NULL, + title VARCHAR(200) NOT NULL, + price INT, + description VARCHAR(500), + offer_status VARCHAR(16), -- Should be Accepted, Pending or Declined + feedback VARCHAR(500), + PRIMARY KEY (offerid), + FOREIGN KEY (taskid) REFERENCES tasks(taskid) +); + +/* +* Initial data +*/ + +insert into users values (NULL, "admin", "password", "Admin Modsen", "ntnu", "12345678", "street", "trondheim", "trondheim", "1234", "norway"); insert into guestbook values (NULL, "Hello World"); +insert into project_category values (NULL, "Test"); + +/* +Create default database user +*/ + CREATE USER 'root'@'10.5.0.6' IDENTIFIED BY 'root'; GRANT ALL PRIVILEGES ON db.* TO 'root'@'10.5.0.6'; diff --git a/src/app/models/database.py b/src/app/models/database.py index dbca4a2..11bbd81 100644 --- a/src/app/models/database.py +++ b/src/app/models/database.py @@ -3,6 +3,6 @@ import mysql.connector db = mysql.connector.connect( user='root', password='root', - host='0.0.0.0', + host='10.5.0.5', database='db' ) diff --git a/src/app/models/project.py b/src/app/models/project.py new file mode 100644 index 0000000..f75a217 --- /dev/null +++ b/src/app/models/project.py @@ -0,0 +1,23 @@ +from models.database import db + +def get_categories(): + cursor = db.cursor() + query = ("SELECT * FROM project_category") + cursor.execute(query) + categories = cursor.fetchall() + cursor.close() + return categories + +def set_project(categoryid, userid, title, project_description, project_status): + cursor = db.cursor() + query = ("INSERT INTO projects values (NULL, \"1\", \"1\", \"sad\", \"desdf\", \"open\")") + #("INSERT INTO projects values (NULL, \"" + + #categoryid + "\", \"" + userid + "\", \"" + title + "\", \"" + + #project_description + "\", \"" + project_status + "\")") + print(query) + cursor.execute(query) + cursor.close() + categories = get_categories() + print(categories) + return categories + diff --git a/src/app/models/register.py b/src/app/models/register.py index c2aab3a..af5172e 100644 --- a/src/app/models/register.py +++ b/src/app/models/register.py @@ -1,8 +1,11 @@ from models.database import db -def set_user(username, password): +def set_user(username, password, full_name, company, phone_number, + street_address, city, state, postal_code, country): cursor = db.cursor() - query = ("INSERT INTO users VALUES (NULL, \"" + username + - "\", \"" + password + "\")") + query = ("INSERT INTO users VALUES (NULL, \"" + username + "\", \"" + + password + "\", \"" + full_name + "\" , \"" + company + "\", \"" + + phone_number + "\", \"" + street_address + "\", \"" + city + "\", \"" + + state + "\", \"" + postal_code + "\", \"" + country + "\")") cursor.execute(query) cursor.close() diff --git a/src/app/templates/project.html b/src/app/templates/project.html new file mode 100644 index 0000000..8682a59 --- /dev/null +++ b/src/app/templates/project.html @@ -0,0 +1,20 @@ +$def with (nav, project_form) + +
+