From 0c41f3da818867341770c7b4846d17fb5e6035f6 Mon Sep 17 00:00:00 2001 From: Sameer Shaik Date: Sat, 2 Nov 2024 00:42:50 +0530 Subject: [PATCH] fix: server --- landing_page/.gitignore | 1 + landing_page/package-lock.json | 91 +++++++++++++++++++++++ landing_page/package.json | 1 + landing_page/src/App.tsx | 34 ++++++++- server/controller/SubscriberController.js | 11 ++- server/index.js | 2 +- server/routes/SubscriberRoutes.js | 6 +- 7 files changed, 139 insertions(+), 7 deletions(-) create mode 100644 landing_page/.gitignore diff --git a/landing_page/.gitignore b/landing_page/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/landing_page/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/landing_page/package-lock.json b/landing_page/package-lock.json index 2a3e552..5abee7a 100644 --- a/landing_page/package-lock.json +++ b/landing_page/package-lock.json @@ -8,6 +8,7 @@ "name": "landing_page", "version": "0.0.0", "dependencies": { + "axios": "^1.7.7", "react": "^18.3.1", "react-dom": "^18.3.1", "sweetalert": "^2.1.2" @@ -1597,6 +1598,11 @@ "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", "dev": true }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, "node_modules/autoprefixer": { "version": "10.4.20", "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.20.tgz", @@ -1634,6 +1640,16 @@ "postcss": "^8.1.0" } }, + "node_modules/axios": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -1814,6 +1830,17 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commander": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", @@ -1890,6 +1917,14 @@ "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/didyoumean": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz", @@ -2266,6 +2301,25 @@ "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", "dev": true }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/foreground-child": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.0.tgz", @@ -2282,6 +2336,19 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/form-data": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", + "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fraction.js": { "version": "4.3.7", "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.3.7.tgz", @@ -2711,6 +2778,25 @@ "node": ">=8.6" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -3131,6 +3217,11 @@ "resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-6.1.0.tgz", "integrity": "sha512-g0LWaH0gFsxovsU7R5LrrhHhWAWiHRnh1GPrhXnPgYsDkIqjRYUYSZEsej/wtleDrz5xVSIDbeKfidztp2XHFQ==" }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", diff --git a/landing_page/package.json b/landing_page/package.json index 5b5ca60..ac696a8 100644 --- a/landing_page/package.json +++ b/landing_page/package.json @@ -12,6 +12,7 @@ "preview": "vite preview" }, "dependencies": { + "axios": "^1.7.7", "react": "^18.3.1", "react-dom": "^18.3.1", "sweetalert": "^2.1.2" diff --git a/landing_page/src/App.tsx b/landing_page/src/App.tsx index 345414f..3be1bf8 100644 --- a/landing_page/src/App.tsx +++ b/landing_page/src/App.tsx @@ -1,5 +1,6 @@ import { useEffect, useState } from "react"; import swal from "sweetalert"; +import axios from "axios"; interface ScreenSize { width: number; height: number; @@ -13,6 +14,26 @@ export default function App() { height: window.innerHeight, }); + const SubscribeUser = async (email: string): Promise => { + try { + const response = await axios.post( + "http://localhost:8080/api/v0/launch/register", + { + email: email, + } + ); + if (response.status === 201) { + swal("Subscribed", "Subscribed to SKIN AI", "success"); + return true; + } + swal("Error While Subscribing", "Error While Subscribing", "error"); + return false; + } catch (error) { + swal("Error While Subscribing", "Error While Subscribing", "error"); + return false; + } + }; + function isEmailValid(email: string): boolean { const emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/; return emailRegex.test(email); @@ -30,14 +51,19 @@ export default function App() { return () => window.removeEventListener("resize", screenSetup); }, [screen]); - const handleEmail = () => { + const handleEmail = async () => { if (isEmailValid(email)) { - setFlag(true); setEmail(""); - swal("Thanks for Joining", "You have registered", "success"); + const response = await SubscribeUser(email); + + if (response) { + setFlag(true); + return swal("Thanks for Joining", "You have registered", "success"); + } + return swal("unable to register", "Error While Registering", "warning"); } else { setEmail(""); - swal("Email Error", "Provide Correct Email", "warning"); + swal("Email Error", "Provide Correct Email", "error"); } }; return ( diff --git a/server/controller/SubscriberController.js b/server/controller/SubscriberController.js index 985b08a..2ef0889 100644 --- a/server/controller/SubscriberController.js +++ b/server/controller/SubscriberController.js @@ -41,4 +41,13 @@ const SubscriberRegister = async (req, res) => { } }; -module.exports = { SubscriberRegister }; +const AllSubscribers = async (req, res) => { + try { + const users = await Subscriber.find(); + return res.status(200).send({ subscribers: users }); + } catch (error) { + return res.status(500).send({ message: error }); + } +}; + +module.exports = { SubscriberRegister, AllSubscribers }; diff --git a/server/index.js b/server/index.js index 705c3f4..c359cb2 100644 --- a/server/index.js +++ b/server/index.js @@ -13,7 +13,7 @@ app.use(cors()); app.use(bodyParser.json()); /** User Routes */ -app.use("/api/v0/launch", SubscriberRouter); +app.use("/api/v1/launch", SubscriberRouter); app.use("/api/v1/user", UserRouter); app.get("/", (req, res) => { diff --git a/server/routes/SubscriberRoutes.js b/server/routes/SubscriberRoutes.js index f661a9e..eb1da29 100644 --- a/server/routes/SubscriberRoutes.js +++ b/server/routes/SubscriberRoutes.js @@ -1,9 +1,13 @@ const express = require("express"); const { Router } = express; -const { SubscriberRegister } = require("../controller/SubscriberController"); +const { + SubscriberRegister, + AllSubscribers, +} = require("../controller/SubscriberController"); const SubscriberRouter = Router(); SubscriberRouter.post("/register", SubscriberRegister); +SubscriberRouter.get("/subscribers", AllSubscribers); module.exports = SubscriberRouter;