From e54e823a879e0c66b42a99178c0d679d933a3ac3 Mon Sep 17 00:00:00 2001 From: Bruno Date: Tue, 24 Nov 2020 01:41:04 -0500 Subject: [PATCH] MVP --- client/.eslintcache | 2 +- client/package-lock.json | 8 +++ client/package.json | 1 + client/src/App.js | 91 ++++++++++++++++++++++----- client/src/index.js | 1 + server/database/db.sqlite | Bin 16384 -> 16384 bytes server/package-lock.json | 9 +++ server/package.json | 1 + server/src/routes/index.js | 5 ++ server/src/routes/inventory.route.js | 12 +++- 10 files changed, 113 insertions(+), 17 deletions(-) diff --git a/client/.eslintcache b/client/.eslintcache index 91ed707..681d8b6 100644 --- a/client/.eslintcache +++ b/client/.eslintcache @@ -1 +1 @@ -[{"/Users/jgo/Documents/Sonobi/fe-code-challenge/client/src/index.js":"1","/Users/jgo/Documents/Sonobi/fe-code-challenge/client/src/App.js":"2"},{"size":219,"mtime":1606160019328,"results":"3","hashOfConfig":"4"},{"size":528,"mtime":1606155683575,"results":"5","hashOfConfig":"4"},{"filePath":"6","messages":"7","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1qz3yvt",{"filePath":"8","messages":"9","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/jgo/Documents/Sonobi/fe-code-challenge/client/src/index.js",[],"/Users/jgo/Documents/Sonobi/fe-code-challenge/client/src/App.js",[]] \ No newline at end of file +[{"/home/bruno/fe-code-challenge/client/src/App.js":"1","/home/bruno/fe-code-challenge/client/src/index.js":"2"},{"size":2155,"mtime":1606199973499,"results":"3","hashOfConfig":"4"},{"size":220,"mtime":1606186125964,"results":"5","hashOfConfig":"4"},{"filePath":"6","messages":"7","errorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"67sdn0",{"filePath":"8","messages":"9","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/home/bruno/fe-code-challenge/client/src/App.js",["10"],"/home/bruno/fe-code-challenge/client/src/index.js",[],{"ruleId":"11","severity":1,"message":"12","line":5,"column":5,"nodeType":"13","messageId":"14","endLine":5,"endColumn":16},"no-unused-vars","'buttonStyle' is assigned a value but never used.","Identifier","unusedVar"] \ No newline at end of file diff --git a/client/package-lock.json b/client/package-lock.json index 6ea42f2..2cddc42 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -2818,6 +2818,14 @@ "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.1.1.tgz", "integrity": "sha512-5Kgy8Cz6LPC9DJcNb3yjAXTu3XihQgEdnIg50c//zOC/MyLP0Clg+Y8Sh9ZjjnvBrDZU4DgXS9C3T9r4/scGZQ==" }, + "axios": { + "version": "0.21.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.0.tgz", + "integrity": "sha512-fmkJBknJKoZwem3/IKSSLpkdNXZeBu5Q7GA/aRsr2btgrptmSCxi2oFjZHqGdK9DoTil9PIHlPIZw2EcRJXRvw==", + "requires": { + "follow-redirects": "^1.10.0" + } + }, "axobject-query": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.2.0.tgz", diff --git a/client/package.json b/client/package.json index ebaaec3..6bf9868 100644 --- a/client/package.json +++ b/client/package.json @@ -6,6 +6,7 @@ "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", "@testing-library/user-event": "^12.1.10", + "axios": "^0.21.0", "react": "^17.0.1", "react-dom": "^17.0.1", "react-scripts": "4.0.1", diff --git a/client/src/App.js b/client/src/App.js index 3784575..3f2e950 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -1,23 +1,84 @@ -import logo from './logo.svg'; import './App.css'; +import axios from 'axios'; +import React from 'react'; + +var buttonStyle = { + margin: '10px 10px 10px 0' +}; + + +class Inv extends React.Component { + constructor(props) { + super(props); + this.submitRecord = this.submitRecord.bind(this); + this.nameChange = this.nameChange.bind(this); + this.typeChange = this.typeChange.bind(this); + this.urlChange = this.urlChange.bind(this); + this.state = { list: [], name: "", type: "", url: "" }; + } + + nameChange(event) { this.setState({ name: event.target.value }); } + typeChange(event) { this.setState({ type: event.target.value }); } + urlChange(event) { this.setState({ url: event.target.value }); } + + submitRecord(event) { + + let payload = { + name: this.state.name, + type: this.state.type, + url: this.state.url + } + + axios.post('http://localhost:3001/inventoryset', payload) + .then((response) => { + console.log(response); + this.getInv(); + }) + .catch((error) => { + console.log(error); + }); + + event.preventDefault(); + } + + getInv() { + axios.get('http://localhost:3001/inventoryget') + .then((response) => { + let temp = [] + for (let x of response.data.result) + temp.push(
  • {x.id}, {x.name}, {x.type}, {x.url}
  • ); + console.log(temp); + this.setState({ list: temp }) + }) + .catch((error) => { + console.log(error); + this.setState({ list: [
  • Could not grab inventory
  • ] }) + }) + } + + componentDidMount() { + this.getInv(); + } + + render() { + return
    +
    + + + + +
    + +
    ; + } +} + + function App() { return (
    -
    - logo -

    - Edit src/App.js and save to reload. -

    - - Learn React - -
    +
    ); } diff --git a/client/src/index.js b/client/src/index.js index 6832e78..9b451d9 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -3,6 +3,7 @@ import ReactDOM from 'react-dom'; import './index.css'; import App from './App'; + ReactDOM.render( diff --git a/server/database/db.sqlite b/server/database/db.sqlite index ed1e828954eb1f0644cc1e08eb156c6e4f3dac66..929478c48e520b5461292dfe6de845785ab81edd 100644 GIT binary patch literal 16384 zcmeI2J8%<69EVqa=wVy76UUf5S;9cf7*6++bh^X?!cjmIV;oD~geK@DpDhPj5|SK4 zhX;yO8A?jZlyp#1Qc@-zB_$VRZQE_? z>d?|!E?dmuV)oo}4wooW!tFRAdGix_^U(VxrK$$ z<=)ua*J|(?_Db8nwrkfbw&Uh7GinE%?{3pmu;fXYUh(klZ1+PiLi?My&%K;gGtP9W zSl?<^y<D5d%EoIV*x7R`8`0F!HuWBZB$&fSNUIzv5 z9e%Ge&`VSB8r)tvBPmIr`JkE%g?Fc?oLJZBB*kyLftRM>mASp$ z`Jnr*FGCR;{gdCD0pFO83f?BS7oKk^ z)n}f`-DhK;g7+}LHzlRCq+h-|O%WP;#O+lLNlE#xFGImw<@aimuKMPy(iFVY++IbO zl1bnBz)*xj54pXvDy9A2-{7sErr<5{c#~!_W9piuYF_WhZVKKgw^vI`n&LGddR~UY zuGf8Tuafb3-RXH5O2QGu<4u`b#*_{4dd~+Z-9IuKMMq}#7xMY<&D(osiRN#ww>XhN0Eon z6?rq0*o22!V0^tVr(q>ysm*+Twa)@cIm<<)H{VJ_}o}o6PxLtF^Ih)w^jx zL|X?p|7{{aha%|cEab6tu7C^8Myu2A{)bAr-R|A+_q+BhnCM8rbNukwqp|APbnIcQ6pKdh zM}LZ<$RCl_@Qd)h@P*OmqjyKojyxN=Ghz%seGftsLlg=8&k`UEM>;DN3=IuB9 zuaBuxXC3q@ITFN6H~eldP01GlyiCLI@-mcs&h2$H{0^^!lFzukj)vdibx`tY5HH>E zyS+3ep9JtS4Zq9FQ1UUi*U|7hybekZ2l3JkzuQYwG8e$hH2f|vL&>2aUb^9Tdud8$ zgL(T6zn8a9$wxuFbi?oV(v-{u@zM>y+e=gOA-C7j@H@N?N?m!@Poh?j2o z-CmlKsQ_N4;dgl%N+yGN>4x9!r74LA@G=d*%gazQ5yVS3{BAEz$#?)S)9|~z3?*X$ zyiCLI@-mdf_`L3hpZ2;bi3ad84Zq9FP!b8?Wg32$m!Z7FlF9U~E-sGj{zUVcsnCcf{{ns+zCJ!B-UgtCJl@R>vXg{h HtOh0kGd>w* diff --git a/server/package-lock.json b/server/package-lock.json index b30e21a..f3bb27e 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -234,6 +234,15 @@ "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" + } + }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", diff --git a/server/package.json b/server/package.json index 68c8a71..82f0800 100644 --- a/server/package.json +++ b/server/package.json @@ -10,6 +10,7 @@ "author": "", "license": "ISC", "dependencies": { + "cors": "^2.8.5", "express": "^4.17.1", "sequelize": "^6.3.5", "sqlite3": "^5.0.0" diff --git a/server/src/routes/index.js b/server/src/routes/index.js index 24a9b7e..4b9c60f 100644 --- a/server/src/routes/index.js +++ b/server/src/routes/index.js @@ -1,7 +1,12 @@ const express = require('express'); +const cors = require('cors'); //needed to make sure it runs locally const app = express(); const port = 3001; +app.use(cors()) +app.use(express.urlencoded({ extened: true })) +app.use(express.json()) + const inventory = require('./inventory.route'); module.exports = function routes(sequelize) { diff --git a/server/src/routes/inventory.route.js b/server/src/routes/inventory.route.js index b28b912..b4c4909 100644 --- a/server/src/routes/inventory.route.js +++ b/server/src/routes/inventory.route.js @@ -1,9 +1,19 @@ module.exports = function inventoryRoute(app, sequelize) { - app.get('/inventory', async (req, res) => { + app.get('/inventoryget', async (req, res) => { const inventories = await sequelize.models.Inventory.findAll(); res.statusCode = 200; res.send({ result: inventories }); }); + + app.post('/inventoryset', async (req, res) => { + const inventories = await sequelize.models.Inventory.create({ + name: req.body.name, + type: req.body.type, + url: req.body.url + }); + res.statusCode = 200; + res.send(); + }) };