From eddb18ba1744f49c8c9ba43b98a25a12442b8a4e Mon Sep 17 00:00:00 2001 From: Manoj Date: Tue, 10 Sep 2024 08:49:42 +0530 Subject: [PATCH 01/13] user signup & signin --- week-1/problems/vs/index.css | 63 +++++ week-1/problems/vs/index.html | 106 ++++++++ week-5/backend/db/index.js | 74 ++++- week-5/backend/index.js | 20 +- week-5/backend/middleware/user.js | 17 +- week-5/backend/package-lock.json | 433 +++++++++++++++++++++++++++++- week-5/backend/package.json | 7 +- week-5/backend/routes/user.js | 14 +- week-5/frontend/index.html | 18 ++ week-5/frontend/script.js | 8 +- week-5/frontend/style.css | 10 +- 11 files changed, 761 insertions(+), 9 deletions(-) create mode 100644 week-1/problems/vs/index.css create mode 100644 week-1/problems/vs/index.html diff --git a/week-1/problems/vs/index.css b/week-1/problems/vs/index.css new file mode 100644 index 00000000..efa03afc --- /dev/null +++ b/week-1/problems/vs/index.css @@ -0,0 +1,63 @@ +body{ + background-color: rgb(19, 18, 18); + margin:10px 50px; + color: rgb(245, 233, 233); + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; +} + +.navbar{ + display: flex; + justify-content: space-between; + margin: 10px; + align-items: center; +} + +.items{ + display: flex; + justify-content: space-between; +} + +a{ + text-decoration: none; + color: rgb(176, 176, 176); + margin:0 10px; +} + +.info{ + display: grid; + grid-template-columns: 1fr 2fr; + margin: 20px; + align-items: center; +} + +input ,button{ + padding: 0.75em; + border-radius: 10px; + border: none; +} + +.info>div>h1{ + margin:10px 0; +} + +button{ + background-color: rgb(0, 140, 255); + color:white; + +} + +.container{ + display: grid; + grid-template-columns: 1fr 2fr; +} +.languagePanel{ + display: grid; + grid-template-columns: 1fr 1fr 1fr; +} +.flex{ + display: flex; + align-items: center; +} +.flex>img{ + width: 2em; +} \ No newline at end of file diff --git a/week-1/problems/vs/index.html b/week-1/problems/vs/index.html new file mode 100644 index 00000000..5d1d9cd8 --- /dev/null +++ b/week-1/problems/vs/index.html @@ -0,0 +1,106 @@ + + + + + + Visual Studio + + + + + +
Version 1.92 is now available! Read about the new features and fixes from July.
+ +
+
+ +

Code

+

Editing.

+

Redefined.

+ +
+
+ +
+
+ + + +
+
+
+

Code in any language

+

VS Code supports almost every major programming language. Several ship in the box, like JavaScript, + TypeScript, CSS, and HTML, but extensions for others can be found in the VS Code Marketplace.

+
+
+
+ Javascript + JavaScript +
+
+ TypeScript + TypeScript +
+
+ Python + Python +
+
+ C# + C# +
+
+ C++ + C++ +
+
+ HTML + HTML +
+
+ Java + Java +
+
+ JSON + JSON +
+
+ PHP + PHP +
+
+ Markdown + Markdown +
+
+ Powershell + Powershell +
+
+ YAML + YAML +
+
+
+
+ + \ No newline at end of file diff --git a/week-5/backend/db/index.js b/week-5/backend/db/index.js index 675aa4cb..7a0ec244 100644 --- a/week-5/backend/db/index.js +++ b/week-5/backend/db/index.js @@ -1 +1,73 @@ -// start writing from here \ No newline at end of file +// start writing from here +const jwt=require('jsonwebtoken'); + +let users=[]; + + +const generateJWT=(username)=>{ + // const userame=req.body.username; + const token=jwt.sign({username:username},process.env.JWT_SECRET) + return token; +} + + + +const signup=(req,res)=>{ + const user={username:req.body.username,password:req.body.password}; + if(!user.username||!user.password){ + return res.status(403).send({message:"User Details required"}); + } + + for(let i=0;i{ + const user={username:req.body.username,password:req.body.password}; + if(!user.username||!user.password){ + return res.status(403).send({message:"User Details required"}); + } + + for(let i=0;i{ + +} + +module.exports={ + signup, + signin, + logout +}; \ No newline at end of file diff --git a/week-5/backend/index.js b/week-5/backend/index.js index 2fd17dfa..d3110754 100644 --- a/week-5/backend/index.js +++ b/week-5/backend/index.js @@ -1 +1,19 @@ -// start writing from here \ No newline at end of file +// start writing from here + +const http=require('http'); +const express=require('express'); +require('dotenv').config(); +const userRouter=require("./routes/user.js"); +const todoRouter=require("./routes/todo.js"); + +const PORT=process.env.PORT; +const app=express(); +const server=http.createServer(app); + +app.use(express.json()); +app.use('/user',userRouter) +// app.use("/todo",todoRouter) + +server.listen(PORT,()=>{console.log(`Server running on PORT ${PORT}`); +}) + diff --git a/week-5/backend/middleware/user.js b/week-5/backend/middleware/user.js index 675aa4cb..aaec779b 100644 --- a/week-5/backend/middleware/user.js +++ b/week-5/backend/middleware/user.js @@ -1 +1,16 @@ -// start writing from here \ No newline at end of file +// start writing from here +const jwt=require('jsonwebtoken'); + +const verifyJWT=(req,res,next)=>{ + const token=req.headers.authorization; + const decoded=jwt.verify(token, process.env.JWT_SECRET); + const username=decoded.username; + if(!username){ + return res.status(401) + .send({message:"Unathorized request"}) + } + + next(); +} + +module.exports=verifyJWT; \ No newline at end of file diff --git a/week-5/backend/package-lock.json b/week-5/backend/package-lock.json index 1f376c90..0dd2b4da 100644 --- a/week-5/backend/package-lock.json +++ b/week-5/backend/package-lock.json @@ -11,7 +11,10 @@ "dependencies": { "dotenv": "^16.4.5", "express": "^4.19.2", - "mongoose": "^8.6.1" + "jsonwebtoken": "^9.0.2", + "mongoose": "^8.6.1", + "nodemon": "^3.1.4", + "router": "^1.3.8" } }, "node_modules/@mongodb-js/saslprep": { @@ -51,12 +54,40 @@ "node": ">= 0.6" } }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", "license": "MIT" }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, + "node_modules/binary-extensions": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", + "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/body-parser": { "version": "1.20.2", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", @@ -81,6 +112,26 @@ "npm": "1.2.8000 || >= 1.4.16" } }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/braces": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "dependencies": { + "fill-range": "^7.1.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/bson": { "version": "6.8.0", "resolved": "https://registry.npmjs.org/bson/-/bson-6.8.0.tgz", @@ -90,6 +141,11 @@ "node": ">=16.20.1" } }, + "node_modules/buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==" + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -118,6 +174,34 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/chokidar": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + }, "node_modules/content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", @@ -211,6 +295,14 @@ "url": "https://dotenvx.com" } }, + "node_modules/ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -304,6 +396,17 @@ "node": ">= 0.10.0" } }, + "node_modules/fill-range": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/finalhandler": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", @@ -340,6 +443,19 @@ "node": ">= 0.6" } }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -368,6 +484,17 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/gopd": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", @@ -380,6 +507,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "engines": { + "node": ">=4" + } + }, "node_modules/has-property-descriptors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", @@ -456,6 +591,11 @@ "node": ">=0.10.0" } }, + "node_modules/ignore-by-default": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", + "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==" + }, "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", @@ -471,6 +611,89 @@ "node": ">= 0.10" } }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/jsonwebtoken": { + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz", + "integrity": "sha512-PRp66vJ865SSqOlgqS8hujT5U4AOgMfhrwYIuIhfKaoSCZcirrmASQr8CX7cUg+RMih+hgznrjp99o+W4pJLHQ==", + "dependencies": { + "jws": "^3.2.2", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^7.5.4" + }, + "engines": { + "node": ">=12", + "npm": ">=6" + } + }, + "node_modules/jsonwebtoken/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/jwa": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz", + "integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==", + "dependencies": { + "buffer-equal-constant-time": "1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/jws": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz", + "integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==", + "dependencies": { + "jwa": "^1.4.1", + "safe-buffer": "^5.0.1" + } + }, "node_modules/kareem": { "version": "2.6.3", "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.6.3.tgz", @@ -480,6 +703,41 @@ "node": ">=12.0.0" } }, + "node_modules/lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==" + }, + "node_modules/lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==" + }, + "node_modules/lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==" + }, + "node_modules/lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==" + }, + "node_modules/lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==" + }, + "node_modules/lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==" + }, + "node_modules/lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==" + }, "node_modules/media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -543,6 +801,17 @@ "node": ">= 0.6" } }, + "node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/mongodb": { "version": "6.8.0", "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.8.0.tgz", @@ -686,6 +955,62 @@ "node": ">= 0.6" } }, + "node_modules/nodemon": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.4.tgz", + "integrity": "sha512-wjPBbFhtpJwmIeY2yP7QF+UKzPfltVGtfce1g/bB15/8vCGZj8uxD62b/b9M9/WVgme0NZudpownKN+c0plXlQ==", + "dependencies": { + "chokidar": "^3.5.2", + "debug": "^4", + "ignore-by-default": "^1.0.1", + "minimatch": "^3.1.2", + "pstree.remy": "^1.1.8", + "semver": "^7.5.3", + "simple-update-notifier": "^2.0.0", + "supports-color": "^5.5.0", + "touch": "^3.1.0", + "undefsafe": "^2.0.5" + }, + "bin": { + "nodemon": "bin/nodemon.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nodemon" + } + }, + "node_modules/nodemon/node_modules/debug": { + "version": "4.3.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", + "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/nodemon/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/object-inspect": { "version": "1.13.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", @@ -725,6 +1050,17 @@ "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==", "license": "MIT" }, + "node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -738,6 +1074,11 @@ "node": ">= 0.10" } }, + "node_modules/pstree.remy": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", + "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==" + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -786,6 +1127,39 @@ "node": ">= 0.8" } }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, + "node_modules/router": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/router/-/router-1.3.8.tgz", + "integrity": "sha512-461UFH44NtSfIlS83PUg2N7OZo86BC/kB3dY77gJdsODsBhhw7+2uE0tzTINxrY9CahCUVk1VhpWCA5i1yoIEg==", + "dependencies": { + "array-flatten": "3.0.0", + "debug": "2.6.9", + "methods": "~1.1.2", + "parseurl": "~1.3.3", + "path-to-regexp": "0.1.7", + "setprototypeof": "1.2.0", + "utils-merge": "1.0.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/router/node_modules/array-flatten": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-3.0.0.tgz", + "integrity": "sha512-zPMVc3ZYlGLNk4mpK1NzP2wg0ml9t7fUgDsayR5Y5rSzxQilzR9FGu/EH2jQOcKSAeAfWeylyW8juy3OkWRvNA==" + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -812,6 +1186,17 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "license": "MIT" }, + "node_modules/semver": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/send": { "version": "0.18.0", "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", @@ -904,6 +1289,17 @@ "integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==", "license": "MIT" }, + "node_modules/simple-update-notifier": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", + "integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==", + "dependencies": { + "semver": "^7.5.3" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/sparse-bitfield": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", @@ -922,6 +1318,28 @@ "node": ">= 0.8" } }, + "node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, "node_modules/toidentifier": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", @@ -931,6 +1349,14 @@ "node": ">=0.6" } }, + "node_modules/touch": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.1.tgz", + "integrity": "sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==", + "bin": { + "nodetouch": "bin/nodetouch.js" + } + }, "node_modules/tr46": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/tr46/-/tr46-4.1.1.tgz", @@ -956,6 +1382,11 @@ "node": ">= 0.6" } }, + "node_modules/undefsafe": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", + "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==" + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", diff --git a/week-5/backend/package.json b/week-5/backend/package.json index 2efd5287..0c374640 100644 --- a/week-5/backend/package.json +++ b/week-5/backend/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "dev": "nodemon index.js" }, "keywords": [], "author": "", @@ -12,6 +12,9 @@ "dependencies": { "dotenv": "^16.4.5", "express": "^4.19.2", - "mongoose": "^8.6.1" + "jsonwebtoken": "^9.0.2", + "mongoose": "^8.6.1", + "nodemon": "^3.1.4", + "router": "^1.3.8" } } diff --git a/week-5/backend/routes/user.js b/week-5/backend/routes/user.js index 4be9f96e..4e6f03dd 100644 --- a/week-5/backend/routes/user.js +++ b/week-5/backend/routes/user.js @@ -1 +1,13 @@ -// start writing your code from here \ No newline at end of file +// start writing your code from here + +const express=require('express'); +const router=express.Router(); +const verifyJWT = require('../middleware/user'); +const { signup, signin, logout } = require('../db/index.js'); + + +router.post("/signup",signup); +router.get('/signin',signin); +router.get('/logout',verifyJWT,logout); + +module.exports=router; \ No newline at end of file diff --git a/week-5/frontend/index.html b/week-5/frontend/index.html index 794d1dd7..b7ecd6ae 100644 --- a/week-5/frontend/index.html +++ b/week-5/frontend/index.html @@ -8,6 +8,24 @@ +
+ + + +
+
+ Already have an account? +
+
+ + + +
+ +
+ +
+ \ No newline at end of file diff --git a/week-5/frontend/script.js b/week-5/frontend/script.js index 722bb62e..29cc44e0 100644 --- a/week-5/frontend/script.js +++ b/week-5/frontend/script.js @@ -1 +1,7 @@ -// start from here \ No newline at end of file +// start from here + +const changerButton=document.getElementById("changer"); +changerButton.addEventListener('click',()=>{ + const signin=document.getElementById("signin"); + signin.style.display:"initial"; +}) \ No newline at end of file diff --git a/week-5/frontend/style.css b/week-5/frontend/style.css index 9bff184c..7a742be3 100644 --- a/week-5/frontend/style.css +++ b/week-5/frontend/style.css @@ -1 +1,9 @@ - /* start from here */ \ No newline at end of file + /* start from here */ + + #signin{ + display:none ; + } + + #logout{ + display: none; + } \ No newline at end of file From 74a1804b7ae5ec45dec18f1147df26f80e690e4c Mon Sep 17 00:00:00 2001 From: Manoj Date: Wed, 11 Sep 2024 09:11:08 +0530 Subject: [PATCH 02/13] todo's create, update, delete, get, marked as done --- week-5/backend/db/index.js | 124 +++++++++++++++++++++++++++++++++- week-5/backend/index.js | 2 +- week-5/backend/routes/todo.js | 15 +++- week-5/frontend/index.html | 22 +++++- week-5/frontend/script.js | 2 +- 5 files changed, 157 insertions(+), 8 deletions(-) diff --git a/week-5/backend/db/index.js b/week-5/backend/db/index.js index 7a0ec244..c5bef444 100644 --- a/week-5/backend/db/index.js +++ b/week-5/backend/db/index.js @@ -13,7 +13,12 @@ const generateJWT=(username)=>{ const signup=(req,res)=>{ - const user={username:req.body.username,password:req.body.password}; + const user={ + username:req.body.username, + password:req.body.password, + todosCount:0, + todos:[] + }; if(!user.username||!user.password){ return res.status(403).send({message:"User Details required"}); } @@ -66,8 +71,123 @@ const logout=(req,res)=>{ } + + +//TODOs list/create/delete/update/done marking + +const allTodos=(req,res)=>{ + if(!username){ + return res.status(400).send({message:"User required"}); + } + for(let i=0;i{ + if(!username||!req.body.todo){ + return res.status(400).send({message:"Details required"}); + } + for(let i=0;i{ + //validate the details from req + //search for user + //search for todo + //delete the todo + //Didn't find the user + + if(!username||!req.body.todo){ + return res.status(400).send({message:"Details required"}); + } + for(let i=0;i{ + //validate the details + //find the user + //find the todo + //mark todo as completed + + if(!username||!req.body.todo){ + return res.status(400).send({message:"Details required"}); + } + for(let i=0;i{ + if(!username||!req.body.todo){ + return res.status(400).send({message:"Details required"}); + } + for(let i=0;i{console.log(`Server running on PORT ${PORT}`); }) diff --git a/week-5/backend/routes/todo.js b/week-5/backend/routes/todo.js index 4be9f96e..6511fb93 100644 --- a/week-5/backend/routes/todo.js +++ b/week-5/backend/routes/todo.js @@ -1 +1,14 @@ -// start writing your code from here \ No newline at end of file +// start writing your code from here + +const express=require('express'); +const { createTodo, updateTodo, deleteTodo, allTodos, completeTodo } = require('../db'); +const verifyJWT = require('../middleware/user'); +const router=express.Router(); + +router.post("/create-todo",verifyJWT,createTodo); +router.patch("update-todo",verifyJWT, updateTodo); +router.post('delete-todo',verifyJWT, deleteTodo); +router.get('todos-list',verifyJWT, allTodos); +router.patch('finish-todo',verifyJWT,completeTodo); + +module.exports=router; \ No newline at end of file diff --git a/week-5/frontend/index.html b/week-5/frontend/index.html index b7ecd6ae..574b972e 100644 --- a/week-5/frontend/index.html +++ b/week-5/frontend/index.html @@ -12,10 +12,11 @@ +
+ Already have an account? +
-
- Already have an account? -
+
@@ -26,6 +27,21 @@
+ +
+
+ + +
+
+
Task 1
+ + +
+
+
+
+ \ No newline at end of file diff --git a/week-5/frontend/script.js b/week-5/frontend/script.js index 29cc44e0..b09ddd7b 100644 --- a/week-5/frontend/script.js +++ b/week-5/frontend/script.js @@ -3,5 +3,5 @@ const changerButton=document.getElementById("changer"); changerButton.addEventListener('click',()=>{ const signin=document.getElementById("signin"); - signin.style.display:"initial"; + // signin.style.display:"initial"; }) \ No newline at end of file From fef7c64578f29bbce991872a7e05e268329cda9e Mon Sep 17 00:00:00 2001 From: Manoj Date: Thu, 12 Sep 2024 09:15:53 +0530 Subject: [PATCH 03/13] backend complete --- week-5/backend/db/index.js | 60 +++++++++++++++++-------------- week-5/backend/middleware/user.js | 6 ++-- week-5/backend/routes/todo.js | 8 ++--- 3 files changed, 41 insertions(+), 33 deletions(-) diff --git a/week-5/backend/db/index.js b/week-5/backend/db/index.js index c5bef444..c0c47c6f 100644 --- a/week-5/backend/db/index.js +++ b/week-5/backend/db/index.js @@ -4,9 +4,9 @@ const jwt=require('jsonwebtoken'); let users=[]; -const generateJWT=(username)=>{ - // const userame=req.body.username; - const token=jwt.sign({username:username},process.env.JWT_SECRET) +const generateJWT=(useremail)=>{ + // const userame=req.body.useremail; + const token=jwt.sign({useremail:useremail},process.env.JWT_SECRET) return token; } @@ -14,24 +14,24 @@ const generateJWT=(username)=>{ const signup=(req,res)=>{ const user={ - username:req.body.username, + useremail:req.body.useremail, password:req.body.password, todosCount:0, todos:[] }; - if(!user.username||!user.password){ + if(!user.useremail||!user.password){ return res.status(403).send({message:"User Details required"}); } for(let i=0;i{ } const signin=(req,res)=>{ - const user={username:req.body.username,password:req.body.password}; - if(!user.username||!user.password){ + const user={useremail:req.body.useremail,password:req.body.password}; + if(!user.useremail||!user.password){ return res.status(403).send({message:"User Details required"}); } for(let i=0;i{ //TODOs list/create/delete/update/done marking const allTodos=(req,res)=>{ - if(!username){ + const useremail=req.useremail; + if(!useremail){ return res.status(400).send({message:"User required"}); } for(let i=0;i{ } const createTodo=(req,res)=>{ - if(!username||!req.body.todo){ + const useremail=req.useremail; + if(!useremail||!req.body.todo){ return res.status(400).send({message:"Details required"}); } for(let i=0;i{ //delete the todo //Didn't find the user - if(!username||!req.body.todo){ + const useremail=req.useremail; + if(!useremail||!req.body.id){ return res.status(400).send({message:"Details required"}); } for(let i=0;i{ //find the todo //mark todo as completed - if(!username||!req.body.todo){ + const useremail=req.useremail; + if(!useremail||!req.body.id){ return res.status(400).send({message:"Details required"}); } for(let i=0;i{ } const updateTodo=(req,res)=>{ - if(!username||!req.body.todo){ + const useremail=req.useremail; + if(!useremail||!req.body.todo){ return res.status(400).send({message:"Details required"}); } for(let i=0;i{ const token=req.headers.authorization; const decoded=jwt.verify(token, process.env.JWT_SECRET); - const username=decoded.username; - if(!username){ + const useremail=decoded.useremail; + if(!useremail){ return res.status(401) .send({message:"Unathorized request"}) } - + req.useremail=useremail; next(); } diff --git a/week-5/backend/routes/todo.js b/week-5/backend/routes/todo.js index 6511fb93..3b544018 100644 --- a/week-5/backend/routes/todo.js +++ b/week-5/backend/routes/todo.js @@ -6,9 +6,9 @@ const verifyJWT = require('../middleware/user'); const router=express.Router(); router.post("/create-todo",verifyJWT,createTodo); -router.patch("update-todo",verifyJWT, updateTodo); -router.post('delete-todo',verifyJWT, deleteTodo); -router.get('todos-list',verifyJWT, allTodos); -router.patch('finish-todo',verifyJWT,completeTodo); +router.patch("/update-todo",verifyJWT, updateTodo); +router.post('/delete-todo',verifyJWT, deleteTodo); +router.get('/todos-list',verifyJWT, allTodos); +router.patch('/complete-todo',verifyJWT,completeTodo); module.exports=router; \ No newline at end of file From 09d0047572821d8c12bc870ca7a3e1cd9edc2c2a Mon Sep 17 00:00:00 2001 From: Manoj Date: Fri, 13 Sep 2024 09:12:54 +0530 Subject: [PATCH 04/13] user signup frontend --- week-5/backend/db/index.js | 6 +++++- week-5/backend/index.js | 4 ++-- week-5/backend/package-lock.json | 21 +++++++++++++++++++++ week-5/backend/package.json | 1 + week-5/frontend/index.html | 21 ++++++++++++--------- week-5/frontend/script.js | 28 ++++++++++++++++++++++++---- week-5/frontend/style.css | 4 ++-- 7 files changed, 67 insertions(+), 18 deletions(-) diff --git a/week-5/backend/db/index.js b/week-5/backend/db/index.js index c0c47c6f..46a61ab2 100644 --- a/week-5/backend/db/index.js +++ b/week-5/backend/db/index.js @@ -13,12 +13,16 @@ const generateJWT=(useremail)=>{ const signup=(req,res)=>{ + console.log(req.body); + const user={ useremail:req.body.useremail, password:req.body.password, todosCount:0, todos:[] - }; + } + console.log(user.useremail,user.password); + if(!user.useremail||!user.password){ return res.status(403).send({message:"User Details required"}); } diff --git a/week-5/backend/index.js b/week-5/backend/index.js index 16df605b..84516fc3 100644 --- a/week-5/backend/index.js +++ b/week-5/backend/index.js @@ -5,11 +5,11 @@ const express=require('express'); require('dotenv').config(); const userRouter=require("./routes/user.js"); const todoRouter=require("./routes/todo.js"); - +const cors=require('cors'); const PORT=process.env.PORT; const app=express(); const server=http.createServer(app); - +app.use(cors()) app.use(express.json()); app.use('/user',userRouter) app.use("/todo",todoRouter) diff --git a/week-5/backend/package-lock.json b/week-5/backend/package-lock.json index 0dd2b4da..4b15750a 100644 --- a/week-5/backend/package-lock.json +++ b/week-5/backend/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "cors": "^2.8.5", "dotenv": "^16.4.5", "express": "^4.19.2", "jsonwebtoken": "^9.0.2", @@ -238,6 +239,18 @@ "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==", "license": "MIT" }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -1011,6 +1024,14 @@ "node": ">=0.10.0" } }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/object-inspect": { "version": "1.13.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", diff --git a/week-5/backend/package.json b/week-5/backend/package.json index 0c374640..11ea0c11 100644 --- a/week-5/backend/package.json +++ b/week-5/backend/package.json @@ -10,6 +10,7 @@ "license": "ISC", "description": "", "dependencies": { + "cors": "^2.8.5", "dotenv": "^16.4.5", "express": "^4.19.2", "jsonwebtoken": "^9.0.2", diff --git a/week-5/frontend/index.html b/week-5/frontend/index.html index 574b972e..363572ed 100644 --- a/week-5/frontend/index.html +++ b/week-5/frontend/index.html @@ -8,16 +8,19 @@ -
- - - -
+ +
+ + + + + + +
-
+ diff --git a/week-5/frontend/script.js b/week-5/frontend/script.js index b09ddd7b..37f68783 100644 --- a/week-5/frontend/script.js +++ b/week-5/frontend/script.js @@ -1,7 +1,27 @@ // start from here -const changerButton=document.getElementById("changer"); -changerButton.addEventListener('click',()=>{ - const signin=document.getElementById("signin"); - // signin.style.display:"initial"; +const signupForm=document.getElementById('signup'); +signupForm.addEventListener("submit",(event)=>{ + event.preventDefault(); + const formData = new FormData(signupForm); + console.log(formData); + + const formDataObject={}; + formData.forEach((value,key)=>{ + formDataObject[key]=value; + }) + // console.log(formDataObject); + + fetch("http://localhost:3000/user/signup",{ + method:"POST", + headers:{ + 'Content-Type': 'application/json' + }, + body:JSON.stringify(formDataObject) + }) + .then(res=>res.json()) + .then(data=>{ + alert(data.message); + }) + .catch(err=>{alert("Signup failed")}); }) \ No newline at end of file diff --git a/week-5/frontend/style.css b/week-5/frontend/style.css index 7a742be3..37a42fa2 100644 --- a/week-5/frontend/style.css +++ b/week-5/frontend/style.css @@ -1,9 +1,9 @@ /* start from here */ - #signin{ + /* #signin{ display:none ; } #logout{ display: none; - } \ No newline at end of file + } */ \ No newline at end of file From d2a0ac3044fcdee31cf451333d2e4d8bf0294581 Mon Sep 17 00:00:00 2001 From: Manoj Date: Fri, 13 Sep 2024 09:23:02 +0530 Subject: [PATCH 05/13] login frontend functionalities --- week-5/backend/db/index.js | 2 +- week-5/backend/routes/user.js | 2 +- week-5/frontend/index.html | 11 ++++++++--- week-5/frontend/script.js | 27 +++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/week-5/backend/db/index.js b/week-5/backend/db/index.js index 46a61ab2..07148251 100644 --- a/week-5/backend/db/index.js +++ b/week-5/backend/db/index.js @@ -67,7 +67,7 @@ const signin=(req,res)=>{ return res .status(404) .send({ - message:"User doesn't exist" + message:"Email/Password incorrect" }) } diff --git a/week-5/backend/routes/user.js b/week-5/backend/routes/user.js index 4e6f03dd..dedf9294 100644 --- a/week-5/backend/routes/user.js +++ b/week-5/backend/routes/user.js @@ -7,7 +7,7 @@ const { signup, signin, logout } = require('../db/index.js'); router.post("/signup",signup); -router.get('/signin',signin); +router.post('/signin',signin); router.get('/logout',verifyJWT,logout); module.exports=router; \ No newline at end of file diff --git a/week-5/frontend/index.html b/week-5/frontend/index.html index 363572ed..12569dba 100644 --- a/week-5/frontend/index.html +++ b/week-5/frontend/index.html @@ -19,13 +19,18 @@ Already have an account?
--> + +
+ + + +
- -
- - -
-
-
Task 1
+ + +
+
-
--> +
diff --git a/week-5/frontend/script.js b/week-5/frontend/script.js index 0e49ce22..7597e183 100644 --- a/week-5/frontend/script.js +++ b/week-5/frontend/script.js @@ -1,10 +1,41 @@ // start from here +let todosCount=0; + +const populateTodo=(todos,cls,completed,title)=>{ + const divEl=document.createElement('div'); + divEl.setAttribute('class',cls); + + const checkboxEl=document.createElement('input'); + checkboxEl.setAttribute('type','checkbox'); + checkboxEl.setAttribute('class',cls); + checkboxEl.checked=completed; + + const inputEl=document.createElement('input'); + inputEl.setAttribute('class',cls); + inputEl.setAttribute('value',`${title}`); + + const deleteEl=document.createElement('button'); + deleteEl.innerHTML='Delete'; + deleteEl.setAttribute('class',cls); + + const updateEl=document.createElement('button'); + updateEl.innerHTML='Update'; + updateEl.setAttribute('class',cls); + + + divEl.appendChild(checkboxEl); + divEl.appendChild(inputEl); + divEl.appendChild(deleteEl); + divEl.appendChild(updateEl); + + todos.appendChild(divEl); +} + const signupForm=document.getElementById('signup'); signupForm.addEventListener("submit",(event)=>{ event.preventDefault(); const formData = new FormData(signupForm); - console.log(formData); const formDataObject={}; formData.forEach((value,key)=>{ @@ -21,9 +52,19 @@ signupForm.addEventListener("submit",(event)=>{ }) .then(res=>res.json()) .then(data=>{ + // if(data.token){ + // localStorage.setItem('authorization',data.token); + // console.log(data.token); + + // } alert(data.message); + if(data.message==="User signed up successfully") + signupForm.style.display='none' }) - .catch(err=>{alert("Signup failed")}); + .catch(err=>{ + console.log(err); + alert("Signup failed") + }); }) @@ -31,7 +72,7 @@ const signinForm=document.getElementById('signin'); signinForm.addEventListener("submit",(event)=>{ event.preventDefault(); const formData = new FormData(signinForm); - console.log(formData); + // console.log(formData); const formDataObject={}; formData.forEach((value,key)=>{ @@ -48,7 +89,217 @@ signinForm.addEventListener("submit",(event)=>{ }) .then(res=>res.json()) .then(data=>{ + if(data.token){ + localStorage.setItem('authorization',data.token); + // console.log(data.token); + + } alert(data.message); + + signinForm.style.display='none'; + + fetch("http://localhost:3000/todo/todos-list",{ + headers:{ + 'content-type':'application/json', + 'authorization':localStorage.getItem('authorization') + } + }) + .then(res=>res.json()) + .then(data=>{ + const todos=document.getElementById('todos'); + data.todos.forEach(todo=>{ + // console.log(todo); + + populateTodo(todos,todo.id, todo.completed, todo.title); + }) + todosCount=Number(data.todosCount); + console.log(data.todosCount); + + }) + .catch(err=>{alert(err)}) }) .catch(err=>{alert("Signin failed")}); -}) \ No newline at end of file +}) + + + +const createEl=document.getElementById('create'); +createEl.addEventListener('click',(event)=>{ + const todoInput=document.getElementById('todo').value; + console.log(todoInput); + todosCount+=1; + fetch("http://localhost:3000/todo/create-todo",{ + headers:{ + 'content-type':'application/json', + 'authorization':localStorage.getItem('authorization') + }, + method:"POST", + body:JSON.stringify({ + todo:{ + 'id':`${todosCount}`, + 'title':todoInput, + 'completed':0 + } + }) + }) + .then(res=>res.json()) + .then(data=>{ + alert(data.message); + + const todos=document.getElementById('todos'); + + if(data.message==="Todo created successfully") + populateTodo(todos,todosCount,0,todoInput); + }) + .catch(err=>{ + console.log(err); + alert("Creation failed") + }) +}) + + + +const todos=document.getElementById('todos'); +todos.addEventListener('click',(event)=>{ + //Complete Todo + if(event.target&&event.target.matches('input[type="checkbox"]')&&event.target.checked){ + const id=event.target.className; + fetch("http://localhost:3000/todo/complete-todo",{ + headers:{ + 'content-type':'application/json', + 'authorization':localStorage.getItem('authorization') + }, + method:"PATCH", + body:JSON.stringify({ + "id":id + }) + }) + .then(res=>res.json()) + .then(data=>{ + alert(data.message); + }) + .catch(err=>{ + alert(err) + }) + } + + + //Delete todo + if(event.target&&event.target.tagName==="BUTTON"&&event.target.innerHTML==="Delete"){ + const id=event.target.className; + + fetch("http://localhost:3000/todo/delete-todo",{ + headers:{ + 'content-type':'application/json', + 'authorization':localStorage.getItem('authorization') + }, + method:"POST", + body:JSON.stringify({ + "id":id + }) + }) + .then(res=>res.json()) + .then(data=>{ + alert(data.message) + const todo=document.getElementsByClassName(id); + if(data.message==="Todo deleted successfully") + todo[0].style.display='none' + }) + .catch(err=>{ + alert("Deletion failed") + }) + } + + //Update Todo + if(event.target&&event.target.tagName==="BUTTON"&&event.target.innerHTML=="Update"){ + const id=event.target.className; + const todo=document.getElementsByClassName(`${id}`); + fetch("http://localhost:3000/todo/update-todo",{ + headers:{ + 'content-type':'application/json', + 'authorization':localStorage.getItem('authorization') + }, + method:"PATCH", + body:JSON.stringify({"todo":{ + "title":todo[2].value, + "id":id, + "completed":todo[1].checked + }}) + }) + .then(res=>res.json()) + .then(data=>{ + alert(data.message); + }) + .catch(err=>{ + alert("updation failed") + }) + } +}) + + +//complete todo +// addEventListener('click',()=>{ +// fetch("",{ +// headers:{ +// 'content-type':'application/json', +// 'authorization':localStorage.getItem(authorization) +// }, +// method:"PATCH", +// body:{ +// "id":`${id}` +// } +// }) +// .then(res=>res.json()) +// .then(data=>{ +// alert(data.message); +// }) +// .catch(err=>{ +// alert(err) +// }) +// }) + + +// //Update todo +// addEventListener("click",()=>{ +// fetch("",{ +// headers:{ +// 'content-type':'application/json', +// 'authorization':localStorage.getItem(authorization) +// }, +// method:"PATCH", +// body:{ +// "title":`${todoInput}`, +// "id":`${id}`, +// "completed":0 +// } +// }) +// .then(res=>res.json()) +// .then(data=>{ +// alert(data.message); +// }) +// .catch(err=>{alert("Updation failed")}) +// }) + + +// //delete todo +// addEventListener('click',()=>{ +// fetch("",{ +// headers:{ +// 'content-type':'application/json', +// 'authorization':localStorage.getItem(authorization) +// }, +// method:"POST", +// body:{ +// "id":`${id}` +// } +// }) +// .then(res=>res.json()) +// .then(data=>{ +// alert(data.message) +// }) +// .catch(err=>{ +// alert("Deletion failed") +// }) +// }) + + From 2dfc292c0cb59b945404ac73d59bbd9400f569b7 Mon Sep 17 00:00:00 2001 From: Manoj Date: Thu, 19 Sep 2024 20:01:58 +0530 Subject: [PATCH 07/13] Todo app completed only using HTML,CSS,JS, NodeJs, Express --- week-5/frontend/index.html | 74 ++++++++++++++++++++------------------ week-5/frontend/script.js | 22 ++++++++++-- week-5/frontend/style.css | 36 +++++++++++++++---- 3 files changed, 90 insertions(+), 42 deletions(-) diff --git a/week-5/frontend/index.html b/week-5/frontend/index.html index 96473387..7e0dbddc 100644 --- a/week-5/frontend/index.html +++ b/week-5/frontend/index.html @@ -9,43 +9,49 @@ -
- - - - - - -
- -
- - - - -
- - - +
-
-
- - -
- + +
+
+ + + + + + +
+ +
+ + + + +
+ + + + + +
+
+ + +
+ +
diff --git a/week-5/frontend/script.js b/week-5/frontend/script.js index 7597e183..7f22394c 100644 --- a/week-5/frontend/script.js +++ b/week-5/frontend/script.js @@ -4,6 +4,9 @@ let todosCount=0; const populateTodo=(todos,cls,completed,title)=>{ const divEl=document.createElement('div'); divEl.setAttribute('class',cls); + // divEl.style.border='1px solid black' + divEl.style.display='flex' + divEl.style.margin='5px 0' const checkboxEl=document.createElement('input'); checkboxEl.setAttribute('type','checkbox'); @@ -13,6 +16,7 @@ const populateTodo=(todos,cls,completed,title)=>{ const inputEl=document.createElement('input'); inputEl.setAttribute('class',cls); inputEl.setAttribute('value',`${title}`); + // inputEl.style.border='none'; const deleteEl=document.createElement('button'); deleteEl.innerHTML='Delete'; @@ -58,8 +62,10 @@ signupForm.addEventListener("submit",(event)=>{ // } alert(data.message); - if(data.message==="User signed up successfully") + if(data.message==="User signed up successfully"){ signupForm.style.display='none' + signinForm.style.display='block' + } }) .catch(err=>{ console.log(err); @@ -98,6 +104,11 @@ signinForm.addEventListener("submit",(event)=>{ signinForm.style.display='none'; + const todoSection=document.getElementById('todoSection'); + todoSection.style.display='block'; + const logout=document.getElementById('logout'); + logout.style.display='block' + fetch("http://localhost:3000/todo/todos-list",{ headers:{ 'content-type':'application/json', @@ -126,7 +137,7 @@ signinForm.addEventListener("submit",(event)=>{ const createEl=document.getElementById('create'); createEl.addEventListener('click',(event)=>{ const todoInput=document.getElementById('todo').value; - console.log(todoInput); + // console.log(todoInput); todosCount+=1; fetch("http://localhost:3000/todo/create-todo",{ headers:{ @@ -237,6 +248,13 @@ todos.addEventListener('click',(event)=>{ }) +const logout=document.getElementById('logout'); +logout.addEventListener('click',()=>{ + localStorage.removeItem('authorization'); + location.reload(true); +}) + + //complete todo // addEventListener('click',()=>{ // fetch("",{ diff --git a/week-5/frontend/style.css b/week-5/frontend/style.css index 37a42fa2..44c86ec3 100644 --- a/week-5/frontend/style.css +++ b/week-5/frontend/style.css @@ -1,9 +1,33 @@ /* start from here */ - /* #signin{ - display:none ; - } +#todoApp{ + margin-top: 15%; + margin-left: 30%; + border: 2px solid black; + display: inline-block; + padding: 20px; + border-radius: 5px; +} - #logout{ - display: none; - } */ \ No newline at end of file +#signin, #todoSection{ + display: none; +} + +label,input{ + display: block; +} + +#todos input, #todo{ + display: inline; +} + +#logout{ + position: absolute; + display: none; + top: 10px; + right: 10px; +} + +#logout button{ + padding:5px; +} From 33538a2eb9b2d36385b4e6111e20925e3bb660b6 Mon Sep 17 00:00:00 2001 From: Manoj Date: Thu, 19 Sep 2024 20:07:26 +0530 Subject: [PATCH 08/13] Todo app completed only using HTML,CSS,JS, NodeJs, Express --- week-5/frontend/index.html | 4 +++- week-5/frontend/style.css | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/week-5/frontend/index.html b/week-5/frontend/index.html index 7e0dbddc..6c778a7b 100644 --- a/week-5/frontend/index.html +++ b/week-5/frontend/index.html @@ -14,7 +14,7 @@
- +
@@ -28,7 +28,9 @@
+ + +
+ Already have an account?
Signin here
+
@@ -33,9 +33,9 @@ - +
+ Don't have account?
Signup here
+
diff --git a/week-5/frontend/script.js b/week-5/frontend/script.js index b9938312..4980dcd6 100644 --- a/week-5/frontend/script.js +++ b/week-5/frontend/script.js @@ -35,6 +35,18 @@ const populateTodo=(todos,cls,completed,title)=>{ todos.appendChild(divEl); } +const toSignin=document.getElementById('toSignin'); +toSignin.addEventListener('click',()=>{ + signupForm.style.display='none' + signinForm.style.display='block' +}) + +const toSignup=document.getElementById('toSignup'); +toSignup.addEventListener('click',()=>{ + signupForm.style.display='block' + signinForm.style.display='none' +}) + const signupForm=document.getElementById('signup'); signupForm.addEventListener("submit",(event)=>{ @@ -62,8 +74,9 @@ signupForm.addEventListener("submit",(event)=>{ // } alert(data.message); + if(data.message==="User signed up successfully" || data.message==="User already exists"){ - console.log(data); + // console.log(data); signupForm.style.display='none' signinForm.style.display='block' diff --git a/week-5/frontend/style.css b/week-5/frontend/style.css index 73c0da07..54fc086d 100644 --- a/week-5/frontend/style.css +++ b/week-5/frontend/style.css @@ -38,3 +38,11 @@ input, button{ padding: 3px; } +#toSignin, #toSignup{ + display: inline-block; + background-color: rgb(183, 190, 197); + padding: 5px; + border-radius: 5px; + cursor: pointer; +} + From 145bce26c48e3f359a4043fc72fa3d999fcfa970 Mon Sep 17 00:00:00 2001 From: Manoj Date: Fri, 27 Sep 2024 19:10:33 +0530 Subject: [PATCH 11/13] bookmark-backend --- week-5/frontend/style.css | 11 + week-6/6.1-todo/backend/.gitignore | 2 + .../6.2-bookmark-manager/backend/.gitignore | 2 + .../backend/package-lock.json | 316 +++++++++++++++++- .../6.2-bookmark-manager/backend/package.json | 6 +- .../backend/routes/bookmarks.js | 35 +- 6 files changed, 366 insertions(+), 6 deletions(-) create mode 100644 week-6/6.1-todo/backend/.gitignore create mode 100644 week-6/6.2-bookmark-manager/backend/.gitignore diff --git a/week-5/frontend/style.css b/week-5/frontend/style.css index 54fc086d..ce922e6c 100644 --- a/week-5/frontend/style.css +++ b/week-5/frontend/style.css @@ -7,6 +7,7 @@ display: inline-block; padding: 20px; border-radius: 5px; + background-color: rgb(241, 237, 237); } #signin, #todoSection{ @@ -32,12 +33,22 @@ label,input{ padding:5px; } +/* button{ + background-color: rgb(183, 190, 197); + border: none; + border-radius: 2px; + padding: 3px; +} */ + input, button{ margin-top: 3px; margin-bottom: 3px; padding: 3px; + } + + #toSignin, #toSignup{ display: inline-block; background-color: rgb(183, 190, 197); diff --git a/week-6/6.1-todo/backend/.gitignore b/week-6/6.1-todo/backend/.gitignore new file mode 100644 index 00000000..1dcef2d9 --- /dev/null +++ b/week-6/6.1-todo/backend/.gitignore @@ -0,0 +1,2 @@ +node_modules +.env \ No newline at end of file diff --git a/week-6/6.2-bookmark-manager/backend/.gitignore b/week-6/6.2-bookmark-manager/backend/.gitignore new file mode 100644 index 00000000..37d7e734 --- /dev/null +++ b/week-6/6.2-bookmark-manager/backend/.gitignore @@ -0,0 +1,2 @@ +node_modules +.env diff --git a/week-6/6.2-bookmark-manager/backend/package-lock.json b/week-6/6.2-bookmark-manager/backend/package-lock.json index 19a4d729..722a838f 100644 --- a/week-6/6.2-bookmark-manager/backend/package-lock.json +++ b/week-6/6.2-bookmark-manager/backend/package-lock.json @@ -10,7 +10,8 @@ "license": "ISC", "dependencies": { "cors": "^2.8.5", - "express": "^4.20.0" + "express": "^4.20.0", + "nodemon": "^3.1.7" } }, "node_modules/accepts": { @@ -26,12 +27,40 @@ "node": ">= 0.6" } }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", "license": "MIT" }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, + "node_modules/binary-extensions": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", + "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/body-parser": { "version": "1.20.3", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.3.tgz", @@ -71,6 +100,26 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/braces": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "dependencies": { + "fill-range": "^7.1.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -99,6 +148,34 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/chokidar": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + }, "node_modules/content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", @@ -286,6 +363,17 @@ "node": ">= 0.10.0" } }, + "node_modules/fill-range": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/finalhandler": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", @@ -331,6 +419,19 @@ "node": ">= 0.6" } }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -359,6 +460,17 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/gopd": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", @@ -371,6 +483,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "engines": { + "node": ">=4" + } + }, "node_modules/has-property-descriptors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", @@ -447,6 +567,11 @@ "node": ">=0.10.0" } }, + "node_modules/ignore-by-default": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", + "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==" + }, "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", @@ -462,6 +587,44 @@ "node": ">= 0.10" } }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "engines": { + "node": ">=0.12.0" + } + }, "node_modules/media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -522,6 +685,17 @@ "node": ">= 0.6" } }, + "node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -537,6 +711,62 @@ "node": ">= 0.6" } }, + "node_modules/nodemon": { + "version": "3.1.7", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.7.tgz", + "integrity": "sha512-hLj7fuMow6f0lbB0cD14Lz2xNjwsyruH251Pk4t/yIitCFJbmY1myuLlHm/q06aST4jg6EgAh74PIBBrRqpVAQ==", + "dependencies": { + "chokidar": "^3.5.2", + "debug": "^4", + "ignore-by-default": "^1.0.1", + "minimatch": "^3.1.2", + "pstree.remy": "^1.1.8", + "semver": "^7.5.3", + "simple-update-notifier": "^2.0.0", + "supports-color": "^5.5.0", + "touch": "^3.1.0", + "undefsafe": "^2.0.5" + }, + "bin": { + "nodemon": "bin/nodemon.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nodemon" + } + }, + "node_modules/nodemon/node_modules/debug": { + "version": "4.3.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", + "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/nodemon/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -585,6 +815,17 @@ "integrity": "sha512-7lf7qcQidTku0Gu3YDPc8DJ1q7OOucfa/BSsIwjuh56VU7katFvuM8hULfkwB3Fns/rsVF7PwPKVw1sl5KQS9w==", "license": "MIT" }, + "node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -598,6 +839,11 @@ "node": ">= 0.10" } }, + "node_modules/pstree.remy": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", + "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==" + }, "node_modules/qs": { "version": "6.11.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", @@ -637,6 +883,17 @@ "node": ">= 0.8" } }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -663,6 +920,17 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "license": "MIT" }, + "node_modules/semver": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/send": { "version": "0.19.0", "resolved": "https://registry.npmjs.org/send/-/send-0.19.0.tgz", @@ -797,6 +1065,17 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/simple-update-notifier": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", + "integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==", + "dependencies": { + "semver": "^7.5.3" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", @@ -806,6 +1085,28 @@ "node": ">= 0.8" } }, + "node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, "node_modules/toidentifier": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", @@ -815,6 +1116,14 @@ "node": ">=0.6" } }, + "node_modules/touch": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.1.tgz", + "integrity": "sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==", + "bin": { + "nodetouch": "bin/nodetouch.js" + } + }, "node_modules/type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", @@ -828,6 +1137,11 @@ "node": ">= 0.6" } }, + "node_modules/undefsafe": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", + "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==" + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", diff --git a/week-6/6.2-bookmark-manager/backend/package.json b/week-6/6.2-bookmark-manager/backend/package.json index 7e4d4436..fa960f7c 100644 --- a/week-6/6.2-bookmark-manager/backend/package.json +++ b/week-6/6.2-bookmark-manager/backend/package.json @@ -3,7 +3,8 @@ "version": "1.0.0", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "start": "node index.js", + "dev": "nodemon index.js" }, "keywords": [], "author": "", @@ -11,6 +12,7 @@ "description": "", "dependencies": { "cors": "^2.8.5", - "express": "^4.20.0" + "express": "^4.20.0", + "nodemon": "^3.1.7" } } diff --git a/week-6/6.2-bookmark-manager/backend/routes/bookmarks.js b/week-6/6.2-bookmark-manager/backend/routes/bookmarks.js index 86da9ec0..13651f45 100644 --- a/week-6/6.2-bookmark-manager/backend/routes/bookmarks.js +++ b/week-6/6.2-bookmark-manager/backend/routes/bookmarks.js @@ -1,13 +1,42 @@ let bookmarks = []; // in memory space -export async function addBookmark(req,res,next){ +async function addBookmark(req,res,next){ // write here + //validate the details + const {url,category}=req.body; + if(!url||!category){ + throw new Error("Details required") + } + + //creating a bookmark + const bookmark={ + url:url, + category:category + } + //saving the bookmark + bookmarks.push(bookmark); + + return res.status(201).send({message:"Bookmark created successfully"}) } -export async function deleteBookmark(req,res,next){ +async function deleteBookmark(req,res,next){ // write here + //validate the details + const id=req.params.id; + if(id===''){ + throw new Error("Detais required") + } + //delete the bookmark + bookmarks.splice(id,1); + + return res.status(200).send({message:"Boookmark deleted succesfully"}) + } -export async function getAllBookmarks(req,res,next){ +async function getAllBookmarks(req,res,next){ // write here + return res.status(200).send(bookmarks) } + + +module.exports={addBookmark,deleteBookmark,getAllBookmarks} From e8bfa76b893b06bd820ce0a09cbea4c2607db8db Mon Sep 17 00:00:00 2001 From: Manoj Kumar Date: Fri, 27 Sep 2024 23:56:24 +0530 Subject: [PATCH 12/13] vf --- week-6/6.2-bookmark-manager/frontend/script.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/week-6/6.2-bookmark-manager/frontend/script.js b/week-6/6.2-bookmark-manager/frontend/script.js index 353bbfe2..f96900f7 100644 --- a/week-6/6.2-bookmark-manager/frontend/script.js +++ b/week-6/6.2-bookmark-manager/frontend/script.js @@ -3,11 +3,25 @@ const API_URL = 'http://localhost:3001/bookmarks'; // Fetch bookmarks when the page loads document.addEventListener('DOMContentLoaded', () => { // start here + fetchBookmarks(); }); // Fetch bookmarks from the backend function fetchBookmarks() { // start here + fetch(`${API_URL}`) + .then(res=>res.json()) + .then(data=>{ + const bookmarkList=document.getElementById('bookmark-list'); + data.foreach(bookmark=>{ + console.log(bookmark); + const divEl=document.createElement('div'); + divEl.innerHTML=`${bookmark.url}+(+${bookmark.category}+)`; + bookmarkList.appendChild(divEl); + + + }) + }) } // Add a bookmark to the DOM From b98225281bca7b8dc642b905b34afd4ba953ab29 Mon Sep 17 00:00:00 2001 From: Manoj Kumar Date: Fri, 4 Oct 2024 23:41:44 +0530 Subject: [PATCH 13/13] week-6 bookmark managet assignment --- week-6/6.2-bookmark-manager/backend/index.js | 6 +- .../backend/routes/bookmarks.js | 106 ++++++++- .../6.2-bookmark-manager/frontend/index.html | 8 + .../6.2-bookmark-manager/frontend/script.js | 211 ++++++++++++++++-- .../6.2-bookmark-manager/frontend/styles.css | 52 ++++- 5 files changed, 346 insertions(+), 37 deletions(-) diff --git a/week-6/6.2-bookmark-manager/backend/index.js b/week-6/6.2-bookmark-manager/backend/index.js index 537eb0da..0ecd108d 100644 --- a/week-6/6.2-bookmark-manager/backend/index.js +++ b/week-6/6.2-bookmark-manager/backend/index.js @@ -1,6 +1,6 @@ const express = require('express'); const cors = require('cors'); -const { addBookmark, deleteBookmark, getAllBookmarks } = require('./routes/bookmarks'); // importing callback functions for routes +const { addBookmark, deleteBookmark, getAllBookmarks, getBookmark, favoriteBookmark } = require('./routes/bookmarks'); // importing callback functions for routes const app = express(); const PORT = 3001; @@ -20,6 +20,10 @@ app.delete('/bookmarks/:id', deleteBookmark); // TODO: Can u implement searching bookmark and favorite and unfavorite bookmark route ?? +app.put('/bookmarks/:id',favoriteBookmark); + +app.post('/bookmarks/search',getBookmark); + app.listen(PORT, () => { console.log(`Server is running on http://localhost:${PORT}`); }); diff --git a/week-6/6.2-bookmark-manager/backend/routes/bookmarks.js b/week-6/6.2-bookmark-manager/backend/routes/bookmarks.js index 13651f45..0dcf38b8 100644 --- a/week-6/6.2-bookmark-manager/backend/routes/bookmarks.js +++ b/week-6/6.2-bookmark-manager/backend/routes/bookmarks.js @@ -3,33 +3,53 @@ let bookmarks = []; // in memory space async function addBookmark(req,res,next){ // write here //validate the details + try { const {url,category}=req.body; if(!url||!category){ - throw new Error("Details required") + const err=new Error("Details required"); + err.status=400; + throw err; + // return res.status(401).send({message:"Details required"}) } //creating a bookmark const bookmark={ url:url, - category:category + category:category, + favorite:0 } //saving the bookmark bookmarks.push(bookmark); - return res.status(201).send({message:"Bookmark created successfully"}) + return res.status(201).send(bookmarks) + } catch (error) { + next(error) + } } async function deleteBookmark(req,res,next){ // write here - //validate the details - const id=req.params.id; - if(id===''){ - throw new Error("Detais required") - } - //delete the bookmark - bookmarks.splice(id,1); + try { + //validate the details + const id=req.params.id; + if(id===''){ + const err=new Error("Details required"); + err.status=400; + throw err; + } - return res.status(200).send({message:"Boookmark deleted succesfully"}) + if(id>bookmarks.length){ + const err=new Error("Invalid information"); + err.status=400; + throw err; + } + //delete the bookmark + bookmarks.splice(id,1); + + return res.status(200).send(bookmarks) + } catch (error) { + next(error) + } } @@ -38,5 +58,67 @@ async function getAllBookmarks(req,res,next){ return res.status(200).send(bookmarks) } +const favoriteBookmark=async(req,res,next)=>{ + try { + //get details from frontend + //validate the details + //update the bookmark + + const id=req.params.id; + if(id===''){ + const err=new Error("Details required"); + err.status=400; + throw err; + } + + if(id>bookmarks.length){ + const err=new Error("Invalid information"); + err.status=400; + throw err; + } + + bookmarks[id].favorite=!bookmarks[id].favorite; + return res.status(200).send({message:"Marked succcessfully"}); + } catch (error) { + next(error) + } +} + +const getBookmark=async (req,res,next)=>{ + try { + //get details from frontend + //validate the details + //search for bookmark in bookmarks + //if find then return bookmark + + const url=req.body.url; + const category=req.body.category; + + if(!url||!category){ + const err=new Error("Details required"); + err.status=400; + throw err; + } + + let searchedBookmarks=[]; + bookmarks.forEach(bookmark=>{ + if(bookmark.url===url&&bookmark.category===category){ + searchedBookmarks.push(bookmark); + } + }) + + if(searchedBookmarks.length===0){ + const err=new Error("Not found"); + err.status=404; + throw err; + } + + return res.status(200).send(searchedBookmarks); + + } catch (error) { + next(error) + } +} + -module.exports={addBookmark,deleteBookmark,getAllBookmarks} +module.exports={addBookmark,deleteBookmark,getAllBookmarks,getBookmark,favoriteBookmark} diff --git a/week-6/6.2-bookmark-manager/frontend/index.html b/week-6/6.2-bookmark-manager/frontend/index.html index a9c37b5d..36f9c614 100644 --- a/week-6/6.2-bookmark-manager/frontend/index.html +++ b/week-6/6.2-bookmark-manager/frontend/index.html @@ -5,6 +5,8 @@ Bookmark Manager + +
@@ -16,6 +18,12 @@

Bookmark Manager

+
+ + + +
+
    diff --git a/week-6/6.2-bookmark-manager/frontend/script.js b/week-6/6.2-bookmark-manager/frontend/script.js index f96900f7..5ea65594 100644 --- a/week-6/6.2-bookmark-manager/frontend/script.js +++ b/week-6/6.2-bookmark-manager/frontend/script.js @@ -1,40 +1,207 @@ -const API_URL = 'http://localhost:3001/bookmarks'; +const API_URL = "http://localhost:3001/bookmarks"; // Fetch bookmarks when the page loads -document.addEventListener('DOMContentLoaded', () => { -// start here - fetchBookmarks(); +document.addEventListener("DOMContentLoaded", () => { + // start here + fetchBookmarks(); }); // Fetch bookmarks from the backend function fetchBookmarks() { - // start here - fetch(`${API_URL}`) - .then(res=>res.json()) - .then(data=>{ - const bookmarkList=document.getElementById('bookmark-list'); - data.foreach(bookmark=>{ - console.log(bookmark); - const divEl=document.createElement('div'); - divEl.innerHTML=`${bookmark.url}+(+${bookmark.category}+)`; - bookmarkList.appendChild(divEl); - - - }) + // start here + fetch(`${API_URL}`) + .then((res) => res.json()) + .then((data) => { + let i=0; + data.forEach(function (bookmark) { + addBookmarkToDOM(bookmark,i); + i++; + }); }) + .catch((err) => { + console.log(err); + }); } // Add a bookmark to the DOM -function addBookmarkToDOM(bookmark) { - // start here +function addBookmarkToDOM(bookmark, id) { + // start here + + const bookmarkList = document.getElementById("bookmark-list"); +// bookmarkList.innerHTML=''; + + const divEl=document.createElement('div'); + +{/* */} + const iEl=document.createElement('i'); + iEl.setAttribute('id',`${id}`) + console.log(iEl.id); + + iEl.setAttribute('class','fa-regular fa-heart') + if(bookmark.favorite) + iEl.setAttribute('class','fa-solid fa-heart') + iEl.addEventListener('click',()=>{ + if(iEl.classList[0]==='fa-regular') + iEl.setAttribute('class','fa-solid fa-heart') + else + iEl.setAttribute('class','fa-regular fa-heart') + fetch(`${API_URL}/${id}`,{ + headers:{ + 'content-type':'application/json' + }, + method:"PUT" + }) + .catch(err=>{ + console.log(err); + alert(err.message); + }) + }) + + const liEl = document.createElement("li"); +// liEl.setAttribute("class", `${id}`); + + const aEl = document.createElement("a"); + aEl.innerHTML = `${bookmark.url}(${bookmark.category})`; + aEl.setAttribute("href", `${bookmark.url}`); +// aEl.setAttribute('class',`${id}`); + + const delEl = document.createElement("button"); + delEl.innerHTML = "Delete"; + delEl.setAttribute('id',`${id}`); + delEl.addEventListener('click',()=>{ + deleteBookmark(id); + }) + + divEl.appendChild(iEl); + divEl.appendChild(aEl); + liEl.appendChild(divEl); + liEl.appendChild(delEl); + + bookmarkList.appendChild(liEl); } // Add a new bookmark -document.getElementById('add-bookmark-btn').addEventListener('click', () => { - // start here +document.getElementById("add-bookmark-btn").addEventListener("click", () => { + // start here + //get the details + //trigger the request + //get the resonse + //add the bookmarks to DOM + const bookmarkUrl=document.getElementById('bookmark-url'); + const bookmarkCategory=document.getElementById('bookmark-category'); + const url=bookmarkUrl.value; + const category=bookmarkCategory.value; + bookmarkUrl.value=''; + bookmarkCategory.value=''; + fetch(`${API_URL}`,{ + headers:{ + 'content-type':'application/json' + }, + method:"POST", + body:JSON.stringify({ + url:url, + category:category + }) + }) + .then(res=>{ + if(!res.ok){ + const err=new Error(`${res.message}`); + err.status=res.status; + throw err; + } + return res.json() + }) + .then(data=>{ + let i=0; + const bookmarkList=document.getElementById('bookmark-list'); + bookmarkList.innerHTML=''; + data.forEach(bookmark=>{ + addBookmarkToDOM(bookmark,i); + i++; + }) + }) + .catch(err=>{ + console.log(err); + alert(err.message); +}) }); // Delete a bookmark + + + function deleteBookmark(id) { - // start here; + // start here; + //capture the button click + //then trigger the api with id + //get bookmark array in response + //add bookmarks to DOM + fetch(`${API_URL}/${id}`, { + headers: { + "content-type": "application/json", + }, + + method: "Delete", + }) + .then((res) => res.json()) + .then((data) => { + const bookmarkList=document.getElementById('bookmark-list'); + bookmarkList.innerHTML=''; + let i = 0; + data.forEach(function (bookmark) { + addBookmarkToDOM(bookmark, i); + i++; + }); + }) + .catch((err) => { + console.log(err); + }); } + + + +document.getElementById('search-bookmark-btn').addEventListener('click',()=>{ + const bookmarkUrl=document.getElementById('search-url'); + const bookmarkCategory=document.getElementById('search-category'); + const url=bookmarkUrl.value; + const category=bookmarkCategory.value; + bookmarkUrl.value=''; + bookmarkCategory.value=''; + + fetch(`${API_URL}/search`,{ + headers:{ + 'content-type':'application/json' + }, + method:'POST', + body:JSON.stringify({ + url:url, + category:category + }) + }) + .then(res=>{ + if(!res.ok){ + throw new Error(`${res.statusText}`) + } + return res.json() + }) + .then(data=>{ + const bookmarkList=document.getElementById('bookmark-list'); + bookmarkList.innerHTML=''; + let i=0; + data.forEach(bookmark=>{ + + const liEl = document.createElement("li"); + + const aEl = document.createElement("a"); + aEl.innerHTML = `${bookmark.url}(${bookmark.category})`; + aEl.setAttribute("href", `${bookmark.url}`); + + liEl.appendChild(aEl); + + bookmarkList.appendChild(liEl); + }) + }) + .catch(err=>{ + alert(err.message); + }) +}) diff --git a/week-6/6.2-bookmark-manager/frontend/styles.css b/week-6/6.2-bookmark-manager/frontend/styles.css index 37fb776e..26af08a2 100644 --- a/week-6/6.2-bookmark-manager/frontend/styles.css +++ b/week-6/6.2-bookmark-manager/frontend/styles.css @@ -1,25 +1,48 @@ body { /*start here */ + background-color: rgb(49, 48, 48); + color: white; + display: flex; + justify-content: center; + /* align-content: center; */ } .container { /*start here */ + background-color: rgb(80, 78, 78); + display: inline-block; + border-radius: 5px; + box-shadow: black; + padding: 5em; } h1 { /*start here */ } - -button { +.input-container{ + margin: .25em 0; +} + +button, input { /*start here */ + padding: 0.5em; + border-radius: 5px; } #bookmark-list { /*start here */ + list-style: none; + padding-left: 0; } #bookmark-list li { /*start here */ + background-color: rgb(105, 103, 103); + display: flex; + justify-content: space-between; + padding: 0.5em; + margin: 0.25em 0; + border-radius: 5px; } button.favorite-btn { @@ -29,4 +52,29 @@ button.favorite-btn { button.delete-btn { /*start here */ } + +a{ + text-decoration: none; + color: white; + margin-top: 0.25em; +} + +@media (max-width: 600px){ + .input-container, li,.search-container{ + display: flex; + flex-direction: column; + } + + input,button{ + margin: 0.25em 0; + } +} + +i{ + cursor: pointer; + margin: 0.25em 1em; + margin-left: 0; +} + + \ No newline at end of file