From b6135191b53119cf9609099dcb5fcf923a2507e4 Mon Sep 17 00:00:00 2001 From: Kaj Forney Date: Sat, 29 Apr 2023 23:15:37 -0600 Subject: [PATCH] PA 7 (DELETE). --- css/main.css | 27 +++- delete.html | 310 ++++++++++++++++++++++++++++++++++++++++++ insert.html | 4 +- server/index.js | 31 ++++- server/model/games.js | 14 +- 5 files changed, 375 insertions(+), 11 deletions(-) create mode 100644 delete.html diff --git a/css/main.css b/css/main.css index f4c93df..b9a9641 100644 --- a/css/main.css +++ b/css/main.css @@ -156,16 +156,39 @@ input, select, textarea { box-shadow: #000000 3px 3px 5px; } +#deleteButton { + border-radius: 5px; + border:0; + min-width: 150px; + min-height: 50px; + background-image: linear-gradient(#c51210, #5c1210); + color: #ffffff; +} + +#deleteButton:hover { + background-image: linear-gradient(#e53333, #d51210); + box-shadow: #000000 3px 3px 5px; +} + #successMessage { background-color: #4c6b22; color: #b3d4fc; - min-height: 50px; + min-height: 30px; } #errorMessage { background-color: darkred; color: #b3d4fc; - min-height: 50px; + min-height: 30px; +} + +.warning { + background-color: darkred; + color: #b3d4fc; + min-height: 30px; + font-weight: bolder; + font-size: 24px; + text-align: center; } .tableCoverArt { diff --git a/delete.html b/delete.html new file mode 100644 index 0000000..72f63d8 --- /dev/null +++ b/delete.html @@ -0,0 +1,310 @@ + + + + + + Delete Game + + + + + + + + + + + + + + + + +
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+

Are you SURE you want to delete this game?

+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+
+ Windows + +
+
+ MacOS + +
+
+ Linux + +
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ + +
+ + + + + + + + + + + diff --git a/insert.html b/insert.html index 638f17f..84edebb 100644 --- a/insert.html +++ b/insert.html @@ -293,8 +293,8 @@ .then(({status, json}) => { if (status === 200) { let message = "Game submission successful!" - document.getElementById('outputMessage').hidden = false; - document.getElementById('outputMessage').innerHTML = message; + document.getElementById('successMessage').hidden = false; + document.getElementById('successMessage').innerHTML = message; } }) .catch(error => { diff --git a/server/index.js b/server/index.js index 81e93ac..265ac25 100644 --- a/server/index.js +++ b/server/index.js @@ -156,7 +156,7 @@ app.post('/games', upload.single('coverArt'), async (request, response) => { console.log(request.file); const errors = validationResult(request); - if(!errors.isEmpty()) { + if (!errors.isEmpty()) { return response .status(400) .setHeader('Access-Control-Allow-Origin', '*') //Prevent CORS error @@ -184,13 +184,13 @@ app.post('/games', upload.single('coverArt'), app.post('/developers', upload.none(), check('name', 'You must enter a name.').isLength({min: 3}), - check('description', 'You must enter a description').isLength({min:5}), + check('description', 'You must enter a description').isLength({min: 5}), check('homepage', 'You must enter a homepage URL.').isURL(), async (request, response) => { const errors = validationResult(request); - if(!errors.isEmpty()) { + if (!errors.isEmpty()) { return response .status(400) .setHeader('Access-Control-Allow-Origin', '*') //Prevent CORS error @@ -218,13 +218,13 @@ app.post('/developers', upload.none(), app.post('/publishers', upload.none(), check('name', 'You must enter a name.').isLength({min: 3}), - check('description', 'You must enter a description').isLength({min:5}), + check('description', 'You must enter a description').isLength({min: 5}), check('homepage', 'You must enter a homepage URL.').isURL(), async (request, response) => { const errors = validationResult(request); - if(!errors.isEmpty()) { + if (!errors.isEmpty()) { return response .status(400) .setHeader('Access-Control-Allow-Origin', '*') //Prevent CORS error @@ -270,7 +270,7 @@ app.put('/games/:id', upload.single('coverArt'), async (request, response) => { const errors = validationResult(request); - if(!errors.isEmpty()) { + if (!errors.isEmpty()) { return response .status(400) .setHeader('Access-Control-Allow-Origin', '*') //Prevent CORS error @@ -296,6 +296,25 @@ app.put('/games/:id', upload.single('coverArt'), } }); +app.delete('/games/:id', upload.none(), + + async (request, response) => { + let result = {}; + try { + result = await games.deleteGame(request.query.id); + } catch (error) { + console.log(error); + return response + .status(500) //Error code when something goes wrong with the server + .setHeader('Access-Control-Allow-Origin', '*') //Prevent CORS error + .json({message: 'Something went wrong with the server.'}); + } + response + .setHeader('Access-Control-Allow-Origin', '*') //Prevent CORS error + .json({message: 'Game deleted successfully!'}); + + }); + app.listen(port, () => { console.log(`Application listening at http://localhost:${port}`); }) diff --git a/server/model/games.js b/server/model/games.js index c93dfb5..8388150 100644 --- a/server/model/games.js +++ b/server/model/games.js @@ -1,5 +1,6 @@ const connection = require('./connection'); const parseText = require('./parseText'); +const {del} = require("express/lib/application"); async function getAllGames(parameters = {}) { let selectSql = `SELECT @@ -186,9 +187,20 @@ async function editGame(id, formInput, imagePath) { return await connection.query(updateSql, queryParameters); } +async function deleteGame(id) { + + let deleteSql = `DELETE FROM games_master_table + WHERE id =` + id; + + console.log(deleteSql); + + return await connection.query(deleteSql); +} + module.exports = { getAllGames, getGame, addNewGame, - editGame + editGame, + deleteGame }