diff --git a/backend/config/db.js b/backend/config/db.js index 124f845..598e0bd 100644 --- a/backend/config/db.js +++ b/backend/config/db.js @@ -1,5 +1,6 @@ const mysql = require('mysql'); +// Create the connection to the database const db = mysql.createConnection({ host: process.env.DB_HOST, user: process.env.DB_USER, @@ -7,12 +8,55 @@ const db = mysql.createConnection({ database: process.env.DB_NAME }); +// Connect to the database and create tables if they don't exist db.connect((err) => { if (err) { console.error('Error connecting to MySQL:', err); return; } console.log('Connected to MySQL database'); + + // SQL for checking and creating tables + const queries = [ + `CREATE TABLE IF NOT EXISTS locationTypes ( + id INT AUTO_INCREMENT PRIMARY KEY, + typeName VARCHAR(255) NOT NULL + );`, + `CREATE TABLE IF NOT EXISTS users ( + id INT AUTO_INCREMENT PRIMARY KEY, + userName VARCHAR(255) NOT NULL, + email VARCHAR(255) NOT NULL UNIQUE + );`, + `CREATE TABLE IF NOT EXISTS locations ( + id INT AUTO_INCREMENT PRIMARY KEY, + locationName VARCHAR(255) NOT NULL, + locationTypeId INT, + userId INT, + longitude FLOAT, + latitude FLOAT, + image VARCHAR(255), + FOREIGN KEY (locationTypeId) REFERENCES locationTypes(id), + FOREIGN KEY (userId) REFERENCES users(id) + );`, + `CREATE TABLE IF NOT EXISTS user_locations ( + userId INT, + locationId INT, + PRIMARY KEY (userId, locationId), + FOREIGN KEY (userId) REFERENCES users(id), + FOREIGN KEY (locationId) REFERENCES locations(id) + );` + ]; + + // Loop through each query to create tables + queries.forEach((query) => { + db.query(query, (error, results) => { + if (error) { + console.error('Error creating table:', error); + } else { + console.log('Table checked/created successfully.'); + } + }); + }); }); -module.exports = db; \ No newline at end of file +module.exports = db; diff --git a/frontend/src/app/components/location-card/location-card.component.html b/frontend/src/app/components/location-card/location-card.component.html index f4ee6f7..ee734df 100644 --- a/frontend/src/app/components/location-card/location-card.component.html +++ b/frontend/src/app/components/location-card/location-card.component.html @@ -1,5 +1,5 @@
diff --git a/frontend/src/app/pages/home/home.component.html b/frontend/src/app/pages/home/home.component.html index 6915e45..cba853a 100644 --- a/frontend/src/app/pages/home/home.component.html +++ b/frontend/src/app/pages/home/home.component.html @@ -1,53 +1,50 @@
Location Address or description.
+Location Address or description.
+Location Address or description.
+Location Address or description.
+