diff --git a/controllers/photoController.js b/controllers/photoController.js deleted file mode 100644 index 2d3ecd0..0000000 --- a/controllers/photoController.js +++ /dev/null @@ -1,125 +0,0 @@ -var PhotoModel = require('../models/photoModel.js'); - -/** - * photoController.js - * - * @description :: Server-side logic for managing photos. - */ -module.exports = { - - /** - * photoController.list() - */ - list: function (req, res) { - PhotoModel.find() - .then(photos => { - var data = { - photos: photos - }; - return res.render('photo/list', data); - }) - .catch(err => { - return res.status(500).json({ - message: 'Error when getting photos.', - error: err - }); - }); - }, - - /** - * photoController.show() - */ - show: function (req, res) { - var id = req.params.id; - - PhotoModel.findOne({ _id: id }, function (err, photo) { - if (err) { - return res.status(500).json({ - message: 'Error when getting photo.', - error: err - }); - } - - if (!photo) { - return res.status(404).json({ - message: 'No such photo' - }); - } - - return res.json(photo); - }); - }, - - /** - * photoController.create() - */ - create: function (req, res) { - var photo = new PhotoModel({ - name: req.body.name, - path: "/UpImage/" + req.file.filename, - }); - - photo.save() - .then(savedPhoto => { - // Handle successful save operation - return res.redirect('/photos'); - }) - .catch(err => { - return res.status(500).json({ - message: 'Error when creating photo', - error: err - }); - }); - }, - - /** - * photoController.update() - */ - update: function (req, res) { - var id = req.params.id; - - PhotoModel.findOne({ _id: id }) - .then(photo => { - if (!photo) { - return res.status(404).json({ - message: 'No such photo' - }); - } - - photo.name = req.body.name ? req.body.name : photo.name; - photo.path = req.body.path ? req.body.path : photo.path; - return photo.save(); - }) - .then(updatedPhoto => { - return res.json(updatedPhoto); - }) - .catch(err => { - return res.status(500).json({ - message: 'Error when updating photo.', - error: err - }); - }); - }, - - /** - * photoController.remove() - */ - remove: function (req, res) { - var id = req.params.id; - - PhotoModel.findByIdAndRemove(id, function (err, photo) { - if (err) { - return res.status(500).json({ - message: 'Error when deleting the photo.', - error: err - }); - } - - return res.status(204).json(); - }); - }, - - publish: function (req, res) { - return res.render('photo/publish'); - } -}; diff --git a/models/photoModel.js b/models/photoModel.js deleted file mode 100644 index 3610e01..0000000 --- a/models/photoModel.js +++ /dev/null @@ -1,9 +0,0 @@ -var mongoose = require('mongoose'); -var Schema = mongoose.Schema; - -var photoSchema = new Schema({ - 'name': String, - 'path': String -}); - -module.exports = mongoose.model('photo', photoSchema); diff --git a/package.json b/package.json index 62e1475..8fcbfa1 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,11 @@ "dependencies": { "@mi-sec/wol": "^1.0.13", "express": "^4.18.2", + "@types/express": "^4.17.21", "hbs": "^4.2.0", "http": "^0.0.1-security", "mongoose": "^7.5.2", "morgan": "~1.9.1", - "multer": "^1.4.5-lts.1" + "@types/morgan": "^1.9.9" } -} +} \ No newline at end of file diff --git a/routes/api/apiRouter.js b/routes/api/apiRouter.js index 9e6bc91..5b4cd75 100644 --- a/routes/api/apiRouter.js +++ b/routes/api/apiRouter.js @@ -2,12 +2,10 @@ var express = require('express'); var router = express.Router(); const checkAuthenticated = require('../../middleware/checkAuthenticated.js'); -var photosRouter = require('./photoRouter'); var mediaRouter = require('./mediaRouter'); var gameRouter = require('./gameRouter'); var cashTransactionRouter = require('./cashTransactionRouter'); -router.use('/photos', photosRouter); router.use('/games', gameRouter); router.use('/movies', mediaRouter); router.use('/series', mediaRouter); diff --git a/routes/api/photoRouter.js b/routes/api/photoRouter.js deleted file mode 100644 index 22fc3ee..0000000 --- a/routes/api/photoRouter.js +++ /dev/null @@ -1,20 +0,0 @@ -var express = require('express'); -// Vključimo multer za file upload -var multer = require('multer'); -var upload = multer({ dest: 'public/UpImage/' }); - -var router = express.Router(); -var photoController = require('../../controllers/photoController.js'); - - -router.get('/', photoController.list); -router.get('/publish', photoController.publish); -router.get('/:id', photoController.show); - -router.post('/', upload.single('image'), photoController.create); - -router.put('/:id', photoController.update); - -router.delete('/:id', photoController.remove); - -module.exports = router; diff --git a/views/photo/list.hbs b/views/photo/list.hbs deleted file mode 100644 index 52952ad..0000000 --- a/views/photo/list.hbs +++ /dev/null @@ -1,7 +0,0 @@ -

Slike:

-{{#each photos}} -

slika:

-
-Id: {{id}} -
-{{/each}} \ No newline at end of file diff --git a/views/photo/publish.hbs b/views/photo/publish.hbs deleted file mode 100644 index cb93a80..0000000 --- a/views/photo/publish.hbs +++ /dev/null @@ -1,8 +0,0 @@ -

Dodaj sliko

-
- - -
- -
-
\ No newline at end of file