Skip to content

Commit be2e803

Browse files
authored
Merge pull request #8 from ucfcs/BackEnd
Back end
2 parents 7268627 + 9451763 commit be2e803

9 files changed

Lines changed: 125 additions & 5 deletions

File tree

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@
1212
/duct-drone-app/.vscode
1313
/duct-drone-app/.eslintcache
1414
/duct-drone-app/package-lock.json
15-
/Documents/*
15+
/Documents/*
16+
/duct-drone-app/.vs/
17+
duct-drone-app/src/.vs/
18+
/.vs/
19+
/duct-drone-app/build/

duct-drone-app/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"start": "webpack-dev-server --mode development --open",
88
"build": "webpack --mode production"
99
},
10+
"proxy": "http://localhost:5000",
1011
"author": "",
1112
"license": "ISC",
1213
"devDependencies": {
@@ -22,6 +23,10 @@
2223
"webpack-dev-server": "^3.2.1"
2324
},
2425
"dependencies": {
26+
"express": "^4.16.4",
27+
"mongodb": "^3.2.2",
28+
"mongoose": "^5.4.22",
29+
"path": "^0.12.7",
2530
"prop-types": "^15.7.2",
2631
"react": "^16.8.5",
2732
"react-bootstrap": "^1.0.0-beta.6",

duct-drone-app/server/database.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
let EntryModel = require('./models/entrymodel');
2+
let FloorModel = require('./models/floormodel');
3+
var mongoose = require('mongoose');
4+
5+
const server = '127.0.0.1:27017'; //DB SERVER
6+
const database = 'test'; //DB NAME
7+
8+
//Set up mongoose connection
9+
// var mongoose = require('mongoose');
10+
// var mongoDB = 'insert_your_database_url_here';
11+
// mongoose.connect(mongoDB, { useNewUrlParser: true });
12+
// var db = mongoose.connection;
13+
// db.on('error', console.error.bind(console, 'MongoDB connection error:'));
14+
15+
class Database {
16+
constructor() {
17+
this._connect();
18+
}
19+
_connect() {
20+
mongoose.connect(`mongodb://${server}/${database}`)
21+
.then(() => {
22+
console.log('DB Success');
23+
})
24+
.catch(err => {
25+
console.error('DB ERROR');
26+
});
27+
}
28+
}
29+
30+
module.exports = new Database();

duct-drone-app/server/index.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
let Entry = require('./models/entrymodel');
2+
let Floor= require('./models/floormodel');
3+
var express = require('express');
4+
const path = require('path');
5+
var app = express();
6+
const server = '127.0.0.1:27017'; //DB SERVER
7+
const database = 'test'; //DB NAME
8+
9+
10+
//respond with "hello world" when a GET request is made to the homepage
11+
app.use(express.static(path.join(__dirname, '../build')));
12+
13+
const port = process.env.PORT || 5000;
14+
15+
// console.log that your server is up and running
16+
app.listen(port, () => console.log(`Listening on port ${port}`));
17+
18+
// create a GET route
19+
app.get('/express_backend', (req, res) => {
20+
res.send({ express: 'YOUR EXPRESS BACKEND IS CONNECTED TO REACT' });
21+
});
22+
23+
var mongoose = require('mongoose');
24+
var mongoDB = `mongodb://${server}/${database}`;
25+
mongoose.connect(mongoDB, { useNewUrlParser: true });
26+
var db = mongoose.connection;
27+
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
28+
29+
30+
var testdata = new Entry({
31+
coordinate:[{ x:32, y:32, z:23}],
32+
time: new Date(),
33+
temperature: 32.3,
34+
air_velocity: 35.2,
35+
});
36+
testdata.save(function (err) {
37+
if (err) return handleError(err);
38+
console.log("SAVED");
39+
});
40+
app.get("/adddata", (req, res) => {
41+
var testdata = new Entry({
42+
coordinate:[{ x:32, y:32, z:23}],
43+
time: new Date(),
44+
temperature: 32.3,
45+
air_velocity: 35.2,
46+
});
47+
testdata.save()
48+
.then(item => {
49+
res.send("Saved to db");
50+
})
51+
.catch(err => {
52+
res.status(400).send("unable to save to db");
53+
});
54+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var mongoose = require('mongoose');
2+
const Schema = mongoose.Schema;
3+
4+
const entrySchema = new Schema({
5+
coordinate: [{ x: Number, y: Number, z: Number }],
6+
time: Date,
7+
temperature: Schema.Types.Decimal128,
8+
air_velocity: Schema.Types.Decimal128
9+
});
10+
11+
module.exports = mongoose.model('Entry', entrySchema);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var mongoose = require('mongoose');
2+
const Schema = mongoose.Schema;
3+
4+
const floorSchema = new Schema({
5+
name: String,
6+
map_link: String,
7+
date: Date,
8+
sensorData: [{ type: Schema.Types.ObjectId, ref: 'Entry' }]
9+
});
10+
11+
module.exports = mongoose.model('Floor', floorSchema);

duct-drone-app/src/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import Col from 'react-bootstrap/Col';
99
import { BrowserRouter as Router, Route, Link, Switch } from "react-router-dom";
1010
import { Navbar, Nav, NavItem, NavDropdown, MenuItem } from 'react-bootstrap';
1111
import './App.css';
12+
13+
1214
class App extends Component {
1315
render() {
1416
const InApp = () =>

duct-drone-app/src/Login.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Login extends Component {
2323
<Button variant="primary" type="submit">
2424
Submit
2525
</Button>
26-
<Link to="/app/">Login</Link>
26+
<Link to="/app/">proceed to next page</Link>
2727
</Form>
2828
)
2929
}

duct-drone-app/webpack.config.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
1+
var path = require('path');
22
const HtmlWebPackPlugin = require("html-webpack-plugin");
3-
3+
var BUILD_DIR = path.resolve(__dirname, './build');
44
const htmlPlugin = new HtmlWebPackPlugin({
55
template: "./src/index.html",
66
filename: "./index.html"
77
});
88

99
module.exports = {
10-
// entry: "./src/app.js",
10+
output: {
11+
filename: 'bundle.js',
12+
path: BUILD_DIR
13+
},
1114
module: {
1215
rules: [
1316
{

0 commit comments

Comments
 (0)