consolidate all repos to one for archive
This commit is contained in:
132
projektna_naloga/web_server/.gitignore
vendored
Normal file
132
projektna_naloga/web_server/.gitignore
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
.temp
|
||||
.cache
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
tmp.txt
|
84
projektna_naloga/web_server/app.js
Normal file
84
projektna_naloga/web_server/app.js
Normal file
@@ -0,0 +1,84 @@
|
||||
const createError = require('http-errors');
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
const cookieParser = require('cookie-parser');
|
||||
|
||||
let exampleApp = true;
|
||||
|
||||
if (!exampleApp) {
|
||||
// vključimo mongoose in ga povežemo z MongoDB
|
||||
const mongoose = require('mongoose');
|
||||
const mongoDB = "mongodb://127.0.0.1/projekt";
|
||||
mongoose.connect(mongoDB);
|
||||
mongoose.set('strictQuery', false);
|
||||
mongoose.Promise = global.Promise;
|
||||
const db = mongoose.connection;
|
||||
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
|
||||
}
|
||||
// routes
|
||||
const usersRouter = require('./routes/userRoutes');
|
||||
const locationRouter = require('./routes/locationRoutes');
|
||||
const rawCameraData = require('./routes/rawCameraDataRoutes');
|
||||
const hourlyData = require('./routes/hourlyDataRoutes');
|
||||
const dailyData = require('./routes/dailyDataRoutes');
|
||||
const dataRouter = require('./routes/dataRouter');
|
||||
const counterRouter = require('./routes/counterRouter');
|
||||
|
||||
|
||||
const app = express();
|
||||
|
||||
// view engine setup
|
||||
app.set('views', path.join(__dirname, 'views'));
|
||||
app.set('view engine', 'hbs');
|
||||
|
||||
// const logger = require('morgan');
|
||||
// app.use(logger('dev'));
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
app.use(cookieParser());
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
if (!exampleApp) {
|
||||
const session = require('express-session');
|
||||
const MongoStore = require('connect-mongo');
|
||||
app.use(session({
|
||||
secret: 'work hard',
|
||||
resave: true,
|
||||
saveUninitialized: false,
|
||||
//store: MongoStore.create({ mongoUrl: mongoDB })
|
||||
}));
|
||||
}
|
||||
// catch 404 and forward to error handler
|
||||
app.use(function (req, res, next) {
|
||||
res.locals.session = req.session;
|
||||
next();
|
||||
});
|
||||
|
||||
if (!exampleApp) {
|
||||
app.use('/api/users', usersRouter);
|
||||
app.use('/api/rawCameraData', rawCameraData);
|
||||
app.use('/api/hourlyData', hourlyData);
|
||||
app.use('/api/dailyData', dailyData);
|
||||
app.use('/api/counter', counterRouter);
|
||||
}
|
||||
app.use('/api/location', locationRouter);
|
||||
app.use('/api/data', dataRouter);
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
app.use(function (req, res, next) {
|
||||
next(createError(404));
|
||||
});
|
||||
|
||||
// error handler
|
||||
app.use(function (err, req, res, next) {
|
||||
// set locals, only providing error in development
|
||||
res.locals.message = err.message;
|
||||
res.locals.error = req.app.get('env') === 'development' ? err : {};
|
||||
|
||||
// render the error page
|
||||
res.status(err.status || 500);
|
||||
res.render('error');
|
||||
//console.log(req.socket.remoteAddress);
|
||||
});
|
||||
|
||||
module.exports = app;
|
90
projektna_naloga/web_server/bin/www.js
Normal file
90
projektna_naloga/web_server/bin/www.js
Normal file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const app = require('../app');
|
||||
const debug = require('debug')('backend:server');
|
||||
const http = require('http');
|
||||
|
||||
/**
|
||||
* Get port from environment and store in Express.
|
||||
*/
|
||||
|
||||
const port = normalizePort(process.env.PORT || '3000');
|
||||
app.set('port', port);
|
||||
|
||||
/**
|
||||
* Create HTTP server.
|
||||
*/
|
||||
|
||||
const server = http.createServer(app);
|
||||
|
||||
/**
|
||||
* Listen on provided port, on all network interfaces.
|
||||
*/
|
||||
|
||||
server.listen(port);
|
||||
server.on('error', onError);
|
||||
server.on('listening', onListening);
|
||||
|
||||
/**
|
||||
* Normalize a port into a number, string, or false.
|
||||
*/
|
||||
|
||||
function normalizePort(val) {
|
||||
const port = parseInt(val, 10);
|
||||
|
||||
if (isNaN(port)) {
|
||||
// named pipe
|
||||
return val;
|
||||
}
|
||||
|
||||
if (port >= 0) {
|
||||
// port number
|
||||
return port;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener for HTTP server "error" event.
|
||||
*/
|
||||
|
||||
function onError(error) {
|
||||
if (error.syscall !== 'listen') {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const bind = typeof port === 'string'
|
||||
? 'Pipe ' + port
|
||||
: 'Port ' + port;
|
||||
|
||||
// handle specific listen errors with friendly messages
|
||||
switch (error.code) {
|
||||
case 'EACCES':
|
||||
console.error(bind + ' requires elevated privileges');
|
||||
process.exit(1);
|
||||
break;
|
||||
case 'EADDRINUSE':
|
||||
console.error(bind + ' is already in use');
|
||||
process.exit(1);
|
||||
break;
|
||||
default:
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener for HTTP server "listening" event.
|
||||
*/
|
||||
|
||||
function onListening() {
|
||||
const addr = server.address();
|
||||
const bind = typeof addr === 'string'
|
||||
? 'pipe ' + addr
|
||||
: 'port ' + addr.port;
|
||||
debug('Listening on ' + bind);
|
||||
}
|
198
projektna_naloga/web_server/controllers/dailyDataController.js
Normal file
198
projektna_naloga/web_server/controllers/dailyDataController.js
Normal file
@@ -0,0 +1,198 @@
|
||||
const DailydataModel = require('../models/dailyDataModel.js');
|
||||
const DailyData = require('../data/dailyData.json');
|
||||
/**
|
||||
* dailyDataController.js
|
||||
*
|
||||
* @description :: Server-side logic for managing dailyDatas.
|
||||
*/
|
||||
module.exports = {
|
||||
|
||||
/**
|
||||
* dailyDataController.list()
|
||||
*/
|
||||
list: function (req, res) {
|
||||
DailydataModel.find(function (err, dailyDatas) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting dailyData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(dailyDatas);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* dailyDataController.show()
|
||||
*/
|
||||
show: function (req, res) {
|
||||
const id = req.params.id;
|
||||
|
||||
DailydataModel.find({ location_id: id }, function (err, dailyData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting dailyData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
if (!dailyData) {
|
||||
return res.status(404).json({
|
||||
message: 'No such dailyData'
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(dailyData);
|
||||
});
|
||||
},
|
||||
|
||||
showLocationTest: function (req, res) {
|
||||
let location = req.params.location;
|
||||
location = Number.parseInt(location);
|
||||
|
||||
if (isNaN(location)) return res.json([]);
|
||||
|
||||
if (location > 248) location = 248;
|
||||
else if (location < 0) location = 0;
|
||||
|
||||
return res.json(DailyData[location]);
|
||||
},
|
||||
|
||||
showLocation: function (req, res) {
|
||||
const year = req.params.year;
|
||||
const month = req.params.month;
|
||||
const location = req.params.location;
|
||||
|
||||
DailydataModel.find({
|
||||
year: year,
|
||||
month: month,
|
||||
location_id: location
|
||||
}).exec(function (err, dailyData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting dailyData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
if (!dailyData) {
|
||||
return res.status(404).json({
|
||||
message: 'No such dailyData'
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(dailyData);
|
||||
});
|
||||
},
|
||||
|
||||
showDay: function (req, res) {
|
||||
const year = req.params.year;
|
||||
const month = req.params.month;
|
||||
const day = req.params.day;
|
||||
|
||||
DailydataModel.find({
|
||||
year: year,
|
||||
month: month,
|
||||
day: day
|
||||
}).exec(function (err, dailyData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting dailyData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
if (!dailyData) {
|
||||
return res.status(404).json({
|
||||
message: 'No such dailyData'
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(dailyData);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* dailyDataController.create()
|
||||
*/
|
||||
create: function (req, res) {
|
||||
const dailyData = new DailydataModel({
|
||||
location_id: req.body.location_id,
|
||||
date: req.body.date,
|
||||
car_count: req.body.car_count,
|
||||
year: req.body.year,
|
||||
month: req.body.month,
|
||||
day: req.body.day
|
||||
});
|
||||
|
||||
dailyData.save(function (err, dailyData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when creating dailyData',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(201).json(dailyData);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* dailyDataController.update()
|
||||
*/
|
||||
update: function (req, res) {
|
||||
const id = req.params.id;
|
||||
|
||||
DailydataModel.findOne({ _id: id }, function (err, dailyData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting dailyData',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
if (!dailyData) {
|
||||
return res.status(404).json({
|
||||
message: 'No such dailyData'
|
||||
});
|
||||
}
|
||||
|
||||
dailyData.location_id = req.body.location_id ? req.body.location_id : dailyData.location_id;
|
||||
dailyData.date = req.body.date ? req.body.date : dailyData.date;
|
||||
dailyData.car_count = req.body.car_count ? req.body.car_count : dailyData.car_count;
|
||||
dailyData.year = req.body.year ? req.body.year : dailyData.year;
|
||||
dailyData.month = req.body.month ? req.body.month : dailyData.month;
|
||||
dailyData.day = req.body.day ? req.body.day : dailyData.day;
|
||||
|
||||
dailyData.save(function (err, dailyData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when updating dailyData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(dailyData);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* dailyDataController.remove()
|
||||
*/
|
||||
remove: function (req, res) {
|
||||
const id = req.params.id;
|
||||
|
||||
DailydataModel.findByIdAndRemove(id, function (err, dailyData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when deleting the dailyData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(204).json();
|
||||
});
|
||||
}
|
||||
};
|
254
projektna_naloga/web_server/controllers/hourlyDataController.js
Normal file
254
projektna_naloga/web_server/controllers/hourlyDataController.js
Normal file
@@ -0,0 +1,254 @@
|
||||
const HourlydataModel = require('../models/hourlyDataModel.js');
|
||||
const MapData = require('../data/mapData.json');
|
||||
const HourlyData = require('../data/hourlyData.json');
|
||||
/**
|
||||
* hourlyDataController.js
|
||||
*
|
||||
* @description :: Server-side logic for managing hourlyDatas.
|
||||
*/
|
||||
module.exports = {
|
||||
|
||||
/**
|
||||
* hourlyDataController.list()
|
||||
*/
|
||||
list: function (req, res) {
|
||||
HourlydataModel.find(function (err, hourlyDatas) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting hourlyData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(hourlyDatas);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* hourlyDataController.show()
|
||||
*/
|
||||
// DOTO: change this to get last 24 hours for a location
|
||||
show: function (req, res) {
|
||||
const location = req.params.location;
|
||||
|
||||
HourlydataModel.find({ location_id: location }, function (err, hourlyData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting hourlyData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
if (!hourlyData) {
|
||||
return res.status(404).json({
|
||||
message: 'No such hourlyData'
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(hourlyData);
|
||||
});
|
||||
},
|
||||
//location id max 248
|
||||
showLocationTest: function (req, res) {
|
||||
let location = req.params.location;
|
||||
location = Number.parseInt(location);
|
||||
|
||||
if (isNaN(location)) return res.json([]);
|
||||
|
||||
if (location > 248) location = 248;
|
||||
else if (location < 0) location = 0;
|
||||
|
||||
return res.json(HourlyData[location]);
|
||||
},
|
||||
|
||||
showLocation: function (req, res) {
|
||||
const location = req.params.location;
|
||||
const year = req.params.year;
|
||||
const month = req.params.month;
|
||||
const day = req.params.day;
|
||||
|
||||
HourlydataModel.find({
|
||||
location_id: location,
|
||||
year: year,
|
||||
month: month,
|
||||
day: day
|
||||
}).sort({ hour: 1 }).exec(function (err, hourlyData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting hourlyData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
if (!hourlyData) {
|
||||
return res.status(404).json({
|
||||
message: 'No such hourlyData'
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(hourlyData);
|
||||
});
|
||||
},
|
||||
|
||||
showHourTest: function (req, res) {
|
||||
return res.json(MapData);
|
||||
},
|
||||
|
||||
showHourCsvTest: function (req, res) {
|
||||
let csv = "";
|
||||
MapData.forEach(row =>
|
||||
csv += row.location_id + "," + row.car_count + "\n"
|
||||
);
|
||||
res.setHeader('Content-disposition', 'attachment; filename=hourlyData.csv');
|
||||
res.set('Content-Type', 'text/csv');
|
||||
return res.send(csv);
|
||||
},
|
||||
|
||||
showHour: function (req, res) {
|
||||
const year = req.params.year;
|
||||
const month = req.params.month;
|
||||
const day = req.params.day;
|
||||
const hour = req.params.hour;
|
||||
|
||||
HourlydataModel.find({
|
||||
year: year,
|
||||
month: month,
|
||||
day: day,
|
||||
hour: hour
|
||||
}).sort({ location_id: 1 }).exec(function (err, hourlyData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting hourlyData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
if (!hourlyData) {
|
||||
return res.status(404).json({
|
||||
message: 'No such hourlyData'
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(hourlyData);
|
||||
});
|
||||
},
|
||||
|
||||
showHourCsv: function (req, res) {
|
||||
const year = req.params.year;
|
||||
const month = req.params.month;
|
||||
const day = req.params.day;
|
||||
const hour = req.params.hour;
|
||||
|
||||
HourlydataModel.find({
|
||||
year: year,
|
||||
month: month,
|
||||
day: day,
|
||||
hour: hour
|
||||
}).sort({ location_id: 1 }).exec(function (err, hourlyData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting hourlyData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
if (!hourlyData) {
|
||||
return res.status(404).json({
|
||||
message: 'No such hourlyData'
|
||||
});
|
||||
}
|
||||
|
||||
let csv = "";
|
||||
hourlyData.forEach(function (row) {
|
||||
csv += row.location_id + "," + row.car_count + "\n";
|
||||
});
|
||||
res.setHeader('Content-disposition', 'attachment; filename=hourlyData.csv');
|
||||
res.set('Content-Type', 'text/csv');
|
||||
return res.send(csv);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* hourlyDataController.create()
|
||||
*/
|
||||
create: function (req, res) {
|
||||
const hourlyData = new HourlydataModel({
|
||||
location_id: req.body.location_id,
|
||||
date: req.body.date,
|
||||
car_count: req.body.car_count,
|
||||
hour: req.body.hour,
|
||||
day: req.body.day,
|
||||
month: req.body.month,
|
||||
year: req.body.year
|
||||
});
|
||||
|
||||
hourlyData.save(function (err, hourlyData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when creating hourlyData',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(201).json(hourlyData);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* hourlyDataController.update()
|
||||
*/
|
||||
update: function (req, res) {
|
||||
const id = req.params.id;
|
||||
|
||||
HourlydataModel.findOne({ _id: id }, function (err, hourlyData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting hourlyData',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
if (!hourlyData) {
|
||||
return res.status(404).json({
|
||||
message: 'No such hourlyData'
|
||||
});
|
||||
}
|
||||
|
||||
hourlyData.location_id = req.body.location_id ? req.body.location_id : hourlyData.location_id;
|
||||
hourlyData.date = req.body.date ? req.body.date : hourlyData.date;
|
||||
hourlyData.car_count = req.body.car_count ? req.body.car_count : hourlyData.car_count;
|
||||
hourlyData.hour = req.body.hour ? req.body.hour : hourlyData.hour;
|
||||
hourlyData.day = req.body.day ? req.body.day : hourlyData.day;
|
||||
hourlyData.month = req.body.month ? req.body.month : hourlyData.month;
|
||||
hourlyData.year = req.body.year ? req.body.year : hourlyData.year;
|
||||
|
||||
hourlyData.save(function (err, hourlyData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when updating hourlyData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(hourlyData);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* hourlyDataController.remove()
|
||||
*/
|
||||
remove: function (req, res) {
|
||||
const id = req.params.id;
|
||||
|
||||
HourlydataModel.findByIdAndRemove(id, function (err, hourlyData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when deleting the hourlyData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(204).json();
|
||||
});
|
||||
}
|
||||
};
|
@@ -0,0 +1,38 @@
|
||||
let Locations = require('../data/locations.json');
|
||||
/**
|
||||
* locationController.js
|
||||
*
|
||||
* @description :: Server-side logic for managing locations.
|
||||
*/
|
||||
module.exports = {
|
||||
|
||||
/**
|
||||
* locationController.list()
|
||||
*/
|
||||
list: function (req, res) {
|
||||
return res.json(Locations);
|
||||
},
|
||||
|
||||
csv: function (req, res) {
|
||||
let csvData = "";
|
||||
for (let i = 0; i < Locations.length; i++) {
|
||||
csvData += Locations[i].location_id + "," + Locations[i].name + "," + Locations[i].cord_N + "," + Locations[i].cord_E + "," + Locations[i].img_urls[0] + "\n";
|
||||
}
|
||||
|
||||
res.setHeader('Content-disposition', 'attachment; filename=locations.csv');
|
||||
res.set('Content-Type', 'text/csv');
|
||||
|
||||
res.status(200).send(csvData);
|
||||
},
|
||||
|
||||
/**
|
||||
* locationController.show()
|
||||
*/
|
||||
show: function (req, res) {
|
||||
const id = req.params.id;
|
||||
|
||||
const find = Locations.find(value => value.location_id == id)
|
||||
|
||||
return res.json(find);
|
||||
},
|
||||
};
|
@@ -0,0 +1,130 @@
|
||||
const RawcameradataModel = require('../models/rawCameraDataModel.js');
|
||||
|
||||
/**
|
||||
* rawCameraDataController.js
|
||||
*
|
||||
* @description :: Server-side logic for managing rawCameraDatas.
|
||||
*/
|
||||
module.exports = {
|
||||
|
||||
/**
|
||||
* rawCameraDataController.list()
|
||||
*/
|
||||
list: function (req, res) {
|
||||
RawcameradataModel.find(function (err, rawCameraDatas) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting rawCameraData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(rawCameraDatas);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* rawCameraDataController.show()
|
||||
*/
|
||||
show: function (req, res) {
|
||||
const id = req.params.id;
|
||||
|
||||
RawcameradataModel.findOne({ _id: id }, function (err, rawCameraData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting rawCameraData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
if (!rawCameraData) {
|
||||
return res.status(404).json({
|
||||
message: 'No such rawCameraData'
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(rawCameraData);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* rawCameraDataController.create()
|
||||
*/
|
||||
create: function (req, res) {
|
||||
const date1 = new Date(req.body.date);
|
||||
const rawCameraData = new RawcameradataModel({
|
||||
location_id: req.body.location_id,
|
||||
camera_id: req.body.camera_id,
|
||||
date: date1,
|
||||
car_count: req.body.car_count,
|
||||
hour: req.body.hour
|
||||
});
|
||||
|
||||
rawCameraData.save(function (err, rawCameraData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when creating rawCameraData',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(201).json(rawCameraData);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* rawCameraDataController.update()
|
||||
*/
|
||||
update: function (req, res) {
|
||||
const id = req.params.id;
|
||||
|
||||
RawcameradataModel.findOne({ _id: id }, function (err, rawCameraData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting rawCameraData',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
if (!rawCameraData) {
|
||||
return res.status(404).json({
|
||||
message: 'No such rawCameraData'
|
||||
});
|
||||
}
|
||||
|
||||
rawCameraData.location_id = req.body.location_id ? req.body.location_id : rawCameraData.location_id;
|
||||
rawCameraData.camera_id = req.body.camera_id ? req.body.camera_id : rawCameraData.camera_id;
|
||||
rawCameraData.date = req.body.date ? req.body.date : rawCameraData.date;
|
||||
rawCameraData.car_count = req.body.car_count ? req.body.car_count : rawCameraData.car_count;
|
||||
rawCameraData.hour = req.body.hour ? req.body.hour : rawCameraData.hour;
|
||||
|
||||
rawCameraData.save(function (err, rawCameraData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when updating rawCameraData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(rawCameraData);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* rawCameraDataController.remove()
|
||||
*/
|
||||
remove: function (req, res) {
|
||||
const id = req.params.id;
|
||||
RawcameradataModel.deleteMany({ hour: id }, function (err, rawCameraData) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when deleting the rawCameraData.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(204).json();
|
||||
});
|
||||
}
|
||||
};
|
237
projektna_naloga/web_server/controllers/userController.js
Normal file
237
projektna_naloga/web_server/controllers/userController.js
Normal file
@@ -0,0 +1,237 @@
|
||||
const UserModel = require('../models/userModel.js');
|
||||
/**
|
||||
* userController.js
|
||||
*
|
||||
* @description :: Server-side logic for managing users.
|
||||
*/
|
||||
module.exports = {
|
||||
|
||||
/**
|
||||
* userController.list()
|
||||
*/
|
||||
list: function (req, res) {
|
||||
UserModel.find(function (err, users) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting user.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(users);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* userController.show()
|
||||
*/
|
||||
show: function (req, res) {
|
||||
const id = req.params.id;
|
||||
|
||||
UserModel.findOne({ _id: id }, function (err, user) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting user.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
return res.status(404).json({
|
||||
message: 'No such user'
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(user);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* userController.create()
|
||||
*/
|
||||
create: function (req, res) {
|
||||
const user = new UserModel({
|
||||
username: req.body.username,
|
||||
password: req.body.password,
|
||||
email: req.body.email,
|
||||
locations: []
|
||||
});
|
||||
|
||||
user.save(function (err, user) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when creating user',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(201).json(user);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* userController.update()
|
||||
*/
|
||||
update: function (req, res) {
|
||||
const id = req.params.id;
|
||||
|
||||
UserModel.findOne({ _id: id }, function (err, user) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting user',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
return res.status(404).json({
|
||||
message: 'No such user'
|
||||
});
|
||||
}
|
||||
|
||||
user.username = req.body.username ? req.body.username : user.username;
|
||||
user.password = req.body.password ? req.body.password : user.password;
|
||||
user.email = req.body.email ? req.body.email : user.email;
|
||||
|
||||
|
||||
user.save(function (err, user) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when updating user.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(user);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* userController.remove()
|
||||
*/
|
||||
remove: function (req, res) {
|
||||
const id = req.params.id;
|
||||
|
||||
UserModel.findByIdAndRemove(id, function (err, user) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when deleting the user.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(204).json();
|
||||
});
|
||||
},
|
||||
|
||||
showRegister: function (req, res) {
|
||||
res.render('user/register');
|
||||
},
|
||||
|
||||
showLogin: function (req, res) {
|
||||
res.render('user/login');
|
||||
},
|
||||
|
||||
login: function (req, res, next) {
|
||||
UserModel.authenticate(req.body.username, req.body.password, function (err, user) {
|
||||
if (err || !user) {
|
||||
const err = new Error('Wrong username or paassword');
|
||||
err.status = 401;
|
||||
return next(err);
|
||||
}
|
||||
req.session.userId = user._id;
|
||||
|
||||
return res.json(user);
|
||||
});
|
||||
},
|
||||
|
||||
logout: function (req, res, next) {
|
||||
if (req.session) {
|
||||
req.session.destroy(function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
} else {
|
||||
//return res.redirect('/');
|
||||
return res.status(201).json({});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
profile: function (req, res, next) {
|
||||
UserModel.findById(req.session.userId)
|
||||
.exec(function (error, user) {
|
||||
if (error) {
|
||||
return next(error);
|
||||
} else {
|
||||
if (user === null) {
|
||||
const err = new Error('Not authorized, go back!');
|
||||
err.status = 400;
|
||||
return next(err);
|
||||
} else {
|
||||
//return res.render('user/profile', user);
|
||||
return res.json(user);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
addLocation: function (req, res) {
|
||||
const locationID = req.params.id;
|
||||
|
||||
UserModel.findOne({ _id: req.session.userId }, function (err, user) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting user',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
return res.status(404).json({
|
||||
message: 'No such user'
|
||||
});
|
||||
}
|
||||
|
||||
if (user.locations.includes(locationID)) {
|
||||
return res.status(400).json({
|
||||
message: 'Location already added'
|
||||
});
|
||||
}
|
||||
|
||||
user.locations.push(locationID);
|
||||
|
||||
user.save(function (err, user) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when updating user.',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(user);
|
||||
});
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
checkLocation: function (req, res) {
|
||||
UserModel.findOne({ _id: req.session.userId }, function (err, user) {
|
||||
if (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting user',
|
||||
error: err
|
||||
});
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
return res.status(404).json({
|
||||
message: 'No such user'
|
||||
});
|
||||
}
|
||||
|
||||
return res.json(user.locations);
|
||||
});
|
||||
}
|
||||
};
|
1672
projektna_naloga/web_server/data/cameras.json
Normal file
1672
projektna_naloga/web_server/data/cameras.json
Normal file
File diff suppressed because it is too large
Load Diff
6476
projektna_naloga/web_server/data/dailyData.json
Normal file
6476
projektna_naloga/web_server/data/dailyData.json
Normal file
File diff suppressed because it is too large
Load Diff
54284
projektna_naloga/web_server/data/hourlyData.json
Normal file
54284
projektna_naloga/web_server/data/hourlyData.json
Normal file
File diff suppressed because it is too large
Load Diff
2328
projektna_naloga/web_server/data/locations.json
Normal file
2328
projektna_naloga/web_server/data/locations.json
Normal file
File diff suppressed because it is too large
Load Diff
2243
projektna_naloga/web_server/data/mapData.json
Normal file
2243
projektna_naloga/web_server/data/mapData.json
Normal file
File diff suppressed because it is too large
Load Diff
13
projektna_naloga/web_server/models/dailyDataModel.js
Normal file
13
projektna_naloga/web_server/models/dailyDataModel.js
Normal file
@@ -0,0 +1,13 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const dailyDataSchema = new Schema({
|
||||
'location_id': Number,
|
||||
'date': Date,
|
||||
'car_count': Number,
|
||||
'year': Number,
|
||||
'month': Number,
|
||||
'day': Number
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('dailyData', dailyDataSchema);
|
14
projektna_naloga/web_server/models/hourlyDataModel.js
Normal file
14
projektna_naloga/web_server/models/hourlyDataModel.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const hourlyDataSchema = new Schema({
|
||||
'location_id': Number,
|
||||
'date': Date,
|
||||
'car_count': Number,
|
||||
'hour': Number,
|
||||
'day': Number,
|
||||
'month': Number,
|
||||
'year': Number
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('hourlyData', hourlyDataSchema);
|
12
projektna_naloga/web_server/models/rawCameraDataModel.js
Normal file
12
projektna_naloga/web_server/models/rawCameraDataModel.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const rawCameraDataSchema = new Schema({
|
||||
'location_id': Number,
|
||||
'camera_id': Number,
|
||||
'date': Date,
|
||||
'car_count': Number,
|
||||
'hour': Number
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('rawCameraData', rawCameraDataSchema);
|
45
projektna_naloga/web_server/models/userModel.js
Normal file
45
projektna_naloga/web_server/models/userModel.js
Normal file
@@ -0,0 +1,45 @@
|
||||
const mongoose = require('mongoose');
|
||||
const bcrypt = require('bcrypt');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const userSchema = new Schema({
|
||||
'username': String,
|
||||
'password': String,
|
||||
'email': String,
|
||||
'locations': Array
|
||||
});
|
||||
|
||||
userSchema.pre('save', function (next) {
|
||||
const user = this;
|
||||
bcrypt.hash(user.password, 10, function (err, hash) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
user.password = hash;
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
userSchema.statics.authenticate = function (username, password, callback) {
|
||||
User.findOne({ username: username })
|
||||
.exec(function (err, user) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
} else if (!user) {
|
||||
const err = new Error("User not found.");
|
||||
err.status = 401;
|
||||
return callback(err);
|
||||
}
|
||||
bcrypt.compare(password, user.password, function (err, result) {
|
||||
if (result === true) {
|
||||
return callback(null, user);
|
||||
} else {
|
||||
return callback();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
const User = mongoose.model('user', userSchema);
|
||||
module.exports = User;
|
3145
projektna_naloga/web_server/package-lock.json
generated
Normal file
3145
projektna_naloga/web_server/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
projektna_naloga/web_server/package.json
Normal file
20
projektna_naloga/web_server/package.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "backend",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "node ./bin/www",
|
||||
"dev": "nodemon ./bin/www"
|
||||
},
|
||||
"dependencies": {
|
||||
"bcrypt": "^5.1.0",
|
||||
"connect-mongo": "^5.0.0",
|
||||
"cookie-parser": "~1.4.4",
|
||||
"debug": "~2.6.9",
|
||||
"express": "^4.18.2",
|
||||
"hbs": "^4.2.0",
|
||||
"http-errors": "~1.6.3",
|
||||
"mongoose": "^6.9.0",
|
||||
"morgan": "~1.9.1"
|
||||
}
|
||||
}
|
13
projektna_naloga/web_server/public/asset-manifest.json
Normal file
13
projektna_naloga/web_server/public/asset-manifest.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"files": {
|
||||
"main.css": "/static/css/main.2fc7e52d.css",
|
||||
"main.js": "/static/js/main.f2c1d8c3.js",
|
||||
"index.html": "/index.html",
|
||||
"main.2fc7e52d.css.map": "/static/css/main.2fc7e52d.css.map",
|
||||
"main.f2c1d8c3.js.map": "/static/js/main.f2c1d8c3.js.map"
|
||||
},
|
||||
"entrypoints": [
|
||||
"static/css/main.2fc7e52d.css",
|
||||
"static/js/main.f2c1d8c3.js"
|
||||
]
|
||||
}
|
BIN
projektna_naloga/web_server/public/favicon.ico
Normal file
BIN
projektna_naloga/web_server/public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 66 KiB |
25
projektna_naloga/web_server/public/manifest.json
Normal file
25
projektna_naloga/web_server/public/manifest.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
3
projektna_naloga/web_server/public/robots.txt
Normal file
3
projektna_naloga/web_server/public/robots.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,99 @@
|
||||
/* @preserve
|
||||
* Leaflet 1.9.3, a JS library for interactive maps. https://leafletjs.com
|
||||
* (c) 2010-2022 Vladimir Agafonkin, (c) 2010-2011 CloudMade
|
||||
*/
|
||||
|
||||
/*!
|
||||
Copyright (c) 2018 Jed Watson.
|
||||
Licensed under the MIT License (MIT), see
|
||||
http://jedwatson.github.io/classnames
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @kurkle/color v0.3.2
|
||||
* https://github.com/kurkle/color#readme
|
||||
* (c) 2023 Jukka Kurkela
|
||||
* Released under the MIT License
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Chart.js v4.3.0
|
||||
* https://www.chartjs.org
|
||||
* (c) 2023 Chart.js Contributors
|
||||
* Released under the MIT License
|
||||
*/
|
||||
|
||||
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
||||
|
||||
/**
|
||||
* @license React
|
||||
* react-dom.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license React
|
||||
* react-jsx-runtime.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license React
|
||||
* react.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license React
|
||||
* scheduler.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @remix-run/router v1.6.1
|
||||
*
|
||||
* Copyright (c) Remix Software Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE.md file in the root directory of this source tree.
|
||||
*
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* React Router DOM v6.11.1
|
||||
*
|
||||
* Copyright (c) Remix Software Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE.md file in the root directory of this source tree.
|
||||
*
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* React Router v6.11.1
|
||||
*
|
||||
* Copyright (c) Remix Software Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE.md file in the root directory of this source tree.
|
||||
*
|
||||
* @license MIT
|
||||
*/
|
File diff suppressed because one or more lines are too long
13
projektna_naloga/web_server/routes/counterRouter.js
Normal file
13
projektna_naloga/web_server/routes/counterRouter.js
Normal file
@@ -0,0 +1,13 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const cameras = require('../data/cameras.json')
|
||||
|
||||
let count = 0;
|
||||
router.get('/', (req, res) => {
|
||||
count++;
|
||||
const i = count % cameras.length;
|
||||
const camera = cameras[i];
|
||||
return res.json(camera);
|
||||
});
|
||||
|
||||
module.exports = router;
|
30
projektna_naloga/web_server/routes/dailyDataRoutes.js
Normal file
30
projektna_naloga/web_server/routes/dailyDataRoutes.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const dailyDataController = require('../controllers/dailyDataController.js');
|
||||
|
||||
/*
|
||||
* GET
|
||||
*/
|
||||
router.get('/', dailyDataController.list);
|
||||
|
||||
/*
|
||||
* GET
|
||||
*/
|
||||
//router.get('/:id', dailyDataController.show);
|
||||
|
||||
/*
|
||||
* POST
|
||||
*/
|
||||
router.post('/', dailyDataController.create);
|
||||
|
||||
/*
|
||||
* PUT
|
||||
*/
|
||||
//router.put('/:id', dailyDataController.update);
|
||||
|
||||
/*
|
||||
* DELETE
|
||||
*/
|
||||
router.delete('/:id', dailyDataController.remove);
|
||||
|
||||
module.exports = router;
|
24
projektna_naloga/web_server/routes/dataRouter.js
Normal file
24
projektna_naloga/web_server/routes/dataRouter.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const hourlyDataController = require('../controllers/hourlyDataController.js');
|
||||
const dailyDataController = require('../controllers/dailyDataController.js');
|
||||
|
||||
let testData = true;
|
||||
|
||||
|
||||
|
||||
if (testData) {
|
||||
router.get('/year/:year/month/:month/day/:day/location/:location', hourlyDataController.showLocationTest);
|
||||
router.get('/year/:year/month/:month/day/:day/hour/:hour', hourlyDataController.showHourTest);
|
||||
router.get('/year/:year/month/:month/day/:day/hour/:hour/csv', hourlyDataController.showHourCsvTest);
|
||||
router.get('/year/:year/month/:month/location/:location', dailyDataController.showLocationTest);
|
||||
} else {
|
||||
router.get('/year/:year/month/:month/day/:day/location/:location', hourlyDataController.showLocation);
|
||||
router.get('/year/:year/month/:month/day/:day/hour/:hour', hourlyDataController.showHour);
|
||||
router.get('/year/:year/month/:month/day/:day/hour/:hour/csv', hourlyDataController.showHourCsv);
|
||||
router.get('/year/:year/month/:month/location/:location', dailyDataController.showLocation);
|
||||
}
|
||||
|
||||
// router.get('/year/:year/month/:month/day/:day', dailyDataController.showDay);
|
||||
|
||||
module.exports = router;
|
30
projektna_naloga/web_server/routes/hourlyDataRoutes.js
Normal file
30
projektna_naloga/web_server/routes/hourlyDataRoutes.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const hourlyDataController = require('../controllers/hourlyDataController.js');
|
||||
|
||||
/*
|
||||
* GET
|
||||
*/
|
||||
router.get('/', hourlyDataController.list);
|
||||
|
||||
/*
|
||||
* GET
|
||||
*/
|
||||
//router.get('/:location', hourlyDataController.show);
|
||||
|
||||
/*
|
||||
* POST
|
||||
*/
|
||||
router.post('/', hourlyDataController.create);
|
||||
|
||||
/*
|
||||
* PUT
|
||||
*/
|
||||
//router.put('/:id', hourlyDataController.update);
|
||||
|
||||
/*
|
||||
* DELETE
|
||||
*/
|
||||
router.delete('/:id', hourlyDataController.remove);
|
||||
|
||||
module.exports = router;
|
11
projektna_naloga/web_server/routes/locationRoutes.js
Normal file
11
projektna_naloga/web_server/routes/locationRoutes.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const locationController = require('../controllers/locationController.js');
|
||||
|
||||
router.get('/', locationController.list);
|
||||
|
||||
router.get('/csv', locationController.csv);
|
||||
|
||||
router.get('/:id', locationController.show);
|
||||
|
||||
module.exports = router;
|
30
projektna_naloga/web_server/routes/rawCameraDataRoutes.js
Normal file
30
projektna_naloga/web_server/routes/rawCameraDataRoutes.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const rawCameraDataController = require('../controllers/rawCameraDataController.js');
|
||||
|
||||
/*
|
||||
* GET
|
||||
*/
|
||||
router.get('/', rawCameraDataController.list);
|
||||
|
||||
/*
|
||||
* GET
|
||||
*/
|
||||
router.get('/:id', rawCameraDataController.show);
|
||||
|
||||
/*
|
||||
* POST
|
||||
*/
|
||||
router.post('/', rawCameraDataController.create);
|
||||
|
||||
/*
|
||||
* PUT
|
||||
*/
|
||||
//router.put('/:id', rawCameraDataController.update);
|
||||
|
||||
/*
|
||||
* DELETE
|
||||
*/
|
||||
router.delete('/delete/:id', rawCameraDataController.remove);
|
||||
|
||||
module.exports = router;
|
20
projektna_naloga/web_server/routes/userRoutes.js
Normal file
20
projektna_naloga/web_server/routes/userRoutes.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const userController = require('../controllers/userController.js');
|
||||
|
||||
|
||||
router.get('/', userController.list);
|
||||
router.get('/profile', userController.profile);
|
||||
router.get('/logout', userController.logout);
|
||||
router.get('/savedLocation', userController.checkLocation);
|
||||
router.get('/:id', userController.show);
|
||||
|
||||
router.post('/', userController.create);
|
||||
router.post('/login', userController.login);
|
||||
|
||||
router.put('/addLocation/:id', userController.addLocation);
|
||||
router.put('/:id', userController.update);
|
||||
|
||||
router.delete('/:id', userController.remove);
|
||||
|
||||
module.exports = router;
|
3
projektna_naloga/web_server/views/error.hbs
Normal file
3
projektna_naloga/web_server/views/error.hbs
Normal file
@@ -0,0 +1,3 @@
|
||||
<h1>{{message}}</h1>
|
||||
<h2>{{error.status}}</h2>
|
||||
<pre>{{error.stack}}</pre>
|
27
projektna_naloga/web_server/views/layout.hbs
Normal file
27
projektna_naloga/web_server/views/layout.hbs
Normal file
@@ -0,0 +1,27 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta name="description" content="Web site created using create-react-app" />
|
||||
<link rel="apple-touch-icon" href="/logo192.png" />
|
||||
<link rel="manifest" href="/manifest.json" />
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||
integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"
|
||||
integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe"
|
||||
crossorigin="anonymous"></script>
|
||||
<title>Highway Tracker</title>
|
||||
<script defer="defer" src="/static/js/main.2cf4ff7a.js"></script>
|
||||
<link href="/static/css/main.2fc7e52d.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body><noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
|
||||
</html>
|
Reference in New Issue
Block a user