diff --git a/ef-api/controllers/mysqlproperty.js b/ef-api/controllers/mysqlproperty.js new file mode 100644 index 0000000..3009daf --- /dev/null +++ b/ef-api/controllers/mysqlproperty.js @@ -0,0 +1,31 @@ +import mysql from "mysql2"; + +// MySQL connection setup (you can move this to a separate config file if needed) +const db = mysql.createConnection({ + host: "db-mysql-nyc1-99306-do-user-12431193-0.b.db.ondigitalocean.com", + user: "doadmin", + password: "AVNS_EPHqPilzmVjZfm8GH4G", + database: "defaultdb", + port: "25060", +}); + +// Connect to MySQL database +db.connect((err) => { + if (err) { + console.error("Database connection failed: " + err.stack); + return; + } + console.log("Connected to the MYSQL database."); +}); + +// Controller function +export const searchMySQL = (req, res) => { + const q = "SELECT * FROM client_info"; + db.query(q, (err, data) => { + if (err) { + console.log(err); + return res.status(500).json({ error: "Database query failed" }); + } + return res.json(data); + }); +}; diff --git a/ef-api/controllers/property.js b/ef-api/controllers/property.js index 3c092c4..898844d 100644 --- a/ef-api/controllers/property.js +++ b/ef-api/controllers/property.js @@ -42,8 +42,6 @@ export const getUserProperties = async (req, res) => { } }; - - // Fetch property by ID export const getPropertyById = async (req, res) => { const { propertyId } = req.params; @@ -54,3 +52,9 @@ export const getPropertyById = async (req, res) => { res.status(404).json({ message: "Something went wrong" }); } }; + + + + + + diff --git a/ef-api/index.js b/ef-api/index.js index b37f73b..0a31344 100644 --- a/ef-api/index.js +++ b/ef-api/index.js @@ -1,14 +1,14 @@ import express from "express"; import mongoose from "mongoose"; +import mysql from "mysql2"; import cors from "cors"; import morgan from "morgan"; import session from "express-session"; import userRouter from "./routes/user.js"; import propertyRouter from "./routes/property.js"; +import mysqlRouter from "./routes/mysqlproperty.js"; import dotenv from "dotenv"; - - const app = express(); dotenv.config(); @@ -23,7 +23,6 @@ app.use(cors()); // })); app.use(express.static('dist')); - app.use( session({ secret: process.env.SECRET_KEY, @@ -34,6 +33,8 @@ app.use( app.use("/users", userRouter); app.use("/properties", propertyRouter); +app.use("/mysql", mysqlRouter); // Use MySQL routes + app.get("/", (req, res) => { @@ -42,7 +43,6 @@ app.get("/", (req, res) => { const port = process.env.PORT || 5000; - // Connect to the database const dbConnectionPromise = mongoose.connect(process.env.DB_ACCESS, { // useNewUrlParser: true, @@ -59,7 +59,7 @@ const startHttpServer = () => { // Handle database connection success/failure dbConnectionPromise .then(() => { - console.log("Connected to the database"); + console.log("Connected to the MONGO database"); }) .catch((error) => { console.log(`${error} did not connect`); diff --git a/ef-api/package-lock.json b/ef-api/package-lock.json index 636324c..5dab8ae 100644 --- a/ef-api/package-lock.json +++ b/ef-api/package-lock.json @@ -18,6 +18,8 @@ "jsonwebtoken": "^9.0.2", "mongoose": "^8.6.0", "morgan": "^1.10.0", + "mysql": "^2.18.1", + "mysql2": "^3.11.3", "nodemailer": "^6.9.14", "uuid": "^10.0.0" } @@ -65,6 +67,15 @@ "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", "license": "MIT" }, + "node_modules/aws-ssl-profiles": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz", + "integrity": "sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g==", + "license": "MIT", + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/basic-auth": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", @@ -89,6 +100,15 @@ "integrity": "sha512-V/Hy/X9Vt7f3BbPJEi8BdVFMByHi+jNXrYkW3huaybV/kQ0KJg0Y6PkEMbn+zeT+i+SiKZ/HMqJGIIt4LZDqNQ==", "license": "MIT" }, + "node_modules/bignumber.js": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", + "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==", + "license": "MIT", + "engines": { + "node": "*" + } + }, "node_modules/body-parser": { "version": "1.20.2", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", @@ -192,6 +212,12 @@ "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==", "license": "MIT" }, + "node_modules/core-util-is": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", + "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", + "license": "MIT" + }, "node_modules/cors": { "version": "2.8.5", "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", @@ -231,6 +257,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/denque": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", + "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", + "license": "Apache-2.0", + "engines": { + "node": ">=0.10" + } + }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -438,6 +473,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/generate-function": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz", + "integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==", + "license": "MIT", + "dependencies": { + "is-property": "^1.0.2" + } + }, "node_modules/get-intrinsic": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", @@ -560,6 +604,18 @@ "node": ">= 0.10" } }, + "node_modules/is-property": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", + "integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==", + "license": "MIT" + }, + "node_modules/isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "license": "MIT" + }, "node_modules/jsonwebtoken": { "version": "9.0.2", "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz", @@ -660,6 +716,36 @@ "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==", "license": "MIT" }, + "node_modules/long": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", + "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==", + "license": "Apache-2.0" + }, + "node_modules/lru-cache": { + "version": "7.18.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", + "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", + "license": "ISC", + "engines": { + "node": ">=12" + } + }, + "node_modules/lru.min": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/lru.min/-/lru.min-1.1.0.tgz", + "integrity": "sha512-86xXMB6DiuKrTqkE/lRL0drlNh568awttBPJ7D66fzDHpy6NC5r3N+Ly/lKCS2zjmeGyvFDx670z0cD0PVBwGA==", + "license": "MIT", + "engines": { + "bun": ">=1.0.0", + "deno": ">=1.30.0", + "node": ">=8.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wellwelwel" + } + }, "node_modules/media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -885,6 +971,80 @@ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "license": "MIT" }, + "node_modules/mysql": { + "version": "2.18.1", + "resolved": "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz", + "integrity": "sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig==", + "license": "MIT", + "dependencies": { + "bignumber.js": "9.0.0", + "readable-stream": "2.3.7", + "safe-buffer": "5.1.2", + "sqlstring": "2.3.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mysql/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "license": "MIT" + }, + "node_modules/mysql2": { + "version": "3.11.3", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.11.3.tgz", + "integrity": "sha512-Qpu2ADfbKzyLdwC/5d4W7+5Yz7yBzCU05YWt5npWzACST37wJsB23wgOSo00qi043urkiRwXtEvJc9UnuLX/MQ==", + "license": "MIT", + "dependencies": { + "aws-ssl-profiles": "^1.1.1", + "denque": "^2.1.0", + "generate-function": "^2.3.1", + "iconv-lite": "^0.6.3", + "long": "^5.2.1", + "lru.min": "^1.0.0", + "named-placeholders": "^1.1.3", + "seq-queue": "^0.0.5", + "sqlstring": "^2.3.2" + }, + "engines": { + "node": ">= 8.0" + } + }, + "node_modules/mysql2/node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/mysql2/node_modules/sqlstring": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz", + "integrity": "sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/named-placeholders": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.3.tgz", + "integrity": "sha512-eLoBxg6wE/rZkJPhU/xRX1WTpkFEwDJEN96oxFrTsqBdbT5ec295Q+CoHrL9IT0DipqKhmGcaZmwOt8OON5x1w==", + "license": "MIT", + "dependencies": { + "lru-cache": "^7.14.1" + }, + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/negotiator": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", @@ -960,6 +1120,12 @@ "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==", "license": "MIT" }, + "node_modules/process-nextick-args": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", + "license": "MIT" + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -1030,6 +1196,27 @@ "node": ">= 0.8" } }, + "node_modules/readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "license": "MIT", + "dependencies": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "node_modules/readable-stream/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "license": "MIT" + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -1098,6 +1285,11 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "license": "MIT" }, + "node_modules/seq-queue": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/seq-queue/-/seq-queue-0.0.5.tgz", + "integrity": "sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q==" + }, "node_modules/serve-static": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz", @@ -1169,6 +1361,15 @@ "memory-pager": "^1.0.2" } }, + "node_modules/sqlstring": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz", + "integrity": "sha512-ooAzh/7dxIG5+uDik1z/Rd1vli0+38izZhGzSa34FwR7IbelPWCCKSNIl8jlL/F7ERvy8CB2jNeM1E9i9mXMAQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", @@ -1178,6 +1379,21 @@ "node": ">= 0.8" } }, + "node_modules/string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "license": "MIT", + "dependencies": { + "safe-buffer": "~5.1.0" + } + }, + "node_modules/string_decoder/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "license": "MIT" + }, "node_modules/toidentifier": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", @@ -1233,6 +1449,12 @@ "node": ">= 0.8" } }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", + "license": "MIT" + }, "node_modules/utils-merge": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", diff --git a/ef-api/package.json b/ef-api/package.json index 35210a7..9f6b99d 100644 --- a/ef-api/package.json +++ b/ef-api/package.json @@ -20,6 +20,8 @@ "jsonwebtoken": "^9.0.2", "mongoose": "^8.6.0", "morgan": "^1.10.0", + "mysql": "^2.18.1", + "mysql2": "^3.11.3", "nodemailer": "^6.9.14", "uuid": "^10.0.0" } diff --git a/ef-api/routes/mysqlproperty.js b/ef-api/routes/mysqlproperty.js new file mode 100644 index 0000000..c4325d4 --- /dev/null +++ b/ef-api/routes/mysqlproperty.js @@ -0,0 +1,9 @@ +import express from "express"; +import { searchMySQL } from "../controllers/mysqlproperty.js"; + +const router = express.Router(); + +// Define the route +router.get("/searchmysql", searchMySQL); + +export default router; diff --git a/ef-api/routes/property.js b/ef-api/routes/property.js index d40978c..dd32c1c 100644 --- a/ef-api/routes/property.js +++ b/ef-api/routes/property.js @@ -1,16 +1,10 @@ import express from 'express'; const router = express.Router(); import auth from '../middleware/auth.js'; -import { createProperty, getUserProperties, getPropertyById } from '../controllers/property.js'; +import { createProperty, getUserProperties, getPropertyById} from '../controllers/property.js'; router.post('/', auth, createProperty); router.get('/user/:userId', getUserProperties); router.get('/:propertyId', getPropertyById); - - - - - - export default router; diff --git a/ef-ui/src/App.jsx b/ef-ui/src/App.jsx index c51ecbc..bbd15fa 100644 --- a/ef-ui/src/App.jsx +++ b/ef-ui/src/App.jsx @@ -13,24 +13,29 @@ import ResetPassword from "./components/ResetPassword"; // import Addproperty from "./components/Addproperty"; import Registrationsuccess from "./components/Registrationsuccess"; import PropertyView from "./components/PropertyView"; +import SearchMysql from "./components/SearchMysql"; const App = () => { return ( - - - - }> - }> - }> - }> + + + + }> + }> + }> + }> - }> + + + + } + > - - - - }> - }> + @@ -38,26 +43,23 @@ const App = () => { } /> - } /> - - }> + } /> -} -/> + }> -{/* }> */} + } + /> -} /> + {/* }> */} + } /> - - - - + } /> + - ) -} + ); +}; -export default App \ No newline at end of file +export default App; diff --git a/ef-ui/src/components/Navbar.jsx b/ef-ui/src/components/Navbar.jsx index 2547e62..1dd2902 100644 --- a/ef-ui/src/components/Navbar.jsx +++ b/ef-ui/src/components/Navbar.jsx @@ -64,6 +64,11 @@ const Navbar = () => { Services +
  • + + Search + +
  • About diff --git a/ef-ui/src/components/SearchMysql.jsx b/ef-ui/src/components/SearchMysql.jsx new file mode 100644 index 0000000..950b2df --- /dev/null +++ b/ef-ui/src/components/SearchMysql.jsx @@ -0,0 +1,36 @@ +import { useEffect, useState } from "react"; +import axios from "axios"; + +const SearchMysql = () => { + const [properties, setProperties] = useState([]); + + // Fetch data from backend API + useEffect(() => { + const fetchAllProperties = async () => { + try { + const res = await axios.get(`${import.meta.env.VITE_REACT_APP_SECRET}/mysql/searchmysql`); + setProperties(res.data); // Set the data to the state + } catch (err) { + console.log("Error fetching data:", err); + } + }; + fetchAllProperties(); + }, []); + + return ( + <> + {/* Check if properties array is populated before mapping */} + {properties && properties.length > 0 ? ( + properties.map((property, index) => ( +
    +

    {property.client_name}

    {/* Display client_name */} +
    + )) + ) : ( +

    No properties found.

    + )} + + ); +}; + +export default SearchMysql; diff --git a/ef-ui/src/redux/features/propertySlice.js b/ef-ui/src/redux/features/propertySlice.js index d4f3e1b..c4bf5f8 100644 --- a/ef-ui/src/redux/features/propertySlice.js +++ b/ef-ui/src/redux/features/propertySlice.js @@ -1,5 +1,4 @@ import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'; -import axios from 'axios'; import * as api from "../api"; export const submitProperty = createAsyncThunk(