From 581440c508da1f6b52a4606dcc1dd970868c589d Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Wed, 24 Feb 2021 18:46:43 -0500 Subject: [PATCH 01/20] first commit --- data/schema.sql | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/data/schema.sql b/data/schema.sql index e69de29..1e80f7b 100644 --- a/data/schema.sql +++ b/data/schema.sql @@ -0,0 +1,21 @@ + +CREATE TABLE IF NOT EXISTS pokemon ( + pokemonID INT PRIMARY KEY, + pokemonName VARCHAR(128), + sprite VARCHAR(128) +); + + +CREATE TABLE IF NOT EXISTS pokeType ( + typeID INT PRIMARY KEY, + pokemonType VARCHAR (128) +); + + +CREATE TABLE IF NOT EXISTS mapType ( + mappingID INT, + pokemonID INT, + typeID INT, + FOREIGN KEY (pokemonID) REFERENCES pokemon (pokemonID), + FOREIGN KEY (typeID) REFERENCES pokeType (typeID) +); \ No newline at end of file From 9b6c1938d7bca6c8b0d37077ea91db22bbe9f7ab Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Wed, 24 Feb 2021 19:11:50 -0500 Subject: [PATCH 02/20] Added Bulbasaur data --- data/schema.sql | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/data/schema.sql b/data/schema.sql index 1e80f7b..7ab16f2 100644 --- a/data/schema.sql +++ b/data/schema.sql @@ -18,4 +18,22 @@ CREATE TABLE IF NOT EXISTS mapType ( typeID INT, FOREIGN KEY (pokemonID) REFERENCES pokemon (pokemonID), FOREIGN KEY (typeID) REFERENCES pokeType (typeID) -); \ No newline at end of file +); + +INSERT INTO + pokemon ( + pokemonID, + pokemonName, + sprite + ) +VALUES + ( + "1", + "Bulbasaur", + "https://www.https://www.google.com/imgres?imgurl=https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fen%2F2%2F28%2FPok%25C3%25A9mon_Bulbasaur_art.png&imgrefurl=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FBulbasaur&tbnid=KtgjmFXIcd8sVM&vet=12ahUKEwjh5ZKN34PvAhX5lXIEHXNuABQQMygAegUIARDlAQ..i&docid=dDlg1E6hw6SY6M&w=275&h=256&q=image%20bulbasaur&ved=2ahUKEwjh5ZKN34PvAhX5lXIEHXNuABQQMygAegUIARDlAQ#imgrc=KtgjmFXIcd8sVM&imgdii=7QuAFbKQuiFkrM" + ); + +INSERT INTO + types (typeID, pokemonType) +VALUES + ("1", "grass"); \ No newline at end of file From 7249dbb76ea8c19dde5c329dc40d9e67bc5ee226 Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Wed, 24 Feb 2021 19:30:07 -0500 Subject: [PATCH 03/20] Add use/drop database --- data/schema.sql | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/data/schema.sql b/data/schema.sql index 7ab16f2..4edcc1d 100644 --- a/data/schema.sql +++ b/data/schema.sql @@ -1,8 +1,12 @@ +DROP DATABASE IF EXISTS Pokedex; +CREATE DATABASE Pokedex; + +USE Pokedex; CREATE TABLE IF NOT EXISTS pokemon ( pokemonID INT PRIMARY KEY, pokemonName VARCHAR(128), - sprite VARCHAR(128) + sprite TEXT(65535) ); @@ -34,6 +38,6 @@ VALUES ); INSERT INTO - types (typeID, pokemonType) + pokeType (typeID, pokemonType) VALUES ("1", "grass"); \ No newline at end of file From 13e48689f286400873a7477380ad3a0caeee25e9 Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Sun, 28 Feb 2021 20:42:41 -0500 Subject: [PATCH 04/20] Initial commit --- .vscode/settings.json | 3 + main.js | 21 ++ package-lock.json | 746 +++++++++++++++++++++++++++++++++++++++++- package.json | 6 +- rest/index.js | 159 ++++++++- web/index.html | 7 +- web/index.js | 44 +++ web/style.css | 30 ++ 8 files changed, 1005 insertions(+), 11 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 main.js create mode 100644 web/index.js create mode 100644 web/style.css diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6f3a291 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..b9429d8 --- /dev/null +++ b/main.js @@ -0,0 +1,21 @@ +let mysql = require("mysql"); + +let con = mysql.createConnection({ + host:"localhost", + user: "root", + password: "KillEric5050", + database: "Pokedex" +}) + +con.connect(err => { + if(err){ + throw err; + } + con.query("SELECT * FROM pokemon", (err, result, fields) =>{ + if(err){ + throw err; + } + console.log(result) + + }) +}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 1fca92a..5d66e24 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,8 +1,642 @@ { "name": "pokedex-app", "version": "1.0.0", - "lockfileVersion": 1, + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "name": "pokedex-app", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "axios": "^0.21.1", + "cors": "^2.8.5", + "express": "^4.17.1", + "mysql": "^2.18.1", + "pokedex-promise-v2": "^3.3.0" + } + }, + "node_modules/accepts": { + "version": "1.3.7", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", + "integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==", + "dependencies": { + "mime-types": "~2.1.24", + "negotiator": "0.6.2" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" + }, + "node_modules/axios": { + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", + "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", + "dependencies": { + "follow-redirects": "^1.10.0" + } + }, + "node_modules/bignumber.js": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", + "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==", + "engines": { + "node": "*" + } + }, + "node_modules/body-parser": { + "version": "1.19.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", + "integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==", + "dependencies": { + "bytes": "3.1.0", + "content-type": "~1.0.4", + "debug": "2.6.9", + "depd": "~1.1.2", + "http-errors": "1.7.2", + "iconv-lite": "0.4.24", + "on-finished": "~2.3.0", + "qs": "6.7.0", + "raw-body": "2.4.0", + "type-is": "~1.6.17" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/bytes": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", + "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/content-disposition": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz", + "integrity": "sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==", + "dependencies": { + "safe-buffer": "5.1.2" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", + "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz", + "integrity": "sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" + }, + "node_modules/core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/depd": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", + "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/destroy": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", + "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" + }, + "node_modules/encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "4.17.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", + "integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==", + "dependencies": { + "accepts": "~1.3.7", + "array-flatten": "1.1.1", + "body-parser": "1.19.0", + "content-disposition": "0.5.3", + "content-type": "~1.0.4", + "cookie": "0.4.0", + "cookie-signature": "1.0.6", + "debug": "2.6.9", + "depd": "~1.1.2", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "~1.1.2", + "fresh": "0.5.2", + "merge-descriptors": "1.0.1", + "methods": "~1.1.2", + "on-finished": "~2.3.0", + "parseurl": "~1.3.3", + "path-to-regexp": "0.1.7", + "proxy-addr": "~2.0.5", + "qs": "6.7.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.1.2", + "send": "0.17.1", + "serve-static": "1.14.1", + "setprototypeof": "1.1.1", + "statuses": "~1.5.0", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.10.0" + } + }, + "node_modules/finalhandler": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", + "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", + "dependencies": { + "debug": "2.6.9", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "on-finished": "~2.3.0", + "parseurl": "~1.3.3", + "statuses": "~1.5.0", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/follow-redirects": { + "version": "1.13.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.2.tgz", + "integrity": "sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/forwarded": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", + "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/http-errors": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz", + "integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==", + "dependencies": { + "depd": "~1.1.2", + "inherits": "2.0.3", + "setprototypeof": "1.1.1", + "statuses": ">= 1.5.0 < 2", + "toidentifier": "1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/memory-cache": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/memory-cache/-/memory-cache-0.2.0.tgz", + "integrity": "sha1-eJCwHVLADI68nVM+H46xfjA0hxo=" + }, + "node_modules/merge-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", + "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/mime-db": { + "version": "1.45.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.45.0.tgz", + "integrity": "sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.28", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.28.tgz", + "integrity": "sha512-0TO2yJ5YHYr7M2zzT7gDU1tbwHxEUWBCLt0lscSNpcdAfFyJOVEpRYNS7EXVcTLNj/25QO8gulHC5JtTzSE2UQ==", + "dependencies": { + "mime-db": "1.45.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "node_modules/mysql": { + "version": "2.18.1", + "resolved": "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz", + "integrity": "sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig==", + "dependencies": { + "bignumber.js": "9.0.0", + "readable-stream": "2.3.7", + "safe-buffer": "5.1.2", + "sqlstring": "2.3.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/negotiator": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", + "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/p-map": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/p-map/-/p-map-2.1.0.tgz", + "integrity": "sha512-y3b8Kpd8OAN444hxfBbFfj1FY/RjtTd8tzYwhUqNYXx0fXx2iX4maP4Qr6qhIKbQXI02wTLAda4fYUbDagTUFw==", + "engines": { + "node": ">=6" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", + "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" + }, + "node_modules/pokedex-promise-v2": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/pokedex-promise-v2/-/pokedex-promise-v2-3.3.0.tgz", + "integrity": "sha512-OV18zzr/ThQBEUgLlcUUwxntpOUYGR3wAi9f7DwFVPsaEUWhxnmdyoYxRbhfzeYoXT2UMlzZewPkjiEKfaNvOA==", + "dependencies": { + "axios": "^0.21.0", + "memory-cache": "^0.2.0", + "p-map": "^2.1.0" + }, + "engines": { + "node": ">=7.6" + } + }, + "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==" + }, + "node_modules/proxy-addr": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz", + "integrity": "sha512-dh/frvCBVmSsDYzw6n926jv974gddhkFPfiN8hPOi30Wax25QZyZEGveluCgliBnqmuM+UJmBErbAUFIoDbjOw==", + "dependencies": { + "forwarded": "~0.1.2", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/qs": { + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", + "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.0.tgz", + "integrity": "sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q==", + "dependencies": { + "bytes": "3.1.0", + "http-errors": "1.7.2", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "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/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==" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "node_modules/send": { + "version": "0.17.1", + "resolved": "https://registry.npmjs.org/send/-/send-0.17.1.tgz", + "integrity": "sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg==", + "dependencies": { + "debug": "2.6.9", + "depd": "~1.1.2", + "destroy": "~1.0.4", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "0.5.2", + "http-errors": "~1.7.2", + "mime": "1.6.0", + "ms": "2.1.1", + "on-finished": "~2.3.0", + "range-parser": "~1.2.1", + "statuses": "~1.5.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", + "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" + }, + "node_modules/serve-static": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.1.tgz", + "integrity": "sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg==", + "dependencies": { + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "0.17.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/setprototypeof": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", + "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" + }, + "node_modules/sqlstring": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz", + "integrity": "sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A=", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/statuses": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", + "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=", + "engines": { + "node": ">= 0.6" + } + }, + "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==", + "dependencies": { + "safe-buffer": "~5.1.0" + } + }, + "node_modules/toidentifier": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", + "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==", + "engines": { + "node": ">=0.6" + } + }, + "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==", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=", + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=", + "engines": { + "node": ">= 0.8" + } + } + }, "dependencies": { "accepts": { "version": "1.3.7", @@ -18,6 +652,19 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" }, + "axios": { + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", + "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", + "requires": { + "follow-redirects": "^1.10.0" + } + }, + "bignumber.js": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", + "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==" + }, "body-parser": { "version": "1.19.0", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", @@ -63,6 +710,20 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + }, + "cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "requires": { + "object-assign": "^4", + "vary": "^1" + } + }, "debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -152,6 +813,11 @@ "unpipe": "~1.0.0" } }, + "follow-redirects": { + "version": "1.13.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.2.tgz", + "integrity": "sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA==" + }, "forwarded": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", @@ -192,11 +858,21 @@ "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" }, + "memory-cache": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/memory-cache/-/memory-cache-0.2.0.tgz", + "integrity": "sha1-eJCwHVLADI68nVM+H46xfjA0hxo=" + }, "merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", @@ -230,11 +906,27 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, + "mysql": { + "version": "2.18.1", + "resolved": "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz", + "integrity": "sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig==", + "requires": { + "bignumber.js": "9.0.0", + "readable-stream": "2.3.7", + "safe-buffer": "5.1.2", + "sqlstring": "2.3.1" + } + }, "negotiator": { "version": "0.6.2", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", @@ -243,6 +935,11 @@ "ee-first": "1.1.1" } }, + "p-map": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/p-map/-/p-map-2.1.0.tgz", + "integrity": "sha512-y3b8Kpd8OAN444hxfBbFfj1FY/RjtTd8tzYwhUqNYXx0fXx2iX4maP4Qr6qhIKbQXI02wTLAda4fYUbDagTUFw==" + }, "parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", @@ -253,6 +950,21 @@ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" }, + "pokedex-promise-v2": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/pokedex-promise-v2/-/pokedex-promise-v2-3.3.0.tgz", + "integrity": "sha512-OV18zzr/ThQBEUgLlcUUwxntpOUYGR3wAi9f7DwFVPsaEUWhxnmdyoYxRbhfzeYoXT2UMlzZewPkjiEKfaNvOA==", + "requires": { + "axios": "^0.21.0", + "memory-cache": "^0.2.0", + "p-map": "^2.1.0" + } + }, + "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==" + }, "proxy-addr": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz", @@ -283,6 +995,20 @@ "unpipe": "1.0.0" } }, + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "requires": { + "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" + } + }, "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", @@ -336,11 +1062,24 @@ "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" }, + "sqlstring": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz", + "integrity": "sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A=" + }, "statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" }, + "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==", + "requires": { + "safe-buffer": "~5.1.0" + } + }, "toidentifier": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", @@ -360,6 +1099,11 @@ "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, "utils-merge": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", diff --git a/package.json b/package.json index 944e450..0f7a4f2 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,10 @@ }, "homepage": "https://github.com/code-differently/Pokedex-App#readme", "dependencies": { - "express": "^4.17.1" + "axios": "^0.21.1", + "cors": "^2.8.5", + "express": "^4.17.1", + "mysql": "^2.18.1", + "pokedex-promise-v2": "^3.3.0" } } diff --git a/rest/index.js b/rest/index.js index bba5463..8522a29 100644 --- a/rest/index.js +++ b/rest/index.js @@ -1,11 +1,156 @@ const express = require('express') -const app = express() -const port = 3000 +const axios = require('axios'); +const cors = require("cors") +var Pokedex = require('pokedex-promise-v2'); +let mysql = require("mysql"); +const { response } = require('express'); +var P = new Pokedex(); -app.get('/', (req, res) => { - res.send('Hello World!') -}) +const app = express(); +const port = 3000; + +app.set('view engine', 'pug'); +app.use(cors()); + +let pokemon; + +class Pokemon { + constructor(name, id, img, type) { + this.name = name; + this.id = id; + this.img = img; + this.type = type; + } +} + +let pokedex = []; +let pokeman; + +let db = "Pokedex"; +let con = mysql.createConnection({ + host:"localhost", + user: "root", + password: "KillEric5050" +}); + + + if (!con) { + con.connect (function(err) { + if (err) throw err; + console.log("-------------------------------------------------------------Connected to MySQL Database"); + }); + } else { + console.log("----------------------------------------------------------Already Connected to MySQL Database"); + } + + + let sql1 = "DROP DATABASE IF EXISTS Pokedex"; + con.query(sql1, function (err, result) { + if (err) throw err; + console.log("DROP DATABASE= " + result); + }); + + + let sql2 = "CREATE DATABASE IF NOT EXISTS Pokedex"; + con.query(sql2, function (err, result) { + if (err) throw err; + console.log("CREATE DATABASE= " + result); + }); + + + let sql3 = "CREATE TABLE IF NOT EXISTS pokemon (id INT NOT NULL PRIMARY KEY, pokeName VARCHAR(128), img TEXT(65535), pokeType VARCHAR(32))"; + con.query('CREATE DATABASE IF NOT EXISTS ??', db, function(err, results) { + if (err) { + console.log('error in creating database', err); + return; + } + + console.log('created a new database'); + + con.changeUser({ + database : db + }, function(err) { + if (err) { + console.log('error in changing database', err); + return; + } + + con.query(sql3, function(err) { + if (err) { + console.log('error in creating tables', err); + return; + } + + console.log('created a new table'); + }); + }); + }); + + + + +app.get('/', async (req, res) => { + + var interval = { + limit: 151, + offset: 0 + } + + //select list of 5 pokemon, with their names and urls + //loop through each one's url to + //then access the rest of its data + //create an instance of the pokemon class + //fill it with the data from second API call + //push that instance object to an array + //loop restarts + + P.getPokemonsList(interval) // with Promise + .then(function(response) { + for ( let i = 0 ; i < response.results.length ; i++ ) { + + P.resource([response.results[i].url]) // with Promise + .then(function(response) { + pokeman = response.map(data => ( + { + name: data.name, + id: data.id, + img: data.sprites["front_default"], + type: data.types[0].type.name + } + )) + // console.log("Pokemon[0].name = "+ pokeman[0].name); + // //console.log(typeof(pokeman[0].id)); + // console.log("Pokemon[0].data.id = " + pokeman[0].id); + // console.log("Pokemon[0].data.sprite = " + pokeman[0].img); + // console.log("Pokemon[0].data.types[0].type.name = " + pokeman[0].type); + + + + pokedex.push(pokeman); + let sql4 = `INSERT IGNORE INTO pokemon (id, pokeName, img, pokeType) VALUES ("${pokeman[0].id}", "${pokeman[0].name}", "${pokeman[0].img}", "${pokeman[0].type}")`; + con.query(sql4, function (err, result) { + if (err) throw err; + console.log("INSERT INTO pokemon = " + result); + + }); + con.query ("SELECT * FROM pokemon", function (err, result, fields) { + if (err) throw err; + console.log("SELECT"); + }); + return; + + }).catch(function(error) { + console.log('There was an ERROR: ', error); + }) + } + res.send( pokedex ); + + }).catch(function(error) { + console.log('There was an ERROR: ', error); + }); +}); app.listen(port, () => { - console.log(`Example app listening at http://localhost:${port}`) -}) \ No newline at end of file + console.log(`Example app listening at https://localhost:${port}`) +}); + diff --git a/web/index.html b/web/index.html index 1de928b..727787a 100644 --- a/web/index.html +++ b/web/index.html @@ -3,9 +3,12 @@ - Document + Pokedex + -

Hello Pokemon!

+
+
+ \ No newline at end of file diff --git a/web/index.js b/web/index.js new file mode 100644 index 0000000..dd34af4 --- /dev/null +++ b/web/index.js @@ -0,0 +1,44 @@ +const colors = [ + ["normal", "#A8A77A"], + ["fire", "#EE8130"], + ["water", "#6390F0"], + ["electric", "#F7D02C"], + ["grass", "#7AC74C"], + ["ice", "#96D9D6"], + ["fighting", "#C22E28"], + ["poison", "#A33EA1"], + ["ground", "#E2BF65"], + ["flying", "#A98FF3"], + ["psychic", "#F94487"], + ["bug", "#A6B91A"], + ["rock", "#BA136"], + ["ghost", "#735797"], + ["dragon", "#6F35FC"], + ["dark", "#705746"], + ["steel", "#B7B7CE"], + ["fairy", "#D685AD"] + ] +let cardType; +let xhr = new XMLHttpRequest(); +xhr.open("GET", "http://localhost:3000/") + +xhr.onreadystatechange = function(){ + if(this.readyState === 4 && this.status === 200){ + + let data = JSON.parse(this.responseText); + for ( let i = 0 ; i < data.length ; i++ ) { + for ( let j = 0 ; j < colors.length; j++) { + if (colors[j][0] === data[i][0].type) { + cardType = colors[j][1]; } + } + document.getElementById('container').innerHTML += ` +
+

${data[i][0].name}, #${data[i][0].id}

+ +
+ `; + } + } +} + +xhr.send(); \ No newline at end of file diff --git a/web/style.css b/web/style.css new file mode 100644 index 0000000..18024f2 --- /dev/null +++ b/web/style.css @@ -0,0 +1,30 @@ +body { + font-family: sans-serif, 'Segoe-UI'; + font-size: 16px; +} + +#container { + display: flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: center; +} + +.card { + max-width: 600px; + color: aliceblue; + background-color:coral; + border: 1px solid aliceblue; + border-radius: 5px; + padding: 2em; +} + +img { + margin: auto; + width: 60%; +} + +h1 { + text-align: center; + +} \ No newline at end of file From 9f7241aff79c4d21fd097ff0208cbed33fa3c34d Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Sun, 28 Feb 2021 20:44:53 -0500 Subject: [PATCH 05/20] Added Insert Ignore --- rest/index.js | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/rest/index.js b/rest/index.js index 8522a29..c208a68 100644 --- a/rest/index.js +++ b/rest/index.js @@ -33,7 +33,7 @@ let con = mysql.createConnection({ password: "KillEric5050" }); - +// If connection doesn't exist, connect to database, else already connected if (!con) { con.connect (function(err) { if (err) throw err; @@ -43,30 +43,29 @@ let con = mysql.createConnection({ console.log("----------------------------------------------------------Already Connected to MySQL Database"); } - + // Drop database if it exists let sql1 = "DROP DATABASE IF EXISTS Pokedex"; con.query(sql1, function (err, result) { if (err) throw err; console.log("DROP DATABASE= " + result); }); - + // Create database if it doesn't exist let sql2 = "CREATE DATABASE IF NOT EXISTS Pokedex"; con.query(sql2, function (err, result) { if (err) throw err; console.log("CREATE DATABASE= " + result); }); - + // Create table in database referencing the database let sql3 = "CREATE TABLE IF NOT EXISTS pokemon (id INT NOT NULL PRIMARY KEY, pokeName VARCHAR(128), img TEXT(65535), pokeType VARCHAR(32))"; + // Reference the database to create table in con.query('CREATE DATABASE IF NOT EXISTS ??', db, function(err, results) { if (err) { console.log('error in creating database', err); return; } - console.log('created a new database'); - con.changeUser({ database : db }, function(err) { @@ -74,13 +73,11 @@ let con = mysql.createConnection({ console.log('error in changing database', err); return; } - con.query(sql3, function(err) { if (err) { console.log('error in creating tables', err); return; } - console.log('created a new table'); }); }); @@ -118,14 +115,6 @@ app.get('/', async (req, res) => { type: data.types[0].type.name } )) - // console.log("Pokemon[0].name = "+ pokeman[0].name); - // //console.log(typeof(pokeman[0].id)); - // console.log("Pokemon[0].data.id = " + pokeman[0].id); - // console.log("Pokemon[0].data.sprite = " + pokeman[0].img); - // console.log("Pokemon[0].data.types[0].type.name = " + pokeman[0].type); - - - pokedex.push(pokeman); let sql4 = `INSERT IGNORE INTO pokemon (id, pokeName, img, pokeType) VALUES ("${pokeman[0].id}", "${pokeman[0].name}", "${pokeman[0].img}", "${pokeman[0].type}")`; con.query(sql4, function (err, result) { From 019d0ead3895c755a178d3db865e10a531322020 Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Sun, 28 Feb 2021 20:55:11 -0500 Subject: [PATCH 06/20] Add comments --- rest/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/rest/index.js b/rest/index.js index c208a68..32bef8a 100644 --- a/rest/index.js +++ b/rest/index.js @@ -116,6 +116,7 @@ app.get('/', async (req, res) => { } )) pokedex.push(pokeman); + // Add pokemon to database one by one. Use IGNORE to avoid adding duplicates let sql4 = `INSERT IGNORE INTO pokemon (id, pokeName, img, pokeType) VALUES ("${pokeman[0].id}", "${pokeman[0].name}", "${pokeman[0].img}", "${pokeman[0].type}")`; con.query(sql4, function (err, result) { if (err) throw err; From 50761e92ccd0324dbb534194fbbe6a6e75d199ab Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Sun, 28 Feb 2021 21:40:48 -0500 Subject: [PATCH 07/20] Initial commit --- rest/index.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/rest/index.js b/rest/index.js index 32bef8a..3793d58 100644 --- a/rest/index.js +++ b/rest/index.js @@ -30,7 +30,7 @@ let db = "Pokedex"; let con = mysql.createConnection({ host:"localhost", user: "root", - password: "KillEric5050" + password: "password" }); // If connection doesn't exist, connect to database, else already connected @@ -115,18 +115,13 @@ app.get('/', async (req, res) => { type: data.types[0].type.name } )) - pokedex.push(pokeman); // Add pokemon to database one by one. Use IGNORE to avoid adding duplicates let sql4 = `INSERT IGNORE INTO pokemon (id, pokeName, img, pokeType) VALUES ("${pokeman[0].id}", "${pokeman[0].name}", "${pokeman[0].img}", "${pokeman[0].type}")`; con.query(sql4, function (err, result) { if (err) throw err; console.log("INSERT INTO pokemon = " + result); - - }); - con.query ("SELECT * FROM pokemon", function (err, result, fields) { - if (err) throw err; - console.log("SELECT"); }); + pokedex.push(pokeman); return; }).catch(function(error) { From c33ba5673007aea8142ed308e08cf2bf9b803d49 Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Mon, 1 Mar 2021 10:58:42 -0500 Subject: [PATCH 08/20] added code to fix create table error --- rest/index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rest/index.js b/rest/index.js index 3793d58..55a49a1 100644 --- a/rest/index.js +++ b/rest/index.js @@ -30,7 +30,7 @@ let db = "Pokedex"; let con = mysql.createConnection({ host:"localhost", user: "root", - password: "password" + password: "KillEric5050" }); // If connection doesn't exist, connect to database, else already connected @@ -50,12 +50,12 @@ let con = mysql.createConnection({ console.log("DROP DATABASE= " + result); }); - // Create database if it doesn't exist - let sql2 = "CREATE DATABASE IF NOT EXISTS Pokedex"; - con.query(sql2, function (err, result) { - if (err) throw err; - console.log("CREATE DATABASE= " + result); - }); + // // Create database if it doesn't exist + // let sql2 = "CREATE DATABASE IF NOT EXISTS Pokedex"; + // con.query(sql2, function (err, result) { + // if (err) throw err; + // console.log("CREATE DATABASE= " + result); + // }); // Create table in database referencing the database let sql3 = "CREATE TABLE IF NOT EXISTS pokemon (id INT NOT NULL PRIMARY KEY, pokeName VARCHAR(128), img TEXT(65535), pokeType VARCHAR(32))"; From 88dee7f4b04dba3812c11c7277fb7312eaa0d174 Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Mon, 1 Mar 2021 11:22:48 -0500 Subject: [PATCH 09/20] Update index.js --- rest/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest/index.js b/rest/index.js index 55a49a1..d6a8f24 100644 --- a/rest/index.js +++ b/rest/index.js @@ -30,7 +30,7 @@ let db = "Pokedex"; let con = mysql.createConnection({ host:"localhost", user: "root", - password: "KillEric5050" + password: "password" }); // If connection doesn't exist, connect to database, else already connected From a2db50f7c418d20b47109ae679a82974ea0c50ff Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Mon, 1 Mar 2021 11:25:46 -0500 Subject: [PATCH 10/20] Update main.js --- main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index b9429d8..00c3051 100644 --- a/main.js +++ b/main.js @@ -3,7 +3,7 @@ let mysql = require("mysql"); let con = mysql.createConnection({ host:"localhost", user: "root", - password: "KillEric5050", + password: "password", database: "Pokedex" }) @@ -18,4 +18,4 @@ con.connect(err => { console.log(result) }) -}); \ No newline at end of file +}); From 3df135a44a419fed17e7ff77162dda006f8259eb Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Thu, 4 Mar 2021 00:25:13 -0500 Subject: [PATCH 11/20] get data from database --- rest/index.js | 150 ++++++++--------------------------------- rest/loading-script.js | 141 ++++++++++++++++++++++++++++++++++++++ web/index.html | 11 ++- web/script.js | 13 ++++ 4 files changed, 186 insertions(+), 129 deletions(-) create mode 100644 rest/loading-script.js create mode 100644 web/script.js diff --git a/rest/index.js b/rest/index.js index d6a8f24..5fd17db 100644 --- a/rest/index.js +++ b/rest/index.js @@ -1,141 +1,45 @@ -const express = require('express') -const axios = require('axios'); -const cors = require("cors") -var Pokedex = require('pokedex-promise-v2'); -let mysql = require("mysql"); -const { response } = require('express'); -var P = new Pokedex(); +const express = require("express"); +let mysql = require("mysql"); const app = express(); const port = 3000; -app.set('view engine', 'pug'); -app.use(cors()); +app.get("/", (req, res) => { + res.send("Hello World"); +}); -let pokemon; +app.get("/customers", async(req, res) => { + let customerData = await getCustomerData(); + res.send(customerData); +}); -class Pokemon { - constructor(name, id, img, type) { - this.name = name; - this.id = id; - this.img = img; - this.type = type; - } -} +app.get("/pokemon", async(req, res) => { + let pokemonData = await getPokemonData(); + res.send(pokemonData); +}); -let pokedex = []; -let pokeman; +app.listen(port, () => { + console.log(`Example app listening at https://localhost:${port}`) +}); + +async function getPokemonData() { -let db = "Pokedex"; let con = mysql.createConnection({ host:"localhost", user: "root", - password: "password" + password: "", + database:"Pokedex" }); -// If connection doesn't exist, connect to database, else already connected - if (!con) { - con.connect (function(err) { - if (err) throw err; - console.log("-------------------------------------------------------------Connected to MySQL Database"); - }); - } else { - console.log("----------------------------------------------------------Already Connected to MySQL Database"); - } - - // Drop database if it exists - let sql1 = "DROP DATABASE IF EXISTS Pokedex"; - con.query(sql1, function (err, result) { - if (err) throw err; - console.log("DROP DATABASE= " + result); - }); - - // // Create database if it doesn't exist - // let sql2 = "CREATE DATABASE IF NOT EXISTS Pokedex"; - // con.query(sql2, function (err, result) { - // if (err) throw err; - // console.log("CREATE DATABASE= " + result); - // }); - - // Create table in database referencing the database - let sql3 = "CREATE TABLE IF NOT EXISTS pokemon (id INT NOT NULL PRIMARY KEY, pokeName VARCHAR(128), img TEXT(65535), pokeType VARCHAR(32))"; - // Reference the database to create table in - con.query('CREATE DATABASE IF NOT EXISTS ??', db, function(err, results) { - if (err) { - console.log('error in creating database', err); - return; - } - console.log('created a new database'); - con.changeUser({ - database : db - }, function(err) { - if (err) { - console.log('error in changing database', err); - return; - } - con.query(sql3, function(err) { - if (err) { - console.log('error in creating tables', err); - return; - } - console.log('created a new table'); - }); - }); +let data = await new Promise((resolve, reject )=> { + con.query("SELECT * FROM pokemon", (err, result, fields) => { + (err) ? reject(err) : resolve(result); }); +}); + con.end(); + return data; +} -app.get('/', async (req, res) => { - - var interval = { - limit: 151, - offset: 0 - } - - //select list of 5 pokemon, with their names and urls - //loop through each one's url to - //then access the rest of its data - //create an instance of the pokemon class - //fill it with the data from second API call - //push that instance object to an array - //loop restarts - - P.getPokemonsList(interval) // with Promise - .then(function(response) { - for ( let i = 0 ; i < response.results.length ; i++ ) { - - P.resource([response.results[i].url]) // with Promise - .then(function(response) { - pokeman = response.map(data => ( - { - name: data.name, - id: data.id, - img: data.sprites["front_default"], - type: data.types[0].type.name - } - )) - // Add pokemon to database one by one. Use IGNORE to avoid adding duplicates - let sql4 = `INSERT IGNORE INTO pokemon (id, pokeName, img, pokeType) VALUES ("${pokeman[0].id}", "${pokeman[0].name}", "${pokeman[0].img}", "${pokeman[0].type}")`; - con.query(sql4, function (err, result) { - if (err) throw err; - console.log("INSERT INTO pokemon = " + result); - }); - pokedex.push(pokeman); - return; - - }).catch(function(error) { - console.log('There was an ERROR: ', error); - }) - } - res.send( pokedex ); - - }).catch(function(error) { - console.log('There was an ERROR: ', error); - }); -}); - -app.listen(port, () => { - console.log(`Example app listening at https://localhost:${port}`) -}); - diff --git a/rest/loading-script.js b/rest/loading-script.js new file mode 100644 index 0000000..d2b3132 --- /dev/null +++ b/rest/loading-script.js @@ -0,0 +1,141 @@ +const express = require('express') +const axios = require('axios'); +const cors = require("cors") +var Pokedex = require('pokedex-promise-v2'); +let mysql = require("mysql"); +const { response } = require('express'); +var P = new Pokedex(); + +const app = express(); +const port = 3000; + +app.set('view engine', 'pug'); +app.use(cors()); + +let pokemon; + +class Pokemon { + constructor(name, id, img, type) { + this.name = name; + this.id = id; + this.img = img; + this.type = type; + } +} + +let pokedex = []; +let pokeman; + +let db = "Pokedex"; +let con = mysql.createConnection({ + host:"localhost", + user: "root", + password: "", + database: "Pokedex" +}); + +// If connection doesn't exist, connect to database, else already connected + if (!con) { + con.connect (function(err) { + if (err) throw err; + console.log("-------------------------------------------------------------Connected to MySQL Database"); + }); + } else { + console.log("----------------------------------------------------------Already Connected to MySQL Database"); + } + + // Drop database if it exists + let sql1 = "DROP DATABASE IF EXISTS Pokedex"; + con.query(sql1, function (err, result) { + if (err) throw err; + console.log("DROP DATABASE= " + result); + }); + + // Create database if it doesn't exist + let sql2 = "CREATE DATABASE IF NOT EXISTS Pokedex"; + con.query(sql2, function (err, result) { + if (err) throw err; + console.log("CREATE DATABASE= " + result); + }); + + // Create table in database referencing the database + let sql3 = "CREATE TABLE IF NOT EXISTS pokemon (id INT NOT NULL PRIMARY KEY, pokeName VARCHAR(128), img TEXT(65535), pokeType VARCHAR(32))"; + // Reference the database to create table in + con.query('CREATE DATABASE IF NOT EXISTS ??', db, function(err, results) { + if (err) { + console.log('error in creating database', err); + return; + } + console.log('created a new database'); + con.changeUser({ + database : db + }, function(err) { + if (err) { + console.log('error in changing database', err); + return; + } + con.query(sql3, function(err) { + if (err) { + console.log('error in creating tables', err); + return; + } + console.log('created a new table'); + }); + }); + }); + + + + +app.get('/', async (req, res) => { + + var interval = { + limit: 151, + offset: 0 + } + + //select list of 5 pokemon, with their names and urls + //loop through each one's url to + //then access the rest of its data + //create an instance of the pokemon class + //fill it with the data from second API call + //push that instance object to an array + //loop restarts + + P.getPokemonsList(interval) // with Promise + .then(function(response) { + for ( let i = 0 ; i < response.results.length ; i++ ) { + + P.resource([response.results[i].url]) // with Promise + .then(function(response) { + pokeman = response.map(data => ( + { + name: data.name, + id: data.id, + img: data.sprites["front_default"], + type: data.types[0].type.name + } + )) + // Add pokemon to database one by one. Use IGNORE to avoid adding duplicates + let sql4 = `INSERT IGNORE INTO pokemon (id, pokeName, img, pokeType) VALUES ("${pokeman[0].id}", "${pokeman[0].name}", "${pokeman[0].img}", "${pokeman[0].type}")`; + con.query(sql4, function (err, result) { + if (err) throw err; + console.log("INSERT INTO pokemon = " + result); + }); + pokedex.push(pokeman); + return; + + }).catch(function(error) { + console.log('There was an ERROR: ', error); + }) + } + res.send( pokedex ); + + }).catch(function(error) { + console.log('There was an ERROR: ', error); + }); +}); + +app.listen(port, () => { + console.log(`Example app listening at https://localhost:${port}`) +}); \ No newline at end of file diff --git a/web/index.html b/web/index.html index 727787a..43d6faf 100644 --- a/web/index.html +++ b/web/index.html @@ -3,12 +3,11 @@ - Pokedex - + Document + -
-
- +

Hello Pokemon!

+ - \ No newline at end of file + diff --git a/web/script.js b/web/script.js new file mode 100644 index 0000000..98e61d3 --- /dev/null +++ b/web/script.js @@ -0,0 +1,13 @@ +fetch("http://localhost:3000/pokeman") + .then(response => response.json()) + .then (console.log("IN SCRIPT.JS FILE")) + .then (pokemon => { + pokemon.map(pokemon => `
${pokemon.name} ${pokemon.id}
`).join("") + }) + + + + + + + \ No newline at end of file From 67f0248a39542f36288a19aac532c413b0b9a517 Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Thu, 4 Mar 2021 00:42:47 -0500 Subject: [PATCH 12/20] add div --- web/index.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web/index.html b/web/index.html index 43d6faf..613c514 100644 --- a/web/index.html +++ b/web/index.html @@ -4,10 +4,11 @@ Document +

Hello Pokemon!

- +
From c1c9f86158bfb5977c372c115a51a39af9edbe70 Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Wed, 17 Mar 2021 10:36:37 -0400 Subject: [PATCH 13/20] added class --- web/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/web/index.js b/web/index.js index dd34af4..31cf44a 100644 --- a/web/index.js +++ b/web/index.js @@ -41,4 +41,13 @@ xhr.onreadystatechange = function(){ } } -xhr.send(); \ No newline at end of file +xhr.send(); + + + // const renderData = (data) => { + // document.getElementById("pokemon").innerHTML = data.map(getHtml).join(""); + // } + + // const getHtml = ({pokeName, id, img, pokeType}) => { + // return `

${pokeName}, ${id}, ${pokeType}

` + // } \ No newline at end of file From 25747f29086906b19dc74bdb35ee930e3e69ec94 Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Wed, 17 Mar 2021 10:37:38 -0400 Subject: [PATCH 14/20] added bootstrap --- web/script.js | 52 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/web/script.js b/web/script.js index 98e61d3..e0614c6 100644 --- a/web/script.js +++ b/web/script.js @@ -1,13 +1,53 @@ -fetch("http://localhost:3000/pokeman") +const typeMapping = { + "normal": "#A8A77A", + "fire": "#EE8130", + "water": "#6390F0", + "electric": "#F7D02C", + "grass": "#7AC74C", + "ice": "#96D9D6", + "fighting": "#C22E28", + "poison": "#A33EA1", + "ground": "#E2BF65", + "flying": "#A98FF3", + "psychic": "#F94487", + "bug": "#A6B91A", + "rock": "#BA136", + "ghost": "#735797", + "dragon": "#6F35FC", + "dark": "#705746", + "steel": "#B7B7CE", + "fairy": "#D685AD" +} + +function renderAll() { + fetch("http://localhost:3000/pokemon") .then(response => response.json()) - .then (console.log("IN SCRIPT.JS FILE")) - .then (pokemon => { - pokemon.map(pokemon => `
${pokemon.name} ${pokemon.id}
`).join("") + .catch(error => { + console.log(error); }) + .then(data => { + document.getElementsByClassName("grid")[0].innerHTML = renderData(data); + }); +} +function renderData(data) { + const html = data.map(pokemon => + + `
+

+ ${adjustName(pokemon.name)} +
#${pokemon.id}
+

+ +
` + ).join(""); + return html +} +function adjustName(name) { + return name[0].toUpperCase() + name.substring(1, name.length); +} +renderAll() - - \ No newline at end of file From 344cdb56f88e66082f90466e118b2163e0bd8ba5 Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Wed, 17 Mar 2021 10:38:15 -0400 Subject: [PATCH 15/20] added bootstrap --- web/index.html | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/web/index.html b/web/index.html index 613c514..0609d5c 100644 --- a/web/index.html +++ b/web/index.html @@ -1,14 +1,20 @@ - - - - Document - + + + + Pokemon + + + - -

Hello Pokemon!

-
- + +

Pokedex

+
+ + + + + From b6d12aabf300ff991f64177c7b0025bacc7bf2e4 Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Wed, 17 Mar 2021 10:38:59 -0400 Subject: [PATCH 16/20] added --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 0f7a4f2..bca7672 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "cors": "^2.8.5", "express": "^4.17.1", "mysql": "^2.18.1", + "node-fetch": "^2.6.1", "pokedex-promise-v2": "^3.3.0" } } From 6e5b2806d5486fe6182cfbffc42babc0b6b1b2ef Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Wed, 17 Mar 2021 10:40:30 -0400 Subject: [PATCH 17/20] changed schema to 3 tables --- data/schema.sql | 59 +++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/data/schema.sql b/data/schema.sql index 4edcc1d..12ebe37 100644 --- a/data/schema.sql +++ b/data/schema.sql @@ -1,43 +1,24 @@ -DROP DATABASE IF EXISTS Pokedex; -CREATE DATABASE Pokedex; +drop database pokedex2; +create database pokedex2; +use pokedex2; -USE Pokedex; -CREATE TABLE IF NOT EXISTS pokemon ( - pokemonID INT PRIMARY KEY, - pokemonName VARCHAR(128), - sprite TEXT(65535) +drop table if exists pokemon; +CREATE TABLE pokemon( +id INT PRIMARY KEY NOT NULL, +img varchar(256), +name varchar(50) ); - - -CREATE TABLE IF NOT EXISTS pokeType ( - typeID INT PRIMARY KEY, - pokemonType VARCHAR (128) +drop table if exists type; +CREATE TABLE type ( +id INT PRIMARY KEY NOT NULL, +name varchar(50) ); - - -CREATE TABLE IF NOT EXISTS mapType ( - mappingID INT, - pokemonID INT, - typeID INT, - FOREIGN KEY (pokemonID) REFERENCES pokemon (pokemonID), - FOREIGN KEY (typeID) REFERENCES pokeType (typeID) -); - -INSERT INTO - pokemon ( - pokemonID, - pokemonName, - sprite - ) -VALUES - ( - "1", - "Bulbasaur", - "https://www.https://www.google.com/imgres?imgurl=https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fen%2F2%2F28%2FPok%25C3%25A9mon_Bulbasaur_art.png&imgrefurl=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FBulbasaur&tbnid=KtgjmFXIcd8sVM&vet=12ahUKEwjh5ZKN34PvAhX5lXIEHXNuABQQMygAegUIARDlAQ..i&docid=dDlg1E6hw6SY6M&w=275&h=256&q=image%20bulbasaur&ved=2ahUKEwjh5ZKN34PvAhX5lXIEHXNuABQQMygAegUIARDlAQ#imgrc=KtgjmFXIcd8sVM&imgdii=7QuAFbKQuiFkrM" - ); - -INSERT INTO - pokeType (typeID, pokemonType) -VALUES - ("1", "grass"); \ No newline at end of file +drop table if exists pokemon_type; +CREATE TABLE pokemon_type ( +id INT PRIMARY KEY NOT NULL auto_increment, +pokemonId INT NOT NULL, +FOREIGN KEY (pokemonId) REFERENCES pokemon(id), +typeId INT NOT NULL, +FOREIGN KEY (typeId) REFERENCES type(id) +); \ No newline at end of file From 8078c49c226e53e1a401a8129bc91e93ad40471d Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Wed, 17 Mar 2021 10:41:58 -0400 Subject: [PATCH 18/20] commented out call to API -- need to add new file --- rest/index.js | 112 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 82 insertions(+), 30 deletions(-) diff --git a/rest/index.js b/rest/index.js index 5fd17db..01cc15d 100644 --- a/rest/index.js +++ b/rest/index.js @@ -1,45 +1,97 @@ +const password = "KillEric5050"; + + + + + + +const express = require('express'); +const mysql = require("mysql"); +const cors = require("cors"); +const axios = require('axios'); -const express = require("express"); -let mysql = require("mysql"); const app = express(); const port = 3000; -app.get("/", (req, res) => { - res.send("Hello World"); -}); - -app.get("/customers", async(req, res) => { - let customerData = await getCustomerData(); - res.send(customerData); -}); +app.use(cors()); -app.get("/pokemon", async(req, res) => { - let pokemonData = await getPokemonData(); - res.send(pokemonData); +app.get('/', (req, res) => { + res.send('Hello World!') }); app.listen(port, () => { - console.log(`Example app listening at https://localhost:${port}`) + console.log(`Example app listening at http://localhost:${port}`) }); -async function getPokemonData() { - -let con = mysql.createConnection({ - host:"localhost", - user: "root", - password: "", - database:"Pokedex" -}); - -let data = await new Promise((resolve, reject )=> { - con.query("SELECT * FROM pokemon", (err, result, fields) => { - (err) ? reject(err) : resolve(result); +app.get("/pokemon", async (req, res) => { + let pokemon = await getPokemonsFromDatabase(); + res.send(pokemon); }); -}); - con.end(); +// async function getFromAPI(){ +// let promises = [] +// for (let i = 1; i <= 151; i++){ +// let response = axios.get(`https://pokeapi.co/api/v2/pokemon/${i}`) +// promises.push(response) +// } +// let responses = await Promise.all(promises) +// return responses.map(response => response.data).map(data => ({ +// "id": data.id, +// "name": data.name, +// "types": data.types.map(type => type.type.name), +// "img": data.sprites["other"]["official-artwork"]["front_default"] +// })) + +// } +// getFromAPI(); + +// async function loadDatabase(){ +// let con = mysql.createConnection({ +// host:"localhost", +// user: "root", +// password: password, +// database:"pokedex" +// }); - return data; -} +// let data = await getFromAPI(); +// data.forEach(pokemon => { +// con.query(`INSERT INTO pokemon (id, name, img) VALUES (${pokemon.id}, "${pokemon.name}", "${pokemon.img}");`); +// }) +// let uniqueTypes = new Set(); +// data.forEach(pokemon => { +// pokemon.types.forEach(type => { +// uniqueTypes.add(type) +// }) +// }) +// uniqueTypes = [...uniqueTypes] +// for(let i = 0; i < uniqueTypes.length; i++) { +// con.query(`INSERT INTO type (id, name) VALUES (${i+1}, "${uniqueTypes[i]}");`) +// } +// data.forEach(pokemon => { +// pokemon.types.forEach(type => { +// let typeId = uniqueTypes.indexOf(type) + 1; +// con.query(`INSERT INTO pokemon_type (pokemonId, typeId) VALUES (${pokemon.id}, ${typeId});`) +// }) +// }) +// console.log(data) +// con.end(); +// } +// loadDatabase() +async function getPokemonsFromDatabase(){ + let con = mysql.createConnection({ + host:"localhost", + user: "root", + password: password, + database:"pokedex" + }); + let data = await new Promise((resolve, reject) => { + con.query("SELECT * FROM pokemon", (err, result, fields) => { + (err) ? reject(err) : resolve(result); + }); + }); + + con.end(); + return data; + } From 20739991c6f389f61dfb1301fac2075162c79423 Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Wed, 17 Mar 2021 10:43:22 -0400 Subject: [PATCH 19/20] added package-lock json --- package-lock.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/package-lock.json b/package-lock.json index 5d66e24..136a341 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "cors": "^2.8.5", "express": "^4.17.1", "mysql": "^2.18.1", + "node-fetch": "^2.6.1", "pokedex-promise-v2": "^3.3.0" } }, @@ -392,6 +393,14 @@ "node": ">= 0.6" } }, + "node_modules/node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==", + "engines": { + "node": "4.x || >=6.0.0" + } + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -922,6 +931,11 @@ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" }, + "node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", From e13988a6f6829d3670be371b2257d1bc9cdaf31d Mon Sep 17 00:00:00 2001 From: Katharyn Lynn Oggenfuss Date: Wed, 17 Mar 2021 10:44:01 -0400 Subject: [PATCH 20/20] changed id to class --- web/style.css | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/web/style.css b/web/style.css index 18024f2..f665f8b 100644 --- a/web/style.css +++ b/web/style.css @@ -1,30 +1,23 @@ -body { - font-family: sans-serif, 'Segoe-UI'; - font-size: 16px; -} -#container { - display: flex; - flex-direction: row; - flex-wrap: wrap; - justify-content: center; -} .card { - max-width: 600px; - color: aliceblue; - background-color:coral; - border: 1px solid aliceblue; - border-radius: 5px; - padding: 2em; + margin: 3% auto; + border: 2px black solid; + padding: 3%; } img { + height: 250px; + width: 250px; margin: auto; - width: 60%; } h1 { text-align: center; + margin: 5% +} -} \ No newline at end of file +h4 { + display: grid; + grid-template-columns: auto auto; +} \ No newline at end of file