From 9149bba8688582cc48d6f2a504809bfb33b20c43 Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Thu, 1 May 2025 16:07:55 -0700 Subject: [PATCH 01/15] added password hashing --- assignment-db-service/.env.development | 14 ++ assignment-db-service/{dev.env => .env.test} | 2 + assignment-db-service/app.js | 54 ++++---- assignment-db-service/package-lock.json | 123 ++++++++++++++++++ assignment-db-service/package.json | 5 +- assignment-service/.env.development | 6 + assignment-service/.env.test | 6 + assignment-service/package-lock.json | 110 ++++++++++++++++ assignment-service/package.json | 6 +- assignment-service/routes/InstructorRouter.js | 105 +++++++++------ auth-service/{dev.env => .env.development} | 0 compose.yaml | 8 +- user-db-service/{dev.env => .env.development} | 0 13 files changed, 364 insertions(+), 75 deletions(-) create mode 100644 assignment-db-service/.env.development rename assignment-db-service/{dev.env => .env.test} (97%) create mode 100644 assignment-service/.env.development create mode 100644 assignment-service/.env.test rename auth-service/{dev.env => .env.development} (100%) rename user-db-service/{dev.env => .env.development} (100%) diff --git a/assignment-db-service/.env.development b/assignment-db-service/.env.development new file mode 100644 index 0000000..d370b34 --- /dev/null +++ b/assignment-db-service/.env.development @@ -0,0 +1,14 @@ +NODE_ENV=development + +# Environment variables declared in this file are automatically made available to Prisma. +# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema + +# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB. +# See the documentation for all the connection string options: https://pris.ly/d/connection-strings + +#use this when testing local, remmber to run the proxy command +DATABASE_URL="postgresql://postgres:wly9H8gjjmxYfg1@localhost:15432/postgres?schema=public" + +# DATABASE_URL="postgres://postgres:wly9H8gjjmxYfg1@bytecamp-db.flycast:5432?sslmode=disable" +# DATABASE_URL=postgres://snakebyte:zVB7lgOiKr89dq6@localhost:5432/snakebyte?sslmode=disable +NODE_PORT=3200 diff --git a/assignment-db-service/dev.env b/assignment-db-service/.env.test similarity index 97% rename from assignment-db-service/dev.env rename to assignment-db-service/.env.test index 1e00c54..b464239 100644 --- a/assignment-db-service/dev.env +++ b/assignment-db-service/.env.test @@ -1,3 +1,5 @@ +NODE_ENV=development + # Environment variables declared in this file are automatically made available to Prisma. # See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema diff --git a/assignment-db-service/app.js b/assignment-db-service/app.js index 115c256..09f0055 100644 --- a/assignment-db-service/app.js +++ b/assignment-db-service/app.js @@ -10,8 +10,24 @@ const port = process.env.NODE_PORT || 3000; app.use(express.json()); app.use(express.urlencoded({ extended: true })); +async function encryptPassword(password) { + if (!password) { + return null; + } + + return new Promise((resolve, reject) => { + bcrypt.hash(password, 10, (err, hash) => { + if (err) { + reject(err); + } else { + resolve(hash); + } + }); + }); +} + //function to conver req.body to assignment -function convertToAssignment(req) { +async function convertToAssignment(req) { const { campid, programid, @@ -24,7 +40,8 @@ function convertToAssignment(req) { instructorid } = req.body; - // const hashedPassword = await bcrypt.hash(Password, 10); + const hashPassword = await encryptPassword(req.body.password); + return { campid: campid, programid: programid, @@ -33,8 +50,7 @@ function convertToAssignment(req) { originalfile: originalfile, editablefile: editablefile, assignmenturl: assignmenturl, - // passwordhash: hashedpassword, - passwordhash: password, + passwordhash: hashPassword, instructorid: instructorid, }; } @@ -44,25 +60,11 @@ app.post("/assignments", async (req, res) => { try { console.log("Request body:", req.body); - // const { - // campid, - // programid, - // studentname, - // snakegameid, - // originalfile, - // editablefile, - // assignmenturl, - // password, - // instructorid - // } = req.body; - - // const hashedPassword = await bcrypt.hash(Password, 10); + const assignment = await convertToAssignment(req); const newAssignment = await prisma.assignments.create({ - data: { - ...convertToAssignment(req) - }, + data: assignment, }); - + console.log("Assignment created successfully:", newAssignment); res.json({ @@ -119,17 +121,11 @@ app.get("/assignments/:id", async (req, res) => { app.put("/assignments/:id", async (req, res) => { try { const { id } = req.params; - const data = req.body; - - if (data.password) { - // data.passwordhash = await bcrypt.hash(data.Password, 10); - data.passwordhash = data.password; - delete data.password; - } + const assignment = await convertToAssignment(req); const updatedAssignment = await prisma.assignments.update({ where: { assignmentid: parseInt(id) }, - data, + data: assignment, }); res.json({ diff --git a/assignment-db-service/package-lock.json b/assignment-db-service/package-lock.json index 1f1e538..d88c403 100644 --- a/assignment-db-service/package-lock.json +++ b/assignment-db-service/package-lock.json @@ -10,6 +10,9 @@ "express": "^5.1.0", "nodemon": "^3.1.9", "prisma": "^6.1.0" + }, + "devDependencies": { + "dotenv-cli": "^8.0.0" } }, "node_modules/@mapbox/node-pre-gyp": { @@ -377,6 +380,21 @@ "node": ">=6.6.0" } }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "dev": true, + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/debug": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", @@ -418,6 +436,45 @@ "node": ">=8" } }, + "node_modules/dotenv": { + "version": "16.5.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.5.0.tgz", + "integrity": "sha512-m/C+AwOAr9/W1UOIZUo232ejMNnJAJtYQjUbHoNTBNTJSvqzzDh7vnrei3o3r3m9blf6ZoDkvcw0VmozNRFJxg==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/dotenv-cli": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-8.0.0.tgz", + "integrity": "sha512-aLqYbK7xKOiTMIRf1lDPbI+Y+Ip/wo5k3eyp6ePysVaSqbyxjyK3dK35BTxG+rmd7djf5q2UPs4noPNH+cj0Qw==", + "dev": true, + "license": "MIT", + "dependencies": { + "cross-spawn": "^7.0.6", + "dotenv": "^16.3.0", + "dotenv-expand": "^10.0.0", + "minimist": "^1.2.6" + }, + "bin": { + "dotenv": "cli.js" + } + }, + "node_modules/dotenv-expand": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz", + "integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -912,6 +969,13 @@ "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", "license": "MIT" }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true, + "license": "ISC" + }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -999,6 +1063,16 @@ "node": "*" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/minipass": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", @@ -1211,6 +1285,16 @@ "node": ">=0.10.0" } }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/path-to-regexp": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.2.0.tgz", @@ -1454,6 +1538,29 @@ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "license": "ISC" }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/side-channel": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", @@ -1713,6 +1820,22 @@ "webidl-conversions": "^3.0.0" } }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/wide-align": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", diff --git a/assignment-db-service/package.json b/assignment-db-service/package.json index ca9db41..6724b9c 100644 --- a/assignment-db-service/package.json +++ b/assignment-db-service/package.json @@ -8,6 +8,9 @@ }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "dev": "nodemon app.js" + "dev": "dotenv -e .env.development nodemon app.js" + }, + "devDependencies": { + "dotenv-cli": "^8.0.0" } } diff --git a/assignment-service/.env.development b/assignment-service/.env.development new file mode 100644 index 0000000..1bc73e5 --- /dev/null +++ b/assignment-service/.env.development @@ -0,0 +1,6 @@ +NODE_ENV=development +#DB_ASSIGNMENT_SERVICE_URL="http://localhost:3000" +DB_ASSIGNMENT_SERVICE_URL="http://localhost:3200" +AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" +ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 +PORT=8082 \ No newline at end of file diff --git a/assignment-service/.env.test b/assignment-service/.env.test new file mode 100644 index 0000000..d39a82f --- /dev/null +++ b/assignment-service/.env.test @@ -0,0 +1,6 @@ +NODE_ENV=development +#DB_ASSIGNMENT_SERVICE_URL="http://localhost:3000" +DB_ASSIGNMENT_SERVICE_URL="http://js-assignment-db-service:3200" +AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" +ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 +PORT=8082 \ No newline at end of file diff --git a/assignment-service/package-lock.json b/assignment-service/package-lock.json index 3dff094..683f7be 100644 --- a/assignment-service/package-lock.json +++ b/assignment-service/package-lock.json @@ -17,6 +17,9 @@ "express-session": "^1.18.1", "nodemon": "^3.1.9", "passport": "^0.7.0" + }, + "devDependencies": { + "dotenv-cli": "^8.0.0" } }, "node_modules/@mapbox/node-pre-gyp": { @@ -393,6 +396,21 @@ "node": ">= 0.10" } }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "dev": true, + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -453,6 +471,32 @@ "url": "https://dotenvx.com" } }, + "node_modules/dotenv-cli": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-8.0.0.tgz", + "integrity": "sha512-aLqYbK7xKOiTMIRf1lDPbI+Y+Ip/wo5k3eyp6ePysVaSqbyxjyK3dK35BTxG+rmd7djf5q2UPs4noPNH+cj0Qw==", + "dev": true, + "license": "MIT", + "dependencies": { + "cross-spawn": "^7.0.6", + "dotenv": "^16.3.0", + "dotenv-expand": "^10.0.0", + "minimist": "^1.2.6" + }, + "bin": { + "dotenv": "cli.js" + } + }, + "node_modules/dotenv-expand": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz", + "integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -1109,6 +1153,13 @@ "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", "license": "MIT" }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true, + "license": "ISC" + }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -1196,6 +1247,16 @@ "node": "*" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/minipass": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", @@ -1460,6 +1521,16 @@ "node": ">=0.10.0" } }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/path-to-regexp": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.2.0.tgz", @@ -1738,6 +1809,29 @@ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "license": "ISC" }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/side-channel": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", @@ -2018,6 +2112,22 @@ "webidl-conversions": "^3.0.0" } }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/wide-align": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", diff --git a/assignment-service/package.json b/assignment-service/package.json index b0a2b99..365e94e 100644 --- a/assignment-service/package.json +++ b/assignment-service/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "main": "server.js", "scripts": { - "dev": "nodemon server.js" + "dev": "dotenv -e .env.development nodemon server.js" }, "keywords": [], "author": "", @@ -11,11 +11,15 @@ "description": "", "dependencies": { "axios": "^1.8.4", + "bcrypt": "^5.1.1", "cors": "^2.8.5", "dotenv": "^16.5.0", "express": "^5.1.0", "express-session": "^1.18.1", "nodemon": "^3.1.9", "passport": "^0.7.0" + }, + "devDependencies": { + "dotenv-cli": "^8.0.0" } } diff --git a/assignment-service/routes/InstructorRouter.js b/assignment-service/routes/InstructorRouter.js index c3a6d01..ffee372 100644 --- a/assignment-service/routes/InstructorRouter.js +++ b/assignment-service/routes/InstructorRouter.js @@ -2,30 +2,40 @@ const intructorRouter = require("express").Router(); const passport = require("passport"); const axios = require("axios"); -const DB_ASSIGNMENT_SERVICE_URL = process.env.DB_ASSIGNMENT_SERVICE_URL || "http://localhost:3000"; +const DB_ASSIGNMENT_SERVICE_URL = + process.env.DB_ASSIGNMENT_SERVICE_URL || "http://localhost:3000"; console.log("DB_ASSIGNMENT_SERVICE_URL:", DB_ASSIGNMENT_SERVICE_URL); // This endpoint is for instructors to create a new assignment -intructorRouter.post("/create", - // passport.authenticate("jwt", { session: false }), +intructorRouter.post( + "/create", + // passport.authenticate("jwt", { session: false }), async (req, res) => { - try { - console.log("Creating a new assignment with data:", req.body); - const response = await axios.post(`${DB_ASSIGNMENT_SERVICE_URL}/assignments`, req.body); - console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); - res.status(response.status).json(response.data); - } catch (error) { - console.error("Error creating assignment:", error.message); - res.status(error.response?.status || 500).json({ error: error.message }); + try { + + console.log("Creating a new assignment with data:", req.body); + const response = await axios.post( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments`, + req.body + ); + console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); + res.status(response.status).json(response.data); + } catch (error) { + console.error("Error creating assignment:", error.message); + res.status(error.response?.status || 500).json({ error: error.message }); + } } -}); +); // This endpoint is for instructors to get details of a specific assignment intructorRouter.get("/details/:id", async (req, res) => { try { const assignmentId = req.params.id; console.log("Fetching details for assignmentId:", assignmentId); - const response = await axios.get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`); + const response = await axios.get( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}` + ); + console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); res.status(response.status).json(response.data); } catch (error) { @@ -35,48 +45,63 @@ intructorRouter.get("/details/:id", async (req, res) => { }); // This endpoint is for instructors to get a list of assignments they have created -intructorRouter.get("/list/:id", async (req, res) => { - // if (req.isAuthenticated()) { +intructorRouter.get( + "/list/:id", + // passport.authenticate("jwt", { session: false }), + async (req, res) => { + // if (req.isAuthenticated()) { try { const instructorId = req.params.id; console.log("Fetching assignments for instructorId:", instructorId); // const instructorId = req.user.userid; // Assuming req.user contains the authenticated user - const response = await axios.get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/instructor/${instructorId}`); + const response = await axios.get( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/instructor/${instructorId}` + ); console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); res.status(response.status).json(response.data); } catch (error) { res.status(error.response?.status || 500).json({ error: error.message }); } - // } else { - // return res.status(401).json({ error: "Not authenticated" }); - // } - -}); + // } else { + // return res.status(401).json({ error: "Not authenticated" }); + // } + } +); // This endpoint is for instructors to update an assignment -intructorRouter.put("/update/:id", - // passport.authenticate("jwt", { session: false }), +intructorRouter.put( + "/update/:id", + // passport.authenticate("jwt", { session: false }), async (req, res) => { - try { - const assignmentId = req.params.id; - const response = await axios.put(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`, req.body); - res.status(response.status).json(response.data); - } catch (error) { - res.status(error.response?.status || 500).json({ error: error.message }); + try { + const assignmentId = req.params.id; + + const response = await axios.put( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`, + req.body + ); + res.status(response.status).json(response.data); + } catch (error) { + res.status(error.response?.status || 500).json({ error: error.message }); + } } -}); +); // This endpoint is for instructors to delete an assignment -intructorRouter.delete("/delete/:id", - // passport.authenticate("jwt", { session: false }), +intructorRouter.delete( + "/delete/:id", + // passport.authenticate("jwt", { session: false }), async (req, res) => { - try { - const assignmentId = req.params.id; - const response = await axios.delete(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`); - res.status(response.status).json(response.data); - } catch (error) { - res.status(error.response?.status || 500).json({ error: error.message }); + try { + const assignmentId = req.params.id; + const response = await axios.delete( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}` + ); + res.status(response.status).json(response.data); + } catch (error) { + res.status(error.response?.status || 500).json({ error: error.message }); + } } -}); +); -module.exports = intructorRouter; \ No newline at end of file +module.exports = intructorRouter; diff --git a/auth-service/dev.env b/auth-service/.env.development similarity index 100% rename from auth-service/dev.env rename to auth-service/.env.development diff --git a/compose.yaml b/compose.yaml index 99c6a2d..41c59e6 100644 --- a/compose.yaml +++ b/compose.yaml @@ -11,7 +11,7 @@ services: ports: - "3200:3200" # Expose port to the same host env_file: - - ./assignment-db-service/dev.env + - ./assignment-db-service/.env.development networks: - backend @@ -25,7 +25,7 @@ services: ports: - "8082:8082" # Expose port to the same host env_file: - - ./assignment-service/dev.env + - ./assignment-service/.env.development depends_on: - js-assignment-db-service networks: @@ -41,7 +41,7 @@ services: ports: - "8080:8080" # Expose port to the same host env_file: - - ./auth-service/dev.env + - ./auth-service/.env.development networks: - backend @@ -55,7 +55,7 @@ services: ports: - "3100:3100" # Expose port to the same host env_file: - - ./user-db-service/dev.env + - ./user-db-service/.env.development networks: - backend diff --git a/user-db-service/dev.env b/user-db-service/.env.development similarity index 100% rename from user-db-service/dev.env rename to user-db-service/.env.development From 9b7e8ab276a983b38226639f3ed220112d1f817c Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Fri, 2 May 2025 12:41:41 -0700 Subject: [PATCH 02/15] merge with main --- assignment-service/package-lock.json | 198 ++++++++++++++++-- assignment-service/package.json | 1 + assignment-service/routes/InstructorRouter.js | 35 +++- assignment-service/routes/StudentRouter.js | 50 ++++- auth-service/.env.development | 2 + auth-service/package-lock.json | 123 +++++++++++ auth-service/package.json | 6 +- auth-service/passport.js | 61 ++++-- auth-service/routes/auth.js | 10 + uploader-service/app.js | 2 +- 10 files changed, 434 insertions(+), 54 deletions(-) diff --git a/assignment-service/package-lock.json b/assignment-service/package-lock.json index 683f7be..099ea78 100644 --- a/assignment-service/package-lock.json +++ b/assignment-service/package-lock.json @@ -15,6 +15,7 @@ "dotenv": "^16.5.0", "express": "^5.1.0", "express-session": "^1.18.1", + "multer": "^1.4.5-lts.2", "nodemon": "^3.1.9", "passport": "^0.7.0" }, @@ -112,6 +113,12 @@ "node": ">= 8" } }, + "node_modules/append-field": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz", + "integrity": "sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw==", + "license": "MIT" + }, "node_modules/aproba": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/aproba/-/aproba-2.0.0.tgz", @@ -240,6 +247,23 @@ "node": ">=8" } }, + "node_modules/buffer-from": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", + "license": "MIT" + }, + "node_modules/busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "dependencies": { + "streamsearch": "^1.1.0" + }, + "engines": { + "node": ">=10.16.0" + } + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -338,6 +362,51 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "license": "MIT" }, + "node_modules/concat-stream": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", + "engines": [ + "node >= 0.8" + ], + "license": "MIT", + "dependencies": { + "buffer-from": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^2.2.2", + "typedarray": "^0.0.6" + } + }, + "node_modules/concat-stream/node_modules/readable-stream": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "license": "MIT", + "dependencies": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "node_modules/concat-stream/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "license": "MIT" + }, + "node_modules/concat-stream/node_modules/string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "license": "MIT", + "dependencies": { + "safe-buffer": "~5.1.0" + } + }, "node_modules/console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", @@ -383,6 +452,12 @@ "node": ">=6.6.0" } }, + "node_modules/core-util-is": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", + "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", + "license": "MIT" + }, "node_modules/cors": { "version": "2.8.5", "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", @@ -826,20 +901,6 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "license": "ISC" }, - "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, - "license": "MIT", - "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", @@ -1153,6 +1214,12 @@ "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", "license": "MIT" }, + "node_modules/isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "license": "MIT" + }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -1251,7 +1318,6 @@ "version": "1.2.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", - "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" @@ -1309,6 +1375,79 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "license": "MIT" }, + "node_modules/multer": { + "version": "1.4.5-lts.2", + "resolved": "https://registry.npmjs.org/multer/-/multer-1.4.5-lts.2.tgz", + "integrity": "sha512-VzGiVigcG9zUAoCNU+xShztrlr1auZOlurXynNvO9GiWD1/mTBbUljOKY+qMeazBqXgRnjzeEgJI/wyjJUHg9A==", + "license": "MIT", + "dependencies": { + "append-field": "^1.0.0", + "busboy": "^1.0.0", + "concat-stream": "^1.5.2", + "mkdirp": "^0.5.4", + "object-assign": "^4.1.1", + "type-is": "^1.6.4", + "xtend": "^4.0.0" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/multer/node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/multer/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==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/multer/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==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/multer/node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "license": "MIT", + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, + "node_modules/multer/node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "license": "MIT", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/negotiator": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", @@ -1557,6 +1696,12 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/process-nextick-args": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", + "license": "MIT" + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -1931,6 +2076,14 @@ "node": ">= 0.8" } }, + "node_modules/streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/string_decoder": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", @@ -2045,6 +2198,12 @@ "node": ">= 0.6" } }, + "node_modules/typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==", + "license": "MIT" + }, "node_modules/uid-safe": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz", @@ -2143,6 +2302,15 @@ "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", "license": "ISC" }, + "node_modules/xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", + "license": "MIT", + "engines": { + "node": ">=0.4" + } + }, "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", diff --git a/assignment-service/package.json b/assignment-service/package.json index 365e94e..7e1714a 100644 --- a/assignment-service/package.json +++ b/assignment-service/package.json @@ -16,6 +16,7 @@ "dotenv": "^16.5.0", "express": "^5.1.0", "express-session": "^1.18.1", + "multer": "^1.4.5-lts.2", "nodemon": "^3.1.9", "passport": "^0.7.0" }, diff --git a/assignment-service/routes/InstructorRouter.js b/assignment-service/routes/InstructorRouter.js index ffee372..8fa3cff 100644 --- a/assignment-service/routes/InstructorRouter.js +++ b/assignment-service/routes/InstructorRouter.js @@ -1,23 +1,44 @@ const intructorRouter = require("express").Router(); const passport = require("passport"); const axios = require("axios"); +const multer = require('multer'); +const FormData = require('form-data'); + const DB_ASSIGNMENT_SERVICE_URL = process.env.DB_ASSIGNMENT_SERVICE_URL || "http://localhost:3000"; console.log("DB_ASSIGNMENT_SERVICE_URL:", DB_ASSIGNMENT_SERVICE_URL); +// Use memory storage to keep file in RAM +const upload = multer({ storage: multer.memoryStorage() }); + + // This endpoint is for instructors to create a new assignment -intructorRouter.post( - "/create", - // passport.authenticate("jwt", { session: false }), +intructorRouter.post("/create", + upload.single('file'), + // passport.authenticate("jwt", { session: false }), async (req, res) => { try { + + const file = req.file; + const assignmentData = req.body; + + if (!file) { + return res.status(400).send('No file uploaded.'); + } + + await axios.post('https://target-api.com/endpoint', { + filename: file.originalname, + mimetype: file.mimetype, + content: file.buffer.toString('base64') + }, { + headers: { + 'Content-Type': 'application/json' + } + }); console.log("Creating a new assignment with data:", req.body); - const response = await axios.post( - `${DB_ASSIGNMENT_SERVICE_URL}/assignments`, - req.body - ); + const response = await axios.post(`${DB_ASSIGNMENT_SERVICE_URL}/assignments`, req.body); console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); res.status(response.status).json(response.data); } catch (error) { diff --git a/assignment-service/routes/StudentRouter.js b/assignment-service/routes/StudentRouter.js index 63f07a2..a84b271 100644 --- a/assignment-service/routes/StudentRouter.js +++ b/assignment-service/routes/StudentRouter.js @@ -1,13 +1,49 @@ const studentRouter = require("express").Router(); const passport = require("passport"); const axios = require("axios"); +const bcrypt = require("bcrypt"); +require("dotenv").config(); +const DB_ASSIGNMENT_SERVICE_URL = process.env.DB_ASSIGNMENT_SERVICE_URL; -studentRouter.post("/save", (req, res) => { - + +studentRouter.post("/save", (req, res) => {}); + +studentRouter.post("/deploy", (req, res) => {}); + +studentRouter.post("/verify/", async (req, res) => { + try { + const assignmentId = req.body.id; + const password = req.body.password; + console.log( + "Accessing assignment with ID:", + assignmentId, + "and password:", + password + ); + + console.log(`Fetching from URL: ${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`); + const response = await axios.get( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}` + ); + + console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); + console.log("Password provided:", password); + console.log("Password hash from database:", response.data.passwordhash); + + const isPasswordValid = await bcrypt.compare( + password, + response.data.passwordhash + ); + + if (!isPasswordValid || !response.data) { + return res.status(401).json({ error: "Invalid id and password" }); + } + + res.status(response.status).json(response.data); + } catch (error) { + console.error("Error fetching assignment details:", error.message); + res.status(error.response?.status || 500).json({ error: error.message }); + } }); -studentRouter.post("/deploy", (req, res) => { - -}); - -module.exports = studentRouter; \ No newline at end of file +module.exports = studentRouter; diff --git a/auth-service/.env.development b/auth-service/.env.development index 794749f..74b17a1 100644 --- a/auth-service/.env.development +++ b/auth-service/.env.development @@ -1,3 +1,5 @@ +NODE_ENV=development + GOOGLE_CLIENT_ID="485880105639-1in8tvb6ondnn198rasuj2d8ank06ntp.apps.googleusercontent.com" GOOGLE_CLIENT_SECRET="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" GOOGLE_CALLBACK_URL="http://localhost:8080/auth/google/callback" diff --git a/auth-service/package-lock.json b/auth-service/package-lock.json index 495b39d..26d2726 100644 --- a/auth-service/package-lock.json +++ b/auth-service/package-lock.json @@ -16,7 +16,11 @@ "express-session": "^1.18.1", "nodemon": "^3.1.9", "passport": "^0.7.0", + "passport-custom": "^1.1.1", "passport-google-oauth20": "^2.0.0" + }, + "devDependencies": { + "dotenv-cli": "^8.0.0" } }, "node_modules/accepts": { @@ -280,6 +284,21 @@ "node": ">= 0.10" } }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "dev": true, + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -325,6 +344,32 @@ "url": "https://dotenvx.com" } }, + "node_modules/dotenv-cli": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-8.0.0.tgz", + "integrity": "sha512-aLqYbK7xKOiTMIRf1lDPbI+Y+Ip/wo5k3eyp6ePysVaSqbyxjyK3dK35BTxG+rmd7djf5q2UPs4noPNH+cj0Qw==", + "dev": true, + "license": "MIT", + "dependencies": { + "cross-spawn": "^7.0.6", + "dotenv": "^16.3.0", + "dotenv-expand": "^10.0.0", + "minimist": "^1.2.6" + }, + "bin": { + "dotenv": "cli.js" + } + }, + "node_modules/dotenv-expand": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz", + "integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -847,6 +892,13 @@ "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", "license": "MIT" }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true, + "license": "ISC" + }, "node_modules/math-intrinsics": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", @@ -910,6 +962,16 @@ "node": "*" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -1063,6 +1125,18 @@ "url": "https://github.com/sponsors/jaredhanson" } }, + "node_modules/passport-custom": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/passport-custom/-/passport-custom-1.1.1.tgz", + "integrity": "sha512-/2m7jUGxmCYvoqenLB9UrmkCgPt64h8ZtV+UtuQklZ/Tn1NpKBeOorCYkB/8lMRoiZ5hUrCoMmDtxCS/d38mlg==", + "license": "MIT", + "dependencies": { + "passport-strategy": "1.x.x" + }, + "engines": { + "node": ">= 0.10.0" + } + }, "node_modules/passport-google-oauth20": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/passport-google-oauth20/-/passport-google-oauth20-2.0.0.tgz", @@ -1103,6 +1177,16 @@ "node": ">= 0.4.0" } }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/path-to-regexp": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.2.0.tgz", @@ -1345,6 +1429,29 @@ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "license": "ISC" }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/side-channel": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", @@ -1545,6 +1652,22 @@ "node": ">= 0.8" } }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/auth-service/package.json b/auth-service/package.json index 14d0810..2d95f65 100644 --- a/auth-service/package.json +++ b/auth-service/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "main": "server.js", "scripts": { - "dev": "nodemon server.js" + "dev": "dotenv -e .env.development nodemon server.js" }, "keywords": [], "author": "", @@ -17,6 +17,10 @@ "express-session": "^1.18.1", "nodemon": "^3.1.9", "passport": "^0.7.0", + "passport-custom": "^1.1.1", "passport-google-oauth20": "^2.0.0" + }, + "devDependencies": { + "dotenv-cli": "^8.0.0" } } diff --git a/auth-service/passport.js b/auth-service/passport.js index e65e7c8..2f32e34 100644 --- a/auth-service/passport.js +++ b/auth-service/passport.js @@ -1,36 +1,51 @@ -require('dotenv').config(); +require("dotenv").config(); const GoogleStrategy = require("passport-google-oauth20").Strategy; const passport = require("passport"); +const CustomStrategy = require("passport-custom").Strategy; passport.use( - new GoogleStrategy( - { - clientID: process.env.GOOGLE_CLIENT_ID, - clientSecret: process.env.GOOGLE_CLIENT_SECRET, - callbackURL: process.env.GOOGLE_CALLBACK_URL, - scope: ["profile", "email"], - }, - function (accessToken, refreshToken, profile, callback) { + new GoogleStrategy( + { + clientID: process.env.GOOGLE_CLIENT_ID, + clientSecret: process.env.GOOGLE_CLIENT_SECRET, + callbackURL: process.env.GOOGLE_CALLBACK_URL, + scope: ["profile", "email"], + }, + function (accessToken, refreshToken, profile, callback) { + callback(null, profile); + } + ) +); - // Save the user info to your DB here if still not yet saved - // Example of what profile might contain: - // { - // "id": "112233445566778899", - // "displayName": "John Doe", - // "emails": [{ "value": "john.doe@gmail.com" }], - // "photos": [{ "value": "https://.../photo.jpg" }] - // } +passport.use( + "student-auth", + new CustomStrategy(async (req, done) => { + const { assignment, password } = req.body; - callback(null, profile); - } - ) + try { + // Call your external auth service + const response = await axios.post("http://localhost:8082/student/verify", { + assignment, + password, + }); + + if (response.data && response.data.success) { + const user = response.data.user; + return done(null, user); // success + } else { + return done(null, false, { message: "Invalid credentials" }); + } + } catch (err) { + return done(err); + } + }) ); passport.serializeUser((user, done) => { - done(null, user); + done(null, user); }); passport.deserializeUser((user, done) => { - done(null,user); -}); \ No newline at end of file + done(null, user); +}); diff --git a/auth-service/routes/auth.js b/auth-service/routes/auth.js index 782d09c..3c8e9de 100644 --- a/auth-service/routes/auth.js +++ b/auth-service/routes/auth.js @@ -52,6 +52,16 @@ router.get("/login/failed", (req, res) => { router.get("/google", passport.authenticate("google", ["profile", "email"])); +router.post("/student/login", (req, res) => { + passport.authenticate("student-auth"), + (req, res) => { + res.json({ + message: "Authenticated via external service", + user: req.user, + }); + }; +}); + router.get("/logout", (req, res) => { req.logOut(); res.redirect(process.env.LOGIN_REDIRECT_URL); diff --git a/uploader-service/app.js b/uploader-service/app.js index 6d71209..453324c 100644 --- a/uploader-service/app.js +++ b/uploader-service/app.js @@ -102,7 +102,7 @@ app.post('/machines/get', async (req, res) => { // Endpoint to upload files to Google Drive app.post('/drive/upload', upload.fields([{ name: 'pythonFile' }, { name: 'jsonFile', maxCount: 1 }]), async (req, res) => { const { folderLink } = req.body; - const { pythonFile, jsonFile } = req.files; + const { pythonFile, jsonFile } = req.files; if (!folderLink || !pythonFile) { return res.status(400).json({ error: 'Folder link and Python file are required' }); From adb005ae33965ff5dc5c7ea03704de11cf9db0e5 Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Fri, 2 May 2025 15:06:00 -0700 Subject: [PATCH 03/15] working logout and student login --- assignment-service/routes/StudentRouter.js | 11 ++++- auth-service/.env.development | 2 +- auth-service/passport.js | 50 ++++++++++++++++------ auth-service/routes/auth.js | 48 +++++++++++++++++---- auth-service/server.js | 7 +++ 5 files changed, 94 insertions(+), 24 deletions(-) diff --git a/assignment-service/routes/StudentRouter.js b/assignment-service/routes/StudentRouter.js index a84b271..6dcf37b 100644 --- a/assignment-service/routes/StudentRouter.js +++ b/assignment-service/routes/StudentRouter.js @@ -10,10 +10,12 @@ studentRouter.post("/save", (req, res) => {}); studentRouter.post("/deploy", (req, res) => {}); -studentRouter.post("/verify/", async (req, res) => { +studentRouter.post("/verify", async (req, res) => { try { - const assignmentId = req.body.id; + const assignmentId = req.body.assignmentId; const password = req.body.password; + console.log("Received request to verify assignment."); + console.log("Request body:", req.body); console.log( "Accessing assignment with ID:", assignmentId, @@ -35,13 +37,18 @@ studentRouter.post("/verify/", async (req, res) => { response.data.passwordhash ); + console.log("Password validation result:", isPasswordValid); + if (!isPasswordValid || !response.data) { + console.log("Invalid id or password."); return res.status(401).json({ error: "Invalid id and password" }); } + console.log("Verification successful. Sending response."); res.status(response.status).json(response.data); } catch (error) { console.error("Error fetching assignment details:", error.message); + console.error("Error details:", error); res.status(error.response?.status || 500).json({ error: error.message }); } }); diff --git a/auth-service/.env.development b/auth-service/.env.development index 74b17a1..91cdcab 100644 --- a/auth-service/.env.development +++ b/auth-service/.env.development @@ -5,6 +5,6 @@ GOOGLE_CLIENT_SECRET="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" GOOGLE_CALLBACK_URL="http://localhost:8080/auth/google/callback" LOGIN_REDIRECT_URL="http://localhost:5173/" ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 -DB_USER_SERVICE_URL="http://js-user-db-service:3100/" +DB_USER_SERVICE_URL="http://localhost:3100/" AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" PORT=8080 \ No newline at end of file diff --git a/auth-service/passport.js b/auth-service/passport.js index 2f32e34..1b6b835 100644 --- a/auth-service/passport.js +++ b/auth-service/passport.js @@ -3,6 +3,7 @@ require("dotenv").config(); const GoogleStrategy = require("passport-google-oauth20").Strategy; const passport = require("passport"); const CustomStrategy = require("passport-custom").Strategy; +const axios = require("axios"); passport.use( new GoogleStrategy( @@ -13,7 +14,7 @@ passport.use( scope: ["profile", "email"], }, function (accessToken, refreshToken, profile, callback) { - callback(null, profile); + callback(null, {...profile, role: "instructor"}); } ) ); @@ -21,31 +22,56 @@ passport.use( passport.use( "student-auth", new CustomStrategy(async (req, done) => { - const { assignment, password } = req.body; + const { assignmentId, password } = req.body; + + console.log("Custom strategy invoked"); + console.log("Received assignmentId:", assignmentId); + console.log("Received password:", password); try { - // Call your external auth service - const response = await axios.post("http://localhost:8082/student/verify", { - assignment, - password, - }); + console.log("Sending request to external auth service..."); + const response = await axios.post( + "http://localhost:8082/student/verify", + { + assignmentId, + password, + } + ); - if (response.data && response.data.success) { - const user = response.data.user; + if (response.status === 200 && response.data) { + user = { + ...response.data, + role: "student", + }; + console.log("Authentication successful, user:", user); return done(null, user); // success } else { + console.log("Authentication failed: Invalid credentials"); return done(null, false, { message: "Invalid credentials" }); } } catch (err) { + console.error("Error during authentication:", err); return done(err); } }) ); passport.serializeUser((user, done) => { - done(null, user); + // done(null, user); + console.log("Serializing user:", user); + done(null, { + id: user.assignmentid || user.emal, + displayName: user.studentname || user.displayName, + role: user.role, + }); }); -passport.deserializeUser((user, done) => { - done(null, user); +passport.deserializeUser(async (user, done) => { + try { + console.log("Deserializing user:", user); + done(null, user); + } catch (err) { + console.error("Error during deserialization:", err); + done(err); + } }); diff --git a/auth-service/routes/auth.js b/auth-service/routes/auth.js index 3c8e9de..47e848b 100644 --- a/auth-service/routes/auth.js +++ b/auth-service/routes/auth.js @@ -11,6 +11,8 @@ router.get( ); router.get("/current_user", (req, res) => { + console.log("Current user endpoint hit"); + console.log("Request user:", req.user); if (req.isAuthenticated()) { console.log("Authenticated user:", req.user); res.json(req.user); @@ -52,19 +54,47 @@ router.get("/login/failed", (req, res) => { router.get("/google", passport.authenticate("google", ["profile", "email"])); -router.post("/student/login", (req, res) => { +router.post( + "/student/login", passport.authenticate("student-auth"), - (req, res) => { - res.json({ - message: "Authenticated via external service", - user: req.user, + (req, res) => { + console.log("Student login endpoint hit"); + + if (req.user) { + console.log("Authenticated user:", req.user); + console.log("Processing student login..."); + + // Optional: augment user object (doesn't affect session unless you reserialize) + req.user.userId = req.user.assignmentid; + req.user.role = "student"; + + req.logIn(req.user, function(err) { + if (err) return next(err); + + console.log('is authenticated?: ' + req.isAuthenticated()); + + return res.json({ + success: true, + message: 'Successful Login', + user: req.user + }); }); - }; -}); + + } else { + console.log("Authentication failed"); + res.status(401).json({ error: true, message: "Authentication failed" }); + } + } +); router.get("/logout", (req, res) => { - req.logOut(); - res.redirect(process.env.LOGIN_REDIRECT_URL); + + req.logout((err) => { + if (err) { + return next(err); + } + res.redirect(process.env.LOGIN_REDIRECT_URL); + }); }); module.exports = router; diff --git a/auth-service/server.js b/auth-service/server.js index 8e92dce..f9ac814 100644 --- a/auth-service/server.js +++ b/auth-service/server.js @@ -6,10 +6,14 @@ const passport = require("passport"); const passportSetup = require("./passport"); const authRoute = require("./routes/auth"); const session = require("express-session"); +const bodyParser = require("body-parser"); const app = express(); +app.use(bodyParser.json()); // or express.json() +app.use(bodyParser.urlencoded({ extended: true })); app.use( + session({ secret: process.env.AUTH_SESSION_KEY, resave: false, @@ -31,6 +35,9 @@ app.use( }) ) + +app.use(express.json()); + app.use("/auth", authRoute); const port = process.env.PORT || 8080; From b3dcec17c0fb7d4f3b5263d604343f8aef214b93 Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Fri, 2 May 2025 17:19:47 -0700 Subject: [PATCH 04/15] bug fix for login via google --- auth-service/passport.js | 3 ++- auth-service/routes/auth.js | 2 +- user-db-service/.env | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/auth-service/passport.js b/auth-service/passport.js index 1b6b835..1448a9d 100644 --- a/auth-service/passport.js +++ b/auth-service/passport.js @@ -60,9 +60,10 @@ passport.serializeUser((user, done) => { // done(null, user); console.log("Serializing user:", user); done(null, { - id: user.assignmentid || user.emal, + id: user.assignmentid || user.id, displayName: user.studentname || user.displayName, role: user.role, + emails: user.emails || "none", }); }); diff --git a/auth-service/routes/auth.js b/auth-service/routes/auth.js index 47e848b..05d5f63 100644 --- a/auth-service/routes/auth.js +++ b/auth-service/routes/auth.js @@ -73,7 +73,7 @@ router.post( console.log('is authenticated?: ' + req.isAuthenticated()); - return res.json({ + return res.status(200).json({ success: true, message: 'Successful Login', user: req.user diff --git a/user-db-service/.env b/user-db-service/.env index 3aaa685..52a3ca1 100644 --- a/user-db-service/.env +++ b/user-db-service/.env @@ -5,8 +5,8 @@ # See the documentation for all the connection string options: https://pris.ly/d/connection-strings #use this when testing local, remmber to run the proxy command -# DATABASE_URL="postgresql://postgres:wly9H8gjjmxYfg1@localhost:15432/postgres?schema=public" +DATABASE_URL="postgresql://postgres:wly9H8gjjmxYfg1@localhost:15432/postgres?schema=public" -DATABASE_URL="postgres://postgres:wly9H8gjjmxYfg1@bytecamp-db.flycast:5432?sslmode=disable" +# DATABASE_URL="postgres://postgres:wly9H8gjjmxYfg1@bytecamp-db.flycast:5432?sslmode=disable" # DATABASE_URL=postgres://snakebyte:zVB7lgOiKr89dq6@localhost:5432/snakebyte?sslmode=disable -NODE_PORT=3000 +NODE_PORT=3100 From 0defbfea5a4dfff161f959fa8dd91eec0068217e Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Fri, 2 May 2025 18:33:50 -0700 Subject: [PATCH 05/15] bug fix for fly server --- assignment-db-service/fly.toml | 35 ++++++++++++++++++++--------- assignment-service/.env | 1 + assignment-service/.env.development | 2 +- assignment-service/.env.test | 2 +- assignment-service/server.js | 2 +- auth-service/.env | 1 + auth-service/.env.development | 1 + auth-service/passport.js | 2 +- auth-service/server.js | 1 - user-db-service/fly.toml | 7 ++---- 10 files changed, 33 insertions(+), 21 deletions(-) diff --git a/assignment-db-service/fly.toml b/assignment-db-service/fly.toml index 18fc89d..4f08c1f 100644 --- a/assignment-db-service/fly.toml +++ b/assignment-db-service/fly.toml @@ -7,26 +7,39 @@ app = 'db-assignment-service' primary_region = 'sea' [build] +# Only needed if you're using a Dockerfile — can be empty if using buildpacks or Node preset -[http_service] - internal_port = 3000 - force_https = true - auto_stop_machines = 'stop' - auto_start_machines = true - min_machines_running = 0 - processes = ['app'] +# Removed the [http_service] section to disable public HTTP/HTTPS access +# [http_service] +# internal_port = 3000 +# force_https = true +# auto_stop_machines = true +# auto_start_machines = true +# min_machines_running = 0 +# processes = ["app"] [[services]] - protocol = 'tcp' + protocol = "tcp" internal_port = 3000 - ports = [] + internal_only = true # Makes this service only accessible internally + auto_start_machines = true + auto_stop_machines = true + + # Removed public port exposure + # [[services.ports]] + # port = 80 + # handlers = ["http"] + + # [[services.ports]] + # port = 443 + # handlers = ["tls", "http"] [services.concurrency] - type = 'requests' + type = "requests" hard_limit = 1000 soft_limit = 500 [[vm]] memory = '1gb' - cpu_kind = 'shared' + cpu_kind = "shared" cpus = 1 diff --git a/assignment-service/.env b/assignment-service/.env index b948690..9cf3674 100644 --- a/assignment-service/.env +++ b/assignment-service/.env @@ -1,2 +1,3 @@ #DB_ASSIGNMENT_SERVICE_URL = "http://localhost:3000" DB_ASSIGNMENT_SERVICE_URL = "http://db-assignment-service.internal:3000" +NODE_PORT = 8080 \ No newline at end of file diff --git a/assignment-service/.env.development b/assignment-service/.env.development index 1bc73e5..b0a3aab 100644 --- a/assignment-service/.env.development +++ b/assignment-service/.env.development @@ -3,4 +3,4 @@ NODE_ENV=development DB_ASSIGNMENT_SERVICE_URL="http://localhost:3200" AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 -PORT=8082 \ No newline at end of file +NODE_PORT=8082 \ No newline at end of file diff --git a/assignment-service/.env.test b/assignment-service/.env.test index d39a82f..8323fe9 100644 --- a/assignment-service/.env.test +++ b/assignment-service/.env.test @@ -3,4 +3,4 @@ NODE_ENV=development DB_ASSIGNMENT_SERVICE_URL="http://js-assignment-db-service:3200" AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 -PORT=8082 \ No newline at end of file +NODE_PORT=8082 \ No newline at end of file diff --git a/assignment-service/server.js b/assignment-service/server.js index 875a189..354b1f4 100644 --- a/assignment-service/server.js +++ b/assignment-service/server.js @@ -39,5 +39,5 @@ app.use(cors()); app.use("/instructor", instructorRouter); app.use("/student", studentRouter); -const port = process.env.PORT || 8080; +const port = process.env.NODE_PORT || 8080; app.listen(port, () => console.log(`Listening on port ${port}...`)); \ No newline at end of file diff --git a/auth-service/.env b/auth-service/.env index 4fe65d0..a5e74f3 100644 --- a/auth-service/.env +++ b/auth-service/.env @@ -6,6 +6,7 @@ ACCEPTED_ORIGINS ="https://bytecamp-web.fly.dev,https://byte-camp-auth-service.f #DB_USER_SERVICE_URL = "http://localhost:3000/" DB_USER_SERVICE_URL = "http://db-user-service.internal:3000/" AUTH_SESSION_KEY = "f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" +ASSIGNMENT_SERVICE_URL="http://assignment-service.internal:8080" # fly secrets set GOOGLE_CALLBACK_URL=https://byte-camp-auth-service.fly.dev/auth/google/callback #fly secrets set GOOGLE_CLIENT_ID=485880105639-1in8tvb6ondnn198rasuj2d8ank06ntp.apps.googleusercontent.com GOOGLE_CLIENT_SECRET=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 LOGIN_REDIRECT_URL=https://bytecamp-web.fly.dev/ DB_USER_SERVICE_URL=https://db-user-service.fly.dev:3000/ AUTH_SESSION_KEY=f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42 \ No newline at end of file diff --git a/auth-service/.env.development b/auth-service/.env.development index 91cdcab..e302c2f 100644 --- a/auth-service/.env.development +++ b/auth-service/.env.development @@ -5,6 +5,7 @@ GOOGLE_CLIENT_SECRET="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" GOOGLE_CALLBACK_URL="http://localhost:8080/auth/google/callback" LOGIN_REDIRECT_URL="http://localhost:5173/" ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 +ASSIGNMENT_SERVICE_URL="http://localhost:8082/" DB_USER_SERVICE_URL="http://localhost:3100/" AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" PORT=8080 \ No newline at end of file diff --git a/auth-service/passport.js b/auth-service/passport.js index 1448a9d..8ef091d 100644 --- a/auth-service/passport.js +++ b/auth-service/passport.js @@ -31,7 +31,7 @@ passport.use( try { console.log("Sending request to external auth service..."); const response = await axios.post( - "http://localhost:8082/student/verify", + `${process.env.ASSIGNMENT_SERVICE_URL}/student/verify`, { assignmentId, password, diff --git a/auth-service/server.js b/auth-service/server.js index f9ac814..924dfac 100644 --- a/auth-service/server.js +++ b/auth-service/server.js @@ -35,7 +35,6 @@ app.use( }) ) - app.use(express.json()); app.use("/auth", authRoute); diff --git a/user-db-service/fly.toml b/user-db-service/fly.toml index 07d92c2..30dbd0d 100644 --- a/user-db-service/fly.toml +++ b/user-db-service/fly.toml @@ -6,11 +6,6 @@ primary_region = "sea" [build] # Only needed if you're using a Dockerfile — can be empty if using buildpacks or Node preset -#[env] - #NODE_ENV = "production" - #DATABASE_URL = "postgresql://user:password@hostname:port/dbname" - # you can also leave DATABASE_URL unset here and use secrets instead - # Removed the [http_service] section to disable public HTTP/HTTPS access # [http_service] # internal_port = 3000 @@ -24,6 +19,8 @@ primary_region = "sea" protocol = "tcp" internal_port = 3000 internal_only = true # Makes this service only accessible internally + auto_start_machines = true + auto_stop_machines = true # Removed public port exposure # [[services.ports]] From 5ce01158ade45323e6e5836767092d6f3a51f434 Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Mon, 5 May 2025 14:50:05 -0700 Subject: [PATCH 06/15] submit assignment now creates an fly machine --- assignment-db-service/app.js | 6 +- assignment-service/.env | 2 +- assignment-service/.env.development | 11 +- assignment-service/.env.test | 6 +- assignment-service/dev.env | 5 - assignment-service/routes/InstructorRouter.js | 93 ++++++-- assignment-service/routes/StudentRouter.js | 15 ++ deployment-service/src/index.js | 205 ++++++++++-------- 8 files changed, 215 insertions(+), 128 deletions(-) delete mode 100644 assignment-service/dev.env diff --git a/assignment-db-service/app.js b/assignment-db-service/app.js index 09f0055..659a31f 100644 --- a/assignment-db-service/app.js +++ b/assignment-db-service/app.js @@ -43,15 +43,15 @@ async function convertToAssignment(req) { const hashPassword = await encryptPassword(req.body.password); return { - campid: campid, - programid: programid, + campid: parseInt(campid), + programid: parseInt(programid), studentname: studentname, snakegameid: snakegameid, originalfile: originalfile, editablefile: editablefile, assignmenturl: assignmenturl, passwordhash: hashPassword, - instructorid: instructorid, + instructorid: parseInt(instructorid), }; } diff --git a/assignment-service/.env b/assignment-service/.env index 9cf3674..f5f5b51 100644 --- a/assignment-service/.env +++ b/assignment-service/.env @@ -1,3 +1,3 @@ -#DB_ASSIGNMENT_SERVICE_URL = "http://localhost:3000" DB_ASSIGNMENT_SERVICE_URL = "http://db-assignment-service.internal:3000" +DEPLOY_API_URL="http://localhost:3006" NODE_PORT = 8080 \ No newline at end of file diff --git a/assignment-service/.env.development b/assignment-service/.env.development index b0a3aab..b683362 100644 --- a/assignment-service/.env.development +++ b/assignment-service/.env.development @@ -1,6 +1,11 @@ NODE_ENV=development -#DB_ASSIGNMENT_SERVICE_URL="http://localhost:3000" DB_ASSIGNMENT_SERVICE_URL="http://localhost:3200" -AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" -ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 +DEPLOY_API_URL="http://127.0.0.1:3006" + +AWS_ACCESS_KEY_ID='tid__NSmOVaGknqitaCySppZjqVTgJSdDFnFbWcQllkC_juHwkbQZO' +AWS_ENDPOINT_URL_S3='https://fly.storage.tigris.dev' +AWS_REGION='auto' +AWS_SECRET_ACCESS_KEY='tsec_6Bz1aMbfYQftuq5WfIVEDZkHwskU4MMjVywdtxSP6uxetEBvkSC2VHI9HfTeDgHr4D6kiz' +COMMON_BUCKET='snakeapi-deployment-test-bucket' + NODE_PORT=8082 \ No newline at end of file diff --git a/assignment-service/.env.test b/assignment-service/.env.test index 8323fe9..fd1e4e1 100644 --- a/assignment-service/.env.test +++ b/assignment-service/.env.test @@ -1,6 +1,4 @@ -NODE_ENV=development -#DB_ASSIGNMENT_SERVICE_URL="http://localhost:3000" +NODE_ENV=test DB_ASSIGNMENT_SERVICE_URL="http://js-assignment-db-service:3200" -AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" -ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 +DEPLOY_API_URL="http://localhost:3006/deploy" NODE_PORT=8082 \ No newline at end of file diff --git a/assignment-service/dev.env b/assignment-service/dev.env deleted file mode 100644 index c457dfa..0000000 --- a/assignment-service/dev.env +++ /dev/null @@ -1,5 +0,0 @@ -#DB_ASSIGNMENT_SERVICE_URL="http://localhost:3000" -DB_ASSIGNMENT_SERVICE_URL="http://js-assignment-db-service:3200" -AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" -ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 -PORT=8082 \ No newline at end of file diff --git a/assignment-service/routes/InstructorRouter.js b/assignment-service/routes/InstructorRouter.js index 8fa3cff..9cd23d6 100644 --- a/assignment-service/routes/InstructorRouter.js +++ b/assignment-service/routes/InstructorRouter.js @@ -1,45 +1,98 @@ const intructorRouter = require("express").Router(); const passport = require("passport"); const axios = require("axios"); -const multer = require('multer'); -const FormData = require('form-data'); +const multer = require("multer"); +const FormData = require("form-data"); +const fs = require('fs'); +const path = require('path'); +const AWS = require('aws-sdk'); + +// const { +// COMMON_BUCKET, +// AWS_ACCESS_KEY_ID, +// AWS_SECRET_ACCESS_KEY, +// AWS_ENDPOINT_URL_S3, +// AWS_REGION, +// } = process.env; + +// Log environment variables for debugging +// console.log('--- ENV START ---'); +// console.log('COMMON_BUCKET: ', COMMON_BUCKET); +// console.log('AWS_ACCESS_KEY_ID: ', AWS_ACCESS_KEY_ID ? '(found)' : '(NOT SET)'); +// console.log('AWS_SECRET_ACCESS_KEY:', AWS_SECRET_ACCESS_KEY ? '(found)' : '(NOT SET)'); +// console.log('AWS_ENDPOINT_URL_S3: ', AWS_ENDPOINT_URL_S3); +// console.log('AWS_REGION: ', AWS_REGION); +// console.log('--- ENV END ---'); const DB_ASSIGNMENT_SERVICE_URL = process.env.DB_ASSIGNMENT_SERVICE_URL || "http://localhost:3000"; + +const DEPLOY_API_URL = process.env.DEPLOY_API_URL || "http://localhost:3600"; + console.log("DB_ASSIGNMENT_SERVICE_URL:", DB_ASSIGNMENT_SERVICE_URL); +console.log("DEPLOY_API_URL:", DEPLOY_API_URL); + + +// const s3 = new AWS.S3({ +// endpoint: AWS_ENDPOINT_URL_S3, +// region: AWS_REGION, +// credentials: new AWS.Credentials(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY), +// s3ForcePathStyle: true +// }); // Use memory storage to keep file in RAM const upload = multer({ storage: multer.memoryStorage() }); - // This endpoint is for instructors to create a new assignment -intructorRouter.post("/create", - upload.single('file'), - // passport.authenticate("jwt", { session: false }), +intructorRouter.post( + "/create", + upload.single("file"), + // passport.authenticate("jwt", { session: false }), async (req, res) => { try { - const file = req.file; const assignmentData = req.body; if (!file) { - return res.status(400).send('No file uploaded.'); + return res.status(400).send("No file uploaded."); } - await axios.post('https://target-api.com/endpoint', { - filename: file.originalname, - mimetype: file.mimetype, - content: file.buffer.toString('base64') - }, { - headers: { - 'Content-Type': 'application/json' - } - }); - console.log("Creating a new assignment with data:", req.body); - const response = await axios.post(`${DB_ASSIGNMENT_SERVICE_URL}/assignments`, req.body); + const response = await axios.post( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments`, + req.body + ); console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); + + // Upload the file to the S3 bucket + // console.log('Uploading notebook to S3'); + // const key = `${assignmentData.appname}/notebooks/${Date.now()}-notebook.ipynb`; + // console.log('S3 key:', key); + // await s3.putObject({ + // Bucket: COMMON_BUCKET, + // Key: key, + // Body: file.buffer, + // ContentType: 'application/json' + // }).promise(); + + // call upload api to upload the file to S3 + console.log("Uploading file to:", `${DEPLOY_API_URL}/${assignmentData.appname}/upload`); + const uploadResponse = await axios.post(`${DEPLOY_API_URL}/${assignmentData.appname}/upload`, { + "appName": assignmentData.appname, + "notebookName": file.originalname, + "fileContentBase64": file.buffer.toString('base64'), + }); + console.log('Response from DEPLOY_API_URL:', uploadResponse.data); + + // Deploy a new Battlesnake API + console.log('Deploying a new Battlesnake API'); + console.log("DEPLOY_API_URL:", DEPLOY_API_URL, assignmentData.appname); + const deployResponse = await axios.post(`${DEPLOY_API_URL}/deploy`, { + "appName": assignmentData.appname + }); + console.log('Response from DEPLOY_API_URL:', deployResponse.data); + res.status(response.status).json(response.data); } catch (error) { console.error("Error creating assignment:", error.message); @@ -56,7 +109,7 @@ intructorRouter.get("/details/:id", async (req, res) => { const response = await axios.get( `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}` ); - + console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); res.status(response.status).json(response.data); } catch (error) { diff --git a/assignment-service/routes/StudentRouter.js b/assignment-service/routes/StudentRouter.js index 6dcf37b..d57339a 100644 --- a/assignment-service/routes/StudentRouter.js +++ b/assignment-service/routes/StudentRouter.js @@ -10,6 +10,21 @@ studentRouter.post("/save", (req, res) => {}); studentRouter.post("/deploy", (req, res) => {}); +studentRouter.get("/assignment/:id", (req, res) => { + const assignmentId = req.params.id; + console.log("Fetching details for assignmentId:", assignmentId); + axios + .get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`) + .then((response) => { + console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); + res.status(response.status).json(response.data); + }) + .catch((error) => { + console.error("Error fetching assignment details:", error.message); + res.status(error.response?.status || 500).json({ error: error.message }); + }); +}); + studentRouter.post("/verify", async (req, res) => { try { const assignmentId = req.body.assignmentId; diff --git a/deployment-service/src/index.js b/deployment-service/src/index.js index 433392a..1467d13 100644 --- a/deployment-service/src/index.js +++ b/deployment-service/src/index.js @@ -1,8 +1,9 @@ -const express = require('express'); -const fs = require('fs'); -const path = require('path'); -const AWS = require('aws-sdk'); -const axios = require('axios'); +const express = require("express"); +const fs = require("fs"); +const path = require("path"); +const AWS = require("aws-sdk"); +const axios = require("axios"); +require("dotenv").config(); const { FLY_ORG, @@ -12,47 +13,56 @@ const { AWS_ENDPOINT_URL_S3, AWS_REGION, FLY_ACCESS_TOKEN, - IMAGE_REF + IMAGE_REF, } = process.env; // Log environment variables for debugging -console.log('--- ENV START ---'); -console.log('FLY_ORG: ', FLY_ORG); -console.log('COMMON_BUCKET: ', COMMON_BUCKET); -console.log('AWS_ACCESS_KEY_ID: ', AWS_ACCESS_KEY_ID ? '(found)' : '(NOT SET)'); -console.log('AWS_SECRET_ACCESS_KEY:', AWS_SECRET_ACCESS_KEY ? '(found)' : '(NOT SET)'); -console.log('AWS_ENDPOINT_URL_S3: ', AWS_ENDPOINT_URL_S3); -console.log('AWS_REGION: ', AWS_REGION); -console.log('FLY_ACCESS_TOKEN: ', FLY_ACCESS_TOKEN ? '(found)' : '(NOT SET)'); -console.log('IMAGE_REF: ', IMAGE_REF); -console.log('--- ENV END ---'); +console.log("--- ENV START ---"); +console.log("FLY_ORG: ", FLY_ORG); +console.log("COMMON_BUCKET: ", COMMON_BUCKET); +console.log( + "AWS_ACCESS_KEY_ID: ", + AWS_ACCESS_KEY_ID ? "(found)" : "(NOT SET)" +); +console.log( + "AWS_SECRET_ACCESS_KEY:", + AWS_SECRET_ACCESS_KEY ? "(found)" : "(NOT SET)" +); +console.log("AWS_ENDPOINT_URL_S3: ", AWS_ENDPOINT_URL_S3); +console.log("AWS_REGION: ", AWS_REGION); +console.log( + "FLY_ACCESS_TOKEN: ", + FLY_ACCESS_TOKEN ? "(found)" : "(NOT SET)" +); +console.log("IMAGE_REF: ", IMAGE_REF); +console.log("--- ENV END ---"); // Initialize S3 client const s3 = new AWS.S3({ endpoint: AWS_ENDPOINT_URL_S3, region: AWS_REGION, credentials: new AWS.Credentials(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY), - s3ForcePathStyle: true + s3ForcePathStyle: true, }); // Create Fly Machines API client function createFlyClient() { return axios.create({ - baseURL: 'https://api.machines.dev/v1', + baseURL: "https://api.machines.dev/v1", headers: { Authorization: `Bearer ${FLY_ACCESS_TOKEN}`, - 'Content-Type': 'application/json' - } + "Content-Type": "application/json", + }, }); } // Create Fly GraphQL client (for IP allocation) const gqlClient = axios.create({ - baseURL: 'https://api.fly.io/graphql', + baseURL: "https://api.fly.io/graphql", headers: { Authorization: `Bearer ${FLY_ACCESS_TOKEN}`, - 'Content-Type': 'application/json' - } + "Content-Type": "application/json", + }, }); // Define GraphQL mutation for IP allocation @@ -68,164 +78,175 @@ mutation AllocateIp($input: AllocateIPAddressInput!) { `; const app = express(); -app.use(express.json({ limit: '10mb' })); +app.use(express.json({ limit: "10mb" })); -app.post('/deploy', async (req, res) => { - console.log('Received /deploy:', req.body); - const { appName, region, notebookName } = req.body; - if (!appName || !notebookName) { - return res.status(400).json({ error: 'appName and notebookName required' }); +app.post("/deploy", async (req, res) => { + console.log("Received /deploy:", req.body); + const { + appName, + // , region + // , notebookName + } = req.body; + if (!appName) { + return res.status(400).json({ error: "appName required" }); } - const notebookPath = path.join(__dirname, '../snakeapi_service/notebooks', notebookName); - console.log('Resolved notebookPath:', notebookPath); - if (!fs.existsSync(notebookPath)) { - console.error('Notebook not found at:', notebookPath); - return res.status(500).json({ error: `Notebook not found: ${notebookPath}` }); - } + // const notebookPath = path.join(__dirname, '../snakeapi_service/notebooks', notebookName); + // console.log('Resolved notebookPath:', notebookPath); + // if (!fs.existsSync(notebookPath)) { + // console.error('Notebook not found at:', notebookPath); + // return res.status(500).json({ error: `Notebook not found: ${notebookPath}` }); + // } try { const fly = createFlyClient(); - console.log('Creating Fly app:', appName); - await fly.post('/apps', { + console.log("Creating Fly app:", appName); + await fly.post("/apps", { app_name: appName, org_slug: FLY_ORG, - primary_region: region + primary_region: "sea", }); - console.log('Uploading notebook to S3'); - const data = fs.readFileSync(notebookPath); - const key = `${appName}/notebooks/${Date.now()}-notebook.ipynb`; - console.log('S3 key:', key); - await s3.putObject({ - Bucket: COMMON_BUCKET, - Key: key, - Body: data, - ContentType: 'application/json' - }).promise(); + // console.log('Uploading notebook to S3'); + // const data = fs.readFileSync(notebookPath); + // const key = `${appName}/notebooks/${Date.now()}-notebook.ipynb`; + // console.log('S3 key:', key); + // await s3.putObject({ + // Bucket: COMMON_BUCKET, + // Key: key, + // Body: data, + // ContentType: 'application/json' + // }).promise(); - console.log('Creating machine'); + console.log("Creating machine"); const machineConfig = { name: `${appName}-machine`, - region: 'sea', + region: "sea", count: 1, - vm_size: 'shared-cpu-1x', + vm_size: "shared-cpu-1x", autostart: true, config: { image: IMAGE_REF, env: { INSTANCE_PREFIX: appName, - NOTEBOOK_KEY: key, + // NOTEBOOK_KEY: key, COMMON_BUCKET: COMMON_BUCKET, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_ENDPOINT_URL_S3, - AWS_REGION + AWS_REGION, }, http_service: { internal_port: 8000, force_https: true, - auto_stop_machines: 'stop', + auto_stop_machines: "stop", auto_start_machines: true, min_machines_running: 0, - processes: ['app'] + processes: ["app"], }, services: [ { - protocol: 'tcp', + protocol: "tcp", internal_port: 8000, ports: [ - { port: 443, handlers: ['tls', 'http'] }, - { port: 80, handlers: ['http'] } - ] - } + { port: 443, handlers: ["tls", "http"] }, + { port: 80, handlers: ["http"] }, + ], + }, ], guest: { memory_mb: 512, - cpu_kind: 'shared', - cpus: 1 - } - } + cpu_kind: "shared", + cpus: 1, + }, + }, }; - console.log('Machine config:', JSON.stringify(machineConfig, null, 2)); + console.log("Machine config:", JSON.stringify(machineConfig, null, 2)); await fly.post(`/apps/${appName}/machines`, machineConfig); - console.log('Allocating IPv4 via GraphQL API'); - const v4resp = await gqlClient.post('', { + console.log("Allocating IPv4 via GraphQL API"); + const v4resp = await gqlClient.post("", { query: ALLOCATE_IP_MUTATION, - variables: { input: { appId: appName, type: 'v4' } } + variables: { input: { appId: appName, type: "v4" } }, }); const ipv4 = v4resp.data.data.allocateIpAddress.ipAddress.address; - console.log('Allocated IPv4:', ipv4); + console.log("Allocated IPv4:", ipv4); - console.log('Allocating IPv6 via GraphQL API'); - const v6resp = await gqlClient.post('', { + console.log("Allocating IPv6 via GraphQL API"); + const v6resp = await gqlClient.post("", { query: ALLOCATE_IP_MUTATION, - variables: { input: { appId: appName, type: 'v6' } } + variables: { input: { appId: appName, type: "v6" } }, }); const ipv6 = v6resp.data.data.allocateIpAddress.ipAddress.address; - console.log('Allocated IPv6:', ipv6); + console.log("Allocated IPv6:", ipv6); return res.json({ - status: 'created', + status: "created", app: appName, ipv4, ipv6, url_v4: `http://${ipv4}`, - url_v6: `http://[${ipv6}]` + url_v6: `http://[${ipv6}]`, }); } catch (err) { - console.error('Deployment error:', err.response?.data || err.stack || err.message); + console.error( + "Deployment error:", + err.response?.data || err.stack || err.message + ); return res.status(500).json({ error: err.response?.data || err.message }); } }); // Upload notebook to S3 for an existing app -app.post('/:appName/upload', async (req, res) => { +app.post("/:appName/upload", async (req, res) => { const { appName } = req.params; const { notebookName, fileContentBase64 } = req.body; if (!notebookName || !fileContentBase64) { - return res.status(400).json({ error: 'notebookName and fileContentBase64 are required' }); + return res + .status(400) + .json({ error: "notebookName and fileContentBase64 are required" }); } try { - const buffer = Buffer.from(fileContentBase64, 'base64'); + const buffer = Buffer.from(fileContentBase64, "base64"); const key = `${appName}/notebooks/${notebookName}`; console.log(`Uploading notebook to: s3://${COMMON_BUCKET}/${key}`); - await s3.putObject({ - Bucket: COMMON_BUCKET, - Key: key, - Body: buffer, - ContentType: 'application/json' - }).promise(); + await s3 + .putObject({ + Bucket: COMMON_BUCKET, + Key: key, + Body: buffer, + ContentType: "application/json", + }) + .promise(); - return res.json({ status: 'uploaded', app: appName, key }); + return res.json({ status: "uploaded", app: appName, key }); } catch (err) { - console.error('Notebook upload error:', err); + console.error("Notebook upload error:", err); return res.status(500).json({ error: err.message }); } }); // Delete a Fly app -app.post('/:appName/delete', async (req, res) => { +app.post("/:appName/delete", async (req, res) => { const { appName } = req.params; try { const fly = createFlyClient(); - console.log('Destroying Fly app:', appName); + console.log("Destroying Fly app:", appName); await fly.delete(`/apps/${appName}`); - return res.json({ status: 'deleted', app: appName }); + return res.json({ status: "deleted", app: appName }); } catch (err) { - console.error('App deletion error:', err.response?.data || err.message); + console.error("App deletion error:", err.response?.data || err.message); return res.status(500).json({ error: err.response?.data || err.message }); } }); const LISTEN_PORT = process.env.PORT || 3006; -app.listen(LISTEN_PORT, '0.0.0.0', () => { +app.listen(LISTEN_PORT, "0.0.0.0", () => { console.log(`Deployment service listening on port ${LISTEN_PORT}`); }); From b2a6b3689bac2c46f723ef33fce7dbd336a6895e Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Mon, 5 May 2025 15:07:15 -0700 Subject: [PATCH 07/15] inserts appname and qrcodenumber in the DB --- assignment-db-service/app.js | 12 +- assignment-db-service/package-lock.json | 527 +++++++++++++++++++-- assignment-db-service/package.json | 2 +- assignment-db-service/prisma/schema.prisma | 7 +- 4 files changed, 512 insertions(+), 36 deletions(-) diff --git a/assignment-db-service/app.js b/assignment-db-service/app.js index 659a31f..9f43b2f 100644 --- a/assignment-db-service/app.js +++ b/assignment-db-service/app.js @@ -33,8 +33,9 @@ async function convertToAssignment(req) { programid, studentname, snakegameid, - originalfile, - editablefile, + appname, + qrcodenumber, + description, assignmenturl, password, instructorid @@ -47,8 +48,11 @@ async function convertToAssignment(req) { programid: parseInt(programid), studentname: studentname, snakegameid: snakegameid, - originalfile: originalfile, - editablefile: editablefile, + appname: appname, + qrcodenumber: parseInt(qrcodenumber), + description: description, + // originalfile: originalfile, + // editablefile: editablefile, assignmenturl: assignmenturl, passwordhash: hashPassword, instructorid: parseInt(instructorid), diff --git a/assignment-db-service/package-lock.json b/assignment-db-service/package-lock.json index d88c403..c8e5c33 100644 --- a/assignment-db-service/package-lock.json +++ b/assignment-db-service/package-lock.json @@ -9,12 +9,412 @@ "bcrypt": "^5.1.1", "express": "^5.1.0", "nodemon": "^3.1.9", - "prisma": "^6.1.0" + "prisma": "^6.7.0" }, "devDependencies": { "dotenv-cli": "^8.0.0" } }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.3.tgz", + "integrity": "sha512-W8bFfPA8DowP8l//sxjJLSLkD8iEjMc7cBVyP+u4cEv9sM7mdUCkgsj+t0n/BWPFtv7WWCN5Yzj0N6FJNUUqBQ==", + "cpu": [ + "ppc64" + ], + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.3.tgz", + "integrity": "sha512-PuwVXbnP87Tcff5I9ngV0lmiSu40xw1At6i3GsU77U7cjDDB4s0X2cyFuBiDa1SBk9DnvWwnGvVaGBqoFWPb7A==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.3.tgz", + "integrity": "sha512-XelR6MzjlZuBM4f5z2IQHK6LkK34Cvv6Rj2EntER3lwCBFdg6h2lKbtRjpTTsdEjD/WSe1q8UyPBXP1x3i/wYQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.3.tgz", + "integrity": "sha512-ogtTpYHT/g1GWS/zKM0cc/tIebFjm1F9Aw1boQ2Y0eUQ+J89d0jFY//s9ei9jVIlkYi8AfOjiixcLJSGNSOAdQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.3.tgz", + "integrity": "sha512-eESK5yfPNTqpAmDfFWNsOhmIOaQA59tAcF/EfYvo5/QWQCzXn5iUSOnqt3ra3UdzBv073ykTtmeLJZGt3HhA+w==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.3.tgz", + "integrity": "sha512-Kd8glo7sIZtwOLcPbW0yLpKmBNWMANZhrC1r6K++uDR2zyzb6AeOYtI6udbtabmQpFaxJ8uduXMAo1gs5ozz8A==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.3.tgz", + "integrity": "sha512-EJiyS70BYybOBpJth3M0KLOus0n+RRMKTYzhYhFeMwp7e/RaajXvP+BWlmEXNk6uk+KAu46j/kaQzr6au+JcIw==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.3.tgz", + "integrity": "sha512-Q+wSjaLpGxYf7zC0kL0nDlhsfuFkoN+EXrx2KSB33RhinWzejOd6AvgmP5JbkgXKmjhmpfgKZq24pneodYqE8Q==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.3.tgz", + "integrity": "sha512-dUOVmAUzuHy2ZOKIHIKHCm58HKzFqd+puLaS424h6I85GlSDRZIA5ycBixb3mFgM0Jdh+ZOSB6KptX30DD8YOQ==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.3.tgz", + "integrity": "sha512-xCUgnNYhRD5bb1C1nqrDV1PfkwgbswTTBRbAd8aH5PhYzikdf/ddtsYyMXFfGSsb/6t6QaPSzxtbfAZr9uox4A==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.3.tgz", + "integrity": "sha512-yplPOpczHOO4jTYKmuYuANI3WhvIPSVANGcNUeMlxH4twz/TeXuzEP41tGKNGWJjuMhotpGabeFYGAOU2ummBw==", + "cpu": [ + "ia32" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.3.tgz", + "integrity": "sha512-P4BLP5/fjyihmXCELRGrLd793q/lBtKMQl8ARGpDxgzgIKJDRJ/u4r1A/HgpBpKpKZelGct2PGI4T+axcedf6g==", + "cpu": [ + "loong64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.3.tgz", + "integrity": "sha512-eRAOV2ODpu6P5divMEMa26RRqb2yUoYsuQQOuFUexUoQndm4MdpXXDBbUoKIc0iPa4aCO7gIhtnYomkn2x+bag==", + "cpu": [ + "mips64el" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.3.tgz", + "integrity": "sha512-ZC4jV2p7VbzTlnl8nZKLcBkfzIf4Yad1SJM4ZMKYnJqZFD4rTI+pBG65u8ev4jk3/MPwY9DvGn50wi3uhdaghg==", + "cpu": [ + "ppc64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.3.tgz", + "integrity": "sha512-LDDODcFzNtECTrUUbVCs6j9/bDVqy7DDRsuIXJg6so+mFksgwG7ZVnTruYi5V+z3eE5y+BJZw7VvUadkbfg7QA==", + "cpu": [ + "riscv64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.3.tgz", + "integrity": "sha512-s+w/NOY2k0yC2p9SLen+ymflgcpRkvwwa02fqmAwhBRI3SC12uiS10edHHXlVWwfAagYSY5UpmT/zISXPMW3tQ==", + "cpu": [ + "s390x" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.3.tgz", + "integrity": "sha512-nQHDz4pXjSDC6UfOE1Fw9Q8d6GCAd9KdvMZpfVGWSJztYCarRgSDfOVBY5xwhQXseiyxapkiSJi/5/ja8mRFFA==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.3.tgz", + "integrity": "sha512-1QaLtOWq0mzK6tzzp0jRN3eccmN3hezey7mhLnzC6oNlJoUJz4nym5ZD7mDnS/LZQgkrhEbEiTn515lPeLpgWA==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.3.tgz", + "integrity": "sha512-i5Hm68HXHdgv8wkrt+10Bc50zM0/eonPb/a/OFVfB6Qvpiirco5gBA5bz7S2SHuU+Y4LWn/zehzNX14Sp4r27g==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.3.tgz", + "integrity": "sha512-zGAVApJEYTbOC6H/3QBr2mq3upG/LBEXr85/pTtKiv2IXcgKV0RT0QA/hSXZqSvLEpXeIxah7LczB4lkiYhTAQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.3.tgz", + "integrity": "sha512-fpqctI45NnCIDKBH5AXQBsD0NDPbEFczK98hk/aa6HJxbl+UtLkJV2+Bvy5hLSLk3LHmqt0NTkKNso1A9y1a4w==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.3.tgz", + "integrity": "sha512-ROJhm7d8bk9dMCUZjkS8fgzsPAZEjtRJqCAmVgB0gMrvG7hfmPmz9k1rwO4jSiblFjYmNvbECL9uhaPzONMfgA==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.3.tgz", + "integrity": "sha512-YWcow8peiHpNBiIXHwaswPnAXLsLVygFwCB3A7Bh5jRkIBFWHGmNQ48AlX4xDvQNoMZlPYzjVOQDYEzWCqufMQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.3.tgz", + "integrity": "sha512-qspTZOIGoXVS4DpNqUYUs9UxVb04khS1Degaw/MnfMe7goQ3lTfQ13Vw4qY/Nj0979BGvMRpAYbs/BAxEvU8ew==", + "cpu": [ + "ia32" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.3.tgz", + "integrity": "sha512-ICgUR+kPimx0vvRzf+N/7L7tVSQeE3BYY+NhHRHXS1kBuPO7z2+7ea2HbhDyZdTephgvNvKrlDDKUexuCVBVvg==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, "node_modules/@mapbox/node-pre-gyp": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.11.tgz", @@ -57,49 +457,59 @@ } } }, + "node_modules/@prisma/config": { + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/@prisma/config/-/config-6.7.0.tgz", + "integrity": "sha512-di8QDdvSz7DLUi3OOcCHSwxRNeW7jtGRUD2+Z3SdNE3A+pPiNT8WgUJoUyOwJmUr5t+JA2W15P78C/N+8RXrOA==", + "license": "Apache-2.0", + "dependencies": { + "esbuild": ">=0.12 <1", + "esbuild-register": "3.6.0" + } + }, "node_modules/@prisma/debug": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-6.1.0.tgz", - "integrity": "sha512-0himsvcM4DGBTtvXkd2Tggv6sl2JyUYLzEGXXleFY+7Kp6rZeSS3hiTW9mwtUlXrwYbJP6pwlVNB7jYElrjWUg==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-6.7.0.tgz", + "integrity": "sha512-RabHn9emKoYFsv99RLxvfG2GHzWk2ZI1BuVzqYtmMSIcuGboHY5uFt3Q3boOREM9de6z5s3bQoyKeWnq8Fz22w==", "license": "Apache-2.0" }, "node_modules/@prisma/engines": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-6.1.0.tgz", - "integrity": "sha512-GnYJbCiep3Vyr1P/415ReYrgJUjP79fBNc1wCo7NP6Eia0CzL2Ot9vK7Infczv3oK7JLrCcawOSAxFxNFsAERQ==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-6.7.0.tgz", + "integrity": "sha512-3wDMesnOxPrOsq++e5oKV9LmIiEazFTRFZrlULDQ8fxdub5w4NgRBoxtWbvXmj2nJVCnzuz6eFix3OhIqsZ1jw==", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { - "@prisma/debug": "6.1.0", - "@prisma/engines-version": "6.1.0-21.11f085a2012c0f4778414c8db2651556ee0ef959", - "@prisma/fetch-engine": "6.1.0", - "@prisma/get-platform": "6.1.0" + "@prisma/debug": "6.7.0", + "@prisma/engines-version": "6.7.0-36.3cff47a7f5d65c3ea74883f1d736e41d68ce91ed", + "@prisma/fetch-engine": "6.7.0", + "@prisma/get-platform": "6.7.0" } }, "node_modules/@prisma/engines-version": { - "version": "6.1.0-21.11f085a2012c0f4778414c8db2651556ee0ef959", - "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-6.1.0-21.11f085a2012c0f4778414c8db2651556ee0ef959.tgz", - "integrity": "sha512-PdJqmYM2Fd8K0weOOtQThWylwjsDlTig+8Pcg47/jszMuLL9iLIaygC3cjWJLda69siRW4STlCTMSgOjZzvKPQ==", + "version": "6.7.0-36.3cff47a7f5d65c3ea74883f1d736e41d68ce91ed", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-6.7.0-36.3cff47a7f5d65c3ea74883f1d736e41d68ce91ed.tgz", + "integrity": "sha512-EvpOFEWf1KkJpDsBCrih0kg3HdHuaCnXmMn7XFPObpFTzagK1N0Q0FMnYPsEhvARfANP5Ok11QyoTIRA2hgJTA==", "license": "Apache-2.0" }, "node_modules/@prisma/fetch-engine": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-6.1.0.tgz", - "integrity": "sha512-asdFi7TvPlEZ8CzSZ/+Du5wZ27q6OJbRSXh+S8ISZguu+S9KtS/gP7NeXceZyb1Jv1SM1S5YfiCv+STDsG6rrg==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-6.7.0.tgz", + "integrity": "sha512-zLlAGnrkmioPKJR4Yf7NfW3hftcvqeNNEHleMZK9yX7RZSkhmxacAYyfGsCcqRt47jiZ7RKdgE0Wh2fWnm7WsQ==", "license": "Apache-2.0", "dependencies": { - "@prisma/debug": "6.1.0", - "@prisma/engines-version": "6.1.0-21.11f085a2012c0f4778414c8db2651556ee0ef959", - "@prisma/get-platform": "6.1.0" + "@prisma/debug": "6.7.0", + "@prisma/engines-version": "6.7.0-36.3cff47a7f5d65c3ea74883f1d736e41d68ce91ed", + "@prisma/get-platform": "6.7.0" } }, "node_modules/@prisma/get-platform": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-6.1.0.tgz", - "integrity": "sha512-ia8bNjboBoHkmKGGaWtqtlgQOhCi7+f85aOkPJKgNwWvYrT6l78KgojLekE8zMhVk0R9lWcifV0Pf8l3/15V0Q==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-6.7.0.tgz", + "integrity": "sha512-i9IH5lO4fQwnMLvQLYNdgVh9TK3PuWBfQd7QLk/YurnAIg+VeADcZDbmhAi4XBBDD+hDif9hrKyASu0hbjwabw==", "license": "Apache-2.0", "dependencies": { - "@prisma/debug": "6.1.0" + "@prisma/debug": "6.7.0" } }, "node_modules/abbrev": { @@ -540,6 +950,58 @@ "node": ">= 0.4" } }, + "node_modules/esbuild": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.3.tgz", + "integrity": "sha512-qKA6Pvai73+M2FtftpNKRxJ78GIjmFXFxd/1DVBqGo/qNhLSfv+G12n9pNoWdytJC8U00TrViOwpjT0zgqQS8Q==", + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.25.3", + "@esbuild/android-arm": "0.25.3", + "@esbuild/android-arm64": "0.25.3", + "@esbuild/android-x64": "0.25.3", + "@esbuild/darwin-arm64": "0.25.3", + "@esbuild/darwin-x64": "0.25.3", + "@esbuild/freebsd-arm64": "0.25.3", + "@esbuild/freebsd-x64": "0.25.3", + "@esbuild/linux-arm": "0.25.3", + "@esbuild/linux-arm64": "0.25.3", + "@esbuild/linux-ia32": "0.25.3", + "@esbuild/linux-loong64": "0.25.3", + "@esbuild/linux-mips64el": "0.25.3", + "@esbuild/linux-ppc64": "0.25.3", + "@esbuild/linux-riscv64": "0.25.3", + "@esbuild/linux-s390x": "0.25.3", + "@esbuild/linux-x64": "0.25.3", + "@esbuild/netbsd-arm64": "0.25.3", + "@esbuild/netbsd-x64": "0.25.3", + "@esbuild/openbsd-arm64": "0.25.3", + "@esbuild/openbsd-x64": "0.25.3", + "@esbuild/sunos-x64": "0.25.3", + "@esbuild/win32-arm64": "0.25.3", + "@esbuild/win32-ia32": "0.25.3", + "@esbuild/win32-x64": "0.25.3" + } + }, + "node_modules/esbuild-register": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/esbuild-register/-/esbuild-register-3.6.0.tgz", + "integrity": "sha512-H2/S7Pm8a9CL1uhp9OvjwrBh5Pvx0H8qVOxNu8Wed9Y7qv56MPtq+GGM8RJpq6glYJn9Wspr8uw7l55uyinNeg==", + "license": "MIT", + "dependencies": { + "debug": "^4.3.4" + }, + "peerDependencies": { + "esbuild": ">=0.12 <1" + } + }, "node_modules/escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", @@ -1317,13 +1779,14 @@ } }, "node_modules/prisma": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/prisma/-/prisma-6.1.0.tgz", - "integrity": "sha512-aFI3Yi+ApUxkwCJJwyQSwpyzUX7YX3ihzuHNHOyv4GJg3X5tQsmRaJEnZ+ZyfHpMtnyahhmXVfbTZ+lS8ZtfKw==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-6.7.0.tgz", + "integrity": "sha512-vArg+4UqnQ13CVhc2WUosemwh6hr6cr6FY2uzDvCIFwH8pu8BXVv38PktoMLVjtX7sbYThxbnZF5YiR8sN2clw==", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { - "@prisma/engines": "6.1.0" + "@prisma/config": "6.7.0", + "@prisma/engines": "6.7.0" }, "bin": { "prisma": "build/index.js" @@ -1333,6 +1796,14 @@ }, "optionalDependencies": { "fsevents": "2.3.3" + }, + "peerDependencies": { + "typescript": ">=5.1.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } } }, "node_modules/proxy-addr": { diff --git a/assignment-db-service/package.json b/assignment-db-service/package.json index 6724b9c..f78b946 100644 --- a/assignment-db-service/package.json +++ b/assignment-db-service/package.json @@ -4,7 +4,7 @@ "bcrypt": "^5.1.1", "express": "^5.1.0", "nodemon": "^3.1.9", - "prisma": "^6.1.0" + "prisma": "^6.7.0" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", diff --git a/assignment-db-service/prisma/schema.prisma b/assignment-db-service/prisma/schema.prisma index 0a18c40..5cf5df5 100644 --- a/assignment-db-service/prisma/schema.prisma +++ b/assignment-db-service/prisma/schema.prisma @@ -14,9 +14,10 @@ model assignments { programid Int? studentname String? snakegameid String? - originalfile String? - editablefile String? - assignmenturl String? + qrcodenumber Int @unique + appname String @unique + description String? passwordhash String? // store bcrypt hash + assignmenturl String? instructorid Int? } From df8a9c843622cb1bac7e9b5b12a3269bc9a20bc5 Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Mon, 5 May 2025 18:49:15 -0700 Subject: [PATCH 08/15] converted verification and query(read) using qr code number --- assignment-db-service/app.js | 4 ++-- assignment-service/routes/StudentRouter.js | 18 +++++++++--------- assignment-service/server.js | 2 +- auth-service/.env.development | 2 +- auth-service/passport.js | 6 +++--- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/assignment-db-service/app.js b/assignment-db-service/app.js index 9f43b2f..f35f6d8 100644 --- a/assignment-db-service/app.js +++ b/assignment-db-service/app.js @@ -104,10 +104,10 @@ app.get("/assignments/instructor/:instructorId", async (req, res) => { }); // Read Assignment -app.get("/assignments/:id", async (req, res) => { +app.get("/assignments/:qrNumber", async (req, res) => { try { const assignment = await prisma.assignments.findUnique({ - where: { assignmentid: parseInt(req.params.id) }, + where: { qrcodenumber: parseInt(req.params.qrNumber) }, }); if (!assignment) { diff --git a/assignment-service/routes/StudentRouter.js b/assignment-service/routes/StudentRouter.js index d57339a..0107595 100644 --- a/assignment-service/routes/StudentRouter.js +++ b/assignment-service/routes/StudentRouter.js @@ -10,11 +10,11 @@ studentRouter.post("/save", (req, res) => {}); studentRouter.post("/deploy", (req, res) => {}); -studentRouter.get("/assignment/:id", (req, res) => { - const assignmentId = req.params.id; - console.log("Fetching details for assignmentId:", assignmentId); +studentRouter.get("/assignment/:qrnum", (req, res) => { + const qrnum = req.params.qrnum; + console.log("Fetching details for qr number:", qrnum); axios - .get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`) + .get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrnum}`) .then((response) => { console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); res.status(response.status).json(response.data); @@ -27,20 +27,20 @@ studentRouter.get("/assignment/:id", (req, res) => { studentRouter.post("/verify", async (req, res) => { try { - const assignmentId = req.body.assignmentId; + const qrNumber = req.body.qrNumber; const password = req.body.password; console.log("Received request to verify assignment."); console.log("Request body:", req.body); console.log( - "Accessing assignment with ID:", - assignmentId, + "Accessing assignment with QR Number:", + qrNumber, "and password:", password ); - console.log(`Fetching from URL: ${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`); + console.log(`Fetching from URL: ${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrNumber}`); const response = await axios.get( - `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}` + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrNumber}` ); console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); diff --git a/assignment-service/server.js b/assignment-service/server.js index b7918bd..7c408ee 100644 --- a/assignment-service/server.js +++ b/assignment-service/server.js @@ -71,4 +71,4 @@ app.get("/notebook/:appName", async (req, res) => { }); const port = process.env.NODE_PORT || 8080; -app.listen(port, "0.0.0.0", () => console.log(`Listening on 0.0.0.0:${port}...`)); +app.listen(port, "::", () => console.log(`Listening on :::${port}...`)); diff --git a/auth-service/.env.development b/auth-service/.env.development index e302c2f..5fd061d 100644 --- a/auth-service/.env.development +++ b/auth-service/.env.development @@ -5,7 +5,7 @@ GOOGLE_CLIENT_SECRET="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" GOOGLE_CALLBACK_URL="http://localhost:8080/auth/google/callback" LOGIN_REDIRECT_URL="http://localhost:5173/" ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 -ASSIGNMENT_SERVICE_URL="http://localhost:8082/" +ASSIGNMENT_SERVICE_URL="http://localhost:8082" DB_USER_SERVICE_URL="http://localhost:3100/" AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" PORT=8080 \ No newline at end of file diff --git a/auth-service/passport.js b/auth-service/passport.js index 8ef091d..c6b82f5 100644 --- a/auth-service/passport.js +++ b/auth-service/passport.js @@ -22,10 +22,10 @@ passport.use( passport.use( "student-auth", new CustomStrategy(async (req, done) => { - const { assignmentId, password } = req.body; + const { qrNumber, password } = req.body; console.log("Custom strategy invoked"); - console.log("Received assignmentId:", assignmentId); + console.log("Received qrNumber:", qrNumber); console.log("Received password:", password); try { @@ -33,7 +33,7 @@ passport.use( const response = await axios.post( `${process.env.ASSIGNMENT_SERVICE_URL}/student/verify`, { - assignmentId, + qrNumber, password, } ); From ad50756440773f58591669e215ed5382b6f592c9 Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Mon, 5 May 2025 19:27:08 -0700 Subject: [PATCH 09/15] updated passport to user qrcodenumber instead of assignment id in studen sessions --- auth-service/passport.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth-service/passport.js b/auth-service/passport.js index c6b82f5..84e05e3 100644 --- a/auth-service/passport.js +++ b/auth-service/passport.js @@ -60,7 +60,7 @@ passport.serializeUser((user, done) => { // done(null, user); console.log("Serializing user:", user); done(null, { - id: user.assignmentid || user.id, + id: user.qrcodenumber || user.id, displayName: user.studentname || user.displayName, role: user.role, emails: user.emails || "none", From 5a79b9970b1a0f7dec35c3e7f56f6c9439de8fdd Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Mon, 5 May 2025 22:21:24 -0700 Subject: [PATCH 10/15] added back-end call for edit --- assignment-db-service/app.js | 85 ++++++++++-- assignment-db-service/prisma/schema.prisma | 4 +- assignment-service/package-lock.json | 130 +++++++++++++++++- assignment-service/routes/InstructorRouter.js | 51 ++----- assignment-service/server.js | 2 +- 5 files changed, 209 insertions(+), 63 deletions(-) diff --git a/assignment-db-service/app.js b/assignment-db-service/app.js index f35f6d8..16699b8 100644 --- a/assignment-db-service/app.js +++ b/assignment-db-service/app.js @@ -28,6 +28,7 @@ async function encryptPassword(password) { //function to conver req.body to assignment async function convertToAssignment(req) { + console.log("Converting request body to assignment object..."); const { campid, programid, @@ -41,22 +42,39 @@ async function convertToAssignment(req) { instructorid } = req.body; + console.log("Request body fields:", { + campid, + programid, + studentname, + snakegameid, + appname, + qrcodenumber, + description, + assignmenturl, + password, + instructorid + }); + const hashPassword = await encryptPassword(req.body.password); - return { - campid: parseInt(campid), - programid: parseInt(programid), - studentname: studentname, - snakegameid: snakegameid, - appname: appname, - qrcodenumber: parseInt(qrcodenumber), - description: description, - // originalfile: originalfile, - // editablefile: editablefile, - assignmenturl: assignmenturl, - passwordhash: hashPassword, - instructorid: parseInt(instructorid), - }; + console.log("Password hash generated:", hashPassword); + + const assignment = { + campid: campid ? parseInt(campid) : null, + programid: programid ? parseInt(programid) : null, + studentname: studentname || null, + snakegameid: snakegameid || null, + appname: appname || null, + qrcodenumber: qrcodenumber ? parseInt(qrcodenumber) : null, + description: description || null, + assignmenturl: assignmenturl || null, + passwordhash: hashPassword || null, + instructorid: instructorid ? parseInt(instructorid) : null, + }; + + console.log("Converted assignment object:", assignment); + + return assignment; } // Create Assignment @@ -88,6 +106,7 @@ app.get("/assignments/instructor/:instructorId", async (req, res) => { console.log("InstructorID:", instructorId); const assignments = await prisma.assignments.findMany({ where: { instructorid: parseInt(instructorId) }, + orderBy: { assignmentid: 'asc' }, }); if (assignments.length === 0) { @@ -121,15 +140,51 @@ app.get("/assignments/:qrNumber", async (req, res) => { } }); +//get assignment by appname +app.get("/assignments/appname/:appName", async (req, res) => { + try { + const { appName } = req.params; + const assignments = await prisma.assignments.findMany({ + where: { appname: appName }, + }); + + if (assignments.length === 0) { + return res.status(404).json({ message: "No assignments found" }); + } + + res.json(assignments); + } catch (err) { + console.error("Error fetching assignments:", err.message); + res.status(500).json({ error: err.message }); + } +}); + // Update Assignment app.put("/assignments/:id", async (req, res) => { try { const { id } = req.params; const assignment = await convertToAssignment(req); + const existingAssignment = await prisma.assignments.findUnique({ + where: { assignmentid: parseInt(id) }, + }); + + if (!existingAssignment) { + return res.status(404).json({ message: "Assignment not found" }); + } + + // Update only the fields that are provided in the request body + Object.keys(assignment).forEach((key) => { + if (assignment[key]) { + existingAssignment[key] = assignment[key]; + } + }); + + console.log("Existing Assignment before update:", existingAssignment); + const updatedAssignment = await prisma.assignments.update({ where: { assignmentid: parseInt(id) }, - data: assignment, + data: existingAssignment, }); res.json({ diff --git a/assignment-db-service/prisma/schema.prisma b/assignment-db-service/prisma/schema.prisma index 5cf5df5..4d1a053 100644 --- a/assignment-db-service/prisma/schema.prisma +++ b/assignment-db-service/prisma/schema.prisma @@ -14,8 +14,8 @@ model assignments { programid Int? studentname String? snakegameid String? - qrcodenumber Int @unique - appname String @unique + qrcodenumber Int? @unique + appname String? @unique description String? passwordhash String? // store bcrypt hash assignmenturl String? diff --git a/assignment-service/package-lock.json b/assignment-service/package-lock.json index c14f56e..d8dba1c 100644 --- a/assignment-service/package-lock.json +++ b/assignment-service/package-lock.json @@ -160,6 +160,21 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", "license": "MIT" }, + "node_modules/available-typed-arrays": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", + "integrity": "sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==", + "license": "MIT", + "dependencies": { + "possible-typed-array-names": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/aws-sdk": { "version": "2.1692.0", "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1692.0.tgz", @@ -341,6 +356,24 @@ "node": ">= 0.8" } }, + "node_modules/call-bind": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.8.tgz", + "integrity": "sha512-oKlSFMcMwpUg2ednkhQ454wfWiU/ul3CkJe/PEHcTKuiX6RpbehUiFMXu13HalGZxfUwCQzZG747YXBn1im9ww==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.0", + "es-define-property": "^1.0.0", + "get-intrinsic": "^1.2.4", + "set-function-length": "^1.2.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/call-bind-apply-helpers": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", @@ -539,6 +572,23 @@ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "license": "MIT" }, + "node_modules/define-data-property": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", + "license": "MIT", + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -864,6 +914,21 @@ } } }, + "node_modules/for-each": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.5.tgz", + "integrity": "sha512-dKx12eRCVIzqCxFGplyFKJMPvLEWgmNtUrpTiJIR5u97zEhRG8ySrtboPHZXx7daLxQVrl643cTzbab2tkQjxg==", + "license": "MIT", + "dependencies": { + "is-callable": "^1.2.7" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/form-data": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz", @@ -1069,6 +1134,18 @@ "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", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", + "license": "MIT", + "dependencies": { + "es-define-property": "^1.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/has-symbols": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", @@ -1238,6 +1315,18 @@ "node": ">=8" } }, + "node_modules/is-callable": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", + "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -1819,6 +1908,15 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/possible-typed-array-names": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz", + "integrity": "sha512-/+5VFTchJDoVj3bhoqi6UeymcD00DAwb1nJwamzPvHEszJ4FpF6SNNbUbOS8yI56qHzdV8eK0qEfOSiodkTdxg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", @@ -2125,6 +2223,23 @@ "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==", "license": "ISC" }, + "node_modules/set-function-length": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", + "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", + "license": "MIT", + "dependencies": { + "define-data-property": "^1.1.4", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/setprototypeof": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", @@ -2502,8 +2617,19 @@ "integrity": "sha512-rEvr90Bck4WZt9HHFC4DJMsjvu7x+r6bImz0/BrbWb7A2djJ8hnZMrWnHo9F8ssv0OMErasDhftrfROTyqSDrw==", "license": "MIT", "dependencies": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" + "available-typed-arrays": "^1.0.7", + "call-bind": "^1.0.8", + "call-bound": "^1.0.4", + "for-each": "^0.3.5", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-tostringtag": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, "node_modules/wide-align": { diff --git a/assignment-service/routes/InstructorRouter.js b/assignment-service/routes/InstructorRouter.js index 9cd23d6..51d9394 100644 --- a/assignment-service/routes/InstructorRouter.js +++ b/assignment-service/routes/InstructorRouter.js @@ -4,27 +4,6 @@ const axios = require("axios"); const multer = require("multer"); const FormData = require("form-data"); -const fs = require('fs'); -const path = require('path'); -const AWS = require('aws-sdk'); - -// const { -// COMMON_BUCKET, -// AWS_ACCESS_KEY_ID, -// AWS_SECRET_ACCESS_KEY, -// AWS_ENDPOINT_URL_S3, -// AWS_REGION, -// } = process.env; - -// Log environment variables for debugging -// console.log('--- ENV START ---'); -// console.log('COMMON_BUCKET: ', COMMON_BUCKET); -// console.log('AWS_ACCESS_KEY_ID: ', AWS_ACCESS_KEY_ID ? '(found)' : '(NOT SET)'); -// console.log('AWS_SECRET_ACCESS_KEY:', AWS_SECRET_ACCESS_KEY ? '(found)' : '(NOT SET)'); -// console.log('AWS_ENDPOINT_URL_S3: ', AWS_ENDPOINT_URL_S3); -// console.log('AWS_REGION: ', AWS_REGION); -// console.log('--- ENV END ---'); - const DB_ASSIGNMENT_SERVICE_URL = process.env.DB_ASSIGNMENT_SERVICE_URL || "http://localhost:3000"; @@ -33,14 +12,6 @@ const DEPLOY_API_URL = process.env.DEPLOY_API_URL || "http://localhost:3600"; console.log("DB_ASSIGNMENT_SERVICE_URL:", DB_ASSIGNMENT_SERVICE_URL); console.log("DEPLOY_API_URL:", DEPLOY_API_URL); - -// const s3 = new AWS.S3({ -// endpoint: AWS_ENDPOINT_URL_S3, -// region: AWS_REGION, -// credentials: new AWS.Credentials(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY), -// s3ForcePathStyle: true -// }); - // Use memory storage to keep file in RAM const upload = multer({ storage: multer.memoryStorage() }); @@ -65,17 +36,6 @@ intructorRouter.post( ); console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); - // Upload the file to the S3 bucket - // console.log('Uploading notebook to S3'); - // const key = `${assignmentData.appname}/notebooks/${Date.now()}-notebook.ipynb`; - // console.log('S3 key:', key); - // await s3.putObject({ - // Bucket: COMMON_BUCKET, - // Key: key, - // Body: file.buffer, - // ContentType: 'application/json' - // }).promise(); - // call upload api to upload the file to S3 console.log("Uploading file to:", `${DEPLOY_API_URL}/${assignmentData.appname}/upload`); const uploadResponse = await axios.post(`${DEPLOY_API_URL}/${assignmentData.appname}/upload`, { @@ -126,12 +86,11 @@ intructorRouter.get( // if (req.isAuthenticated()) { try { const instructorId = req.params.id; - console.log("Fetching assignments for instructorId:", instructorId); - // const instructorId = req.user.userid; // Assuming req.user contains the authenticated user + // console.log("Fetching assignments for instructorId:", instructorId); const response = await axios.get( `${DB_ASSIGNMENT_SERVICE_URL}/assignments/instructor/${instructorId}` ); - console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); + // console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); res.status(response.status).json(response.data); } catch (error) { res.status(error.response?.status || 500).json({ error: error.message }); @@ -145,17 +104,23 @@ intructorRouter.get( // This endpoint is for instructors to update an assignment intructorRouter.put( "/update/:id", + upload.none(), // No file upload for this endpoint // passport.authenticate("jwt", { session: false }), async (req, res) => { try { const assignmentId = req.params.id; + console.log("Updating assignment with ID:", assignmentId); + console.log("Request body:", req.body); const response = await axios.put( `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`, req.body ); + + console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); res.status(response.status).json(response.data); } catch (error) { + console.error("Error updating assignment:", error.message); res.status(error.response?.status || 500).json({ error: error.message }); } } diff --git a/assignment-service/server.js b/assignment-service/server.js index 7c408ee..b20c3eb 100644 --- a/assignment-service/server.js +++ b/assignment-service/server.js @@ -71,4 +71,4 @@ app.get("/notebook/:appName", async (req, res) => { }); const port = process.env.NODE_PORT || 8080; -app.listen(port, "::", () => console.log(`Listening on :::${port}...`)); +app.listen({ port: port, host: '::', ipv6Only: false }, () => console.log(`Listening on ${port}...`)); From f003708282d1aecc9f8ba02d1852864f68bce501 Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Mon, 5 May 2025 23:37:54 -0700 Subject: [PATCH 11/15] added checking if appname and qrcode number already exist --- assignment-db-service/app.js | 6 ++- assignment-service/routes/InstructorRouter.js | 41 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/assignment-db-service/app.js b/assignment-db-service/app.js index 16699b8..053f556 100644 --- a/assignment-db-service/app.js +++ b/assignment-db-service/app.js @@ -125,14 +125,18 @@ app.get("/assignments/instructor/:instructorId", async (req, res) => { // Read Assignment app.get("/assignments/:qrNumber", async (req, res) => { try { - const assignment = await prisma.assignments.findUnique({ + console.log("Fetching assignment with QR Code Number:", req.params.qrNumber); + + const assignment = await prisma.assignments.findMany({ where: { qrcodenumber: parseInt(req.params.qrNumber) }, }); if (!assignment) { + console.log("No assignment found for QR Code Number:", req.params.qrNumber); return res.status(404).json({ message: "Assignment not found" }); } + console.log("Assignment found:", assignment); res.json(assignment); } catch (err) { console.error("Error fetching assignment:", err.message); diff --git a/assignment-service/routes/InstructorRouter.js b/assignment-service/routes/InstructorRouter.js index 51d9394..c897d86 100644 --- a/assignment-service/routes/InstructorRouter.js +++ b/assignment-service/routes/InstructorRouter.js @@ -143,4 +143,45 @@ intructorRouter.delete( } ); +//get assignment by appname +intructorRouter.get( + "/checkAssignmentByAppName/:appName", + // passport.authenticate("jwt", { session: false }), + async (req, res) => { + try { + const appName = req.params.appName; + console.log("Fetching assignment for appName:", appName); + const response = await axios.get( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/appname/${appName}` + ); + console.log("exists:", response.data.length > 0); + res.status(response.status).json({"exists": response.data.length > 0}); + } catch (error) { + console.error("Error fetching assignment by app name:", error.message); + res.status(error.response?.status || 500).json({ error: error.message }); + } + } +); + +//get assignment by qrcode number +intructorRouter.get( + "/checkAssignmentByQRCode/:qrcode", + // passport.authenticate("jwt", { session: false }), + async (req, res) => { + try { + const qrcode = req.params.qrcode; + console.log("Fetching assignment for qrcode:", qrcode); + const response = await axios.get( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrcode}` + ); + console.log("response:", response.data); + console.log("exists:", response.data.length > 0); + res.status(response.status).json({"exists": response.data.length > 0}); + } catch (error) { + console.error("Error fetching assignment by QR code:", error.message); + res.status(error.response?.status || 500).json({ error: error.message }); + } + } +); + module.exports = intructorRouter; From 7661e2daa2d256d3819898672bf3a0bfab4330c8 Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Mon, 5 May 2025 23:51:10 -0700 Subject: [PATCH 12/15] bug fix for qr code authentication --- assignment-service/routes/StudentRouter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assignment-service/routes/StudentRouter.js b/assignment-service/routes/StudentRouter.js index 0107595..5715f52 100644 --- a/assignment-service/routes/StudentRouter.js +++ b/assignment-service/routes/StudentRouter.js @@ -45,11 +45,11 @@ studentRouter.post("/verify", async (req, res) => { console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); console.log("Password provided:", password); - console.log("Password hash from database:", response.data.passwordhash); + console.log("Password hash from database:", response.data[0].passwordhash); const isPasswordValid = await bcrypt.compare( password, - response.data.passwordhash + response.data[0].passwordhash ); console.log("Password validation result:", isPasswordValid); From 3712fb332bdf7cc94a07a973b54e9ee5f96faf4e Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Mon, 5 May 2025 23:52:00 -0700 Subject: [PATCH 13/15] bug fix for qr code authentication --- assignment-service/routes/StudentRouter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignment-service/routes/StudentRouter.js b/assignment-service/routes/StudentRouter.js index 5715f52..edb1f57 100644 --- a/assignment-service/routes/StudentRouter.js +++ b/assignment-service/routes/StudentRouter.js @@ -49,7 +49,7 @@ studentRouter.post("/verify", async (req, res) => { const isPasswordValid = await bcrypt.compare( password, - response.data[0].passwordhash + response.data[0].passwordhash ); console.log("Password validation result:", isPasswordValid); From ee04a7e8efc657c248d2b1ee455bb5462ca4e9a4 Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Tue, 6 May 2025 10:43:48 -0700 Subject: [PATCH 14/15] bug fix for duplicate appname and qr code number --- assignment-db-service/app.js | 14 ++++++++------ assignment-service/routes/InstructorRouter.js | 9 ++++----- assignment-service/routes/StudentRouter.js | 4 ++-- auth-service/passport.js | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/assignment-db-service/app.js b/assignment-db-service/app.js index 053f556..61a7a37 100644 --- a/assignment-db-service/app.js +++ b/assignment-db-service/app.js @@ -127,7 +127,7 @@ app.get("/assignments/:qrNumber", async (req, res) => { try { console.log("Fetching assignment with QR Code Number:", req.params.qrNumber); - const assignment = await prisma.assignments.findMany({ + const assignment = await prisma.assignments.findUnique({ where: { qrcodenumber: parseInt(req.params.qrNumber) }, }); @@ -148,17 +148,19 @@ app.get("/assignments/:qrNumber", async (req, res) => { app.get("/assignments/appname/:appName", async (req, res) => { try { const { appName } = req.params; - const assignments = await prisma.assignments.findMany({ + const assignment = await prisma.assignments.findUnique({ where: { appname: appName }, }); - if (assignments.length === 0) { - return res.status(404).json({ message: "No assignments found" }); + if (!assignment) { + console.log("No assignment found for app name:", req.params.qrNumber); + return res.status(404).json({ message: "Assignment not found" }); } - res.json(assignments); + console.log("Assignment found:", assignment); + res.json(assignment); } catch (err) { - console.error("Error fetching assignments:", err.message); + console.error("Error fetching assignment:", err.message); res.status(500).json({ error: err.message }); } }); diff --git a/assignment-service/routes/InstructorRouter.js b/assignment-service/routes/InstructorRouter.js index c897d86..55af452 100644 --- a/assignment-service/routes/InstructorRouter.js +++ b/assignment-service/routes/InstructorRouter.js @@ -154,8 +154,8 @@ intructorRouter.get( const response = await axios.get( `${DB_ASSIGNMENT_SERVICE_URL}/assignments/appname/${appName}` ); - console.log("exists:", response.data.length > 0); - res.status(response.status).json({"exists": response.data.length > 0}); + console.log("Response data:", response.data); + res.status(response.status).json({"exists": (response.data !== null && response.data !== undefined)}); } catch (error) { console.error("Error fetching assignment by app name:", error.message); res.status(error.response?.status || 500).json({ error: error.message }); @@ -174,9 +174,8 @@ intructorRouter.get( const response = await axios.get( `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrcode}` ); - console.log("response:", response.data); - console.log("exists:", response.data.length > 0); - res.status(response.status).json({"exists": response.data.length > 0}); + console.log("Response data:", response.data); + res.status(response.status).json({"exists": (response.data !== null && response.data !== undefined)}); } catch (error) { console.error("Error fetching assignment by QR code:", error.message); res.status(error.response?.status || 500).json({ error: error.message }); diff --git a/assignment-service/routes/StudentRouter.js b/assignment-service/routes/StudentRouter.js index edb1f57..80f9f79 100644 --- a/assignment-service/routes/StudentRouter.js +++ b/assignment-service/routes/StudentRouter.js @@ -45,11 +45,11 @@ studentRouter.post("/verify", async (req, res) => { console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); console.log("Password provided:", password); - console.log("Password hash from database:", response.data[0].passwordhash); + console.log("Password hash from database:", response.data.passwordhash); const isPasswordValid = await bcrypt.compare( password, - response.data[0].passwordhash + response.data.passwordhash ); console.log("Password validation result:", isPasswordValid); diff --git a/auth-service/passport.js b/auth-service/passport.js index 84e05e3..e04adb9 100644 --- a/auth-service/passport.js +++ b/auth-service/passport.js @@ -60,7 +60,7 @@ passport.serializeUser((user, done) => { // done(null, user); console.log("Serializing user:", user); done(null, { - id: user.qrcodenumber || user.id, + userId: user.qrcodenumber || user.id, displayName: user.studentname || user.displayName, role: user.role, emails: user.emails || "none", From fd993102a0a9f46f9785d1988d78f9276d17524a Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Tue, 6 May 2025 13:28:01 -0700 Subject: [PATCH 15/15] fixed editor bug --- assignment-db-service/app.js | 28 +++++++++++++++++-- assignment-service/routes/InstructorRouter.js | 26 +++++++++++++++++ assignment-service/routes/StudentRouter.js | 4 +-- auth-service/.env | 2 +- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/assignment-db-service/app.js b/assignment-db-service/app.js index 61a7a37..91d19be 100644 --- a/assignment-db-service/app.js +++ b/assignment-db-service/app.js @@ -122,8 +122,31 @@ app.get("/assignments/instructor/:instructorId", async (req, res) => { } }); -// Read Assignment -app.get("/assignments/:qrNumber", async (req, res) => { +//Get assignment by assignmentid +app.get("/assignments/:id", async (req, res) => { + try { + const { id } = req.params; + console.log("Fetching assignment with ID:", id); + + const assignment = await prisma.assignments.findUnique({ + where: { assignmentid: parseInt(id) }, + }); + + if (!assignment) { + console.log("No assignment found for ID:", id); + return res.status(404).json({ message: "Assignment not found" }); + } + + console.log("Assignment found:", assignment); + res.json(assignment); + } catch (err) { + console.error("Error fetching assignment:", err.message); + res.status(500).json({ error: err.message }); + } +}); + +// Get Assignment by QR Code Number +app.get("/assignments/qr/:qrNumber", async (req, res) => { try { console.log("Fetching assignment with QR Code Number:", req.params.qrNumber); @@ -222,3 +245,4 @@ app.delete("/assignments/:id", async (req, res) => { app.listen(port, () => { console.log(`Server running at http://localhost:${port}`); }); + diff --git a/assignment-service/routes/InstructorRouter.js b/assignment-service/routes/InstructorRouter.js index 55af452..22777ca 100644 --- a/assignment-service/routes/InstructorRouter.js +++ b/assignment-service/routes/InstructorRouter.js @@ -132,7 +132,33 @@ intructorRouter.delete( // passport.authenticate("jwt", { session: false }), async (req, res) => { try { + const assignmentId = req.params.id; + + //get the assignment data from the database + console.log("Fetching assignment data for ID:", assignmentId); + const assignmentResponse = await axios.get( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}` + ); + const assignmentData = assignmentResponse.data; + console.log("Assignment data:", assignmentData); + + if (!assignmentData) { + return res.status(404).json({ error: "Assignment not found" }); + } + + // Delete the Battlesnake API + console.log('Deploying a new Battlesnake API'); + console.log("DEPLOY_API_URL:", DEPLOY_API_URL, assignmentData.appname); + const deployResponse = await axios.post(`${DEPLOY_API_URL}/${assignmentData.appname}/delete`, { + "appName": assignmentData.appname + }); + //throw error if the response is not 200 + if (deployResponse.status !== 200) { + throw new Error(`Failed to delete Battlesnake API: ${deployResponse.statusText}`); + } + console.log('Response from DEPLOY_API_URL:', deployResponse.data); + const response = await axios.delete( `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}` ); diff --git a/assignment-service/routes/StudentRouter.js b/assignment-service/routes/StudentRouter.js index 80f9f79..947820c 100644 --- a/assignment-service/routes/StudentRouter.js +++ b/assignment-service/routes/StudentRouter.js @@ -14,7 +14,7 @@ studentRouter.get("/assignment/:qrnum", (req, res) => { const qrnum = req.params.qrnum; console.log("Fetching details for qr number:", qrnum); axios - .get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrnum}`) + .get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/qr/${qrnum}`) .then((response) => { console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); res.status(response.status).json(response.data); @@ -40,7 +40,7 @@ studentRouter.post("/verify", async (req, res) => { console.log(`Fetching from URL: ${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrNumber}`); const response = await axios.get( - `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${qrNumber}` + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/qr/${qrNumber}` ); console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); diff --git a/auth-service/.env b/auth-service/.env index a5e74f3..75d4e76 100644 --- a/auth-service/.env +++ b/auth-service/.env @@ -2,7 +2,7 @@ GOOGLE_CLIENT_ID = "485880105639-1in8tvb6ondnn198rasuj2d8ank06ntp.apps.googleuse GOOGLE_CLIENT_SECRET = "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" GOOGLE_CALLBACK_URL = "https://byte-camp-auth-service.fly.dev/auth/google/callback" LOGIN_REDIRECT_URL = "https://bytecamp-web.fly.dev/" -ACCEPTED_ORIGINS ="https://bytecamp-web.fly.dev,https://byte-camp-auth-service.fly.dev" +ACCEPTED_ORIGINS ="https://bytecamp-web.fly.dev,https://byte-camp-auth-service.fly.dev,http://localhost:5173" #DB_USER_SERVICE_URL = "http://localhost:3000/" DB_USER_SERVICE_URL = "http://db-user-service.internal:3000/" AUTH_SESSION_KEY = "f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42"