forked from pawelmalak/flame
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
100f274
commit 27250dc
Showing
7 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
const asyncWrapper = require('../middleware/asyncWrapper'); | ||
const ErrorResponse = require('../utils/ErrorResponse'); | ||
const Bookmark = require('../models/Bookmark'); | ||
|
||
// @desc Create new bookmark | ||
// @route POST /api/bookmarks | ||
// @access Public | ||
exports.createBookmark = asyncWrapper(async (req, res, next) => { | ||
const bookmark = await Bookmark.create(req.body); | ||
|
||
res.status(201).json({ | ||
success: true, | ||
data: bookmark | ||
}) | ||
}) | ||
|
||
// @desc Get all bookmarks | ||
// @route GET /api/bookmarks | ||
// @access Public | ||
exports.getBookmarks = asyncWrapper(async (req, res, next) => { | ||
const bookmarks = await Bookmark.findAll(); | ||
|
||
res.status(200).json({ | ||
success: true, | ||
data: bookmarks | ||
}) | ||
}) | ||
|
||
// @desc Get single bookmark | ||
// @route GET /api/bookmarks/:id | ||
// @access Public | ||
exports.getBookmark = asyncWrapper(async (req, res, next) => { | ||
const bookmark = await Bookmark.findOne({ | ||
where: { id: req.params.id } | ||
}); | ||
|
||
if (!bookmark) { | ||
return next(new ErrorResponse(`Bookmark with id of ${req.params.id} was not found`, 404)); | ||
} | ||
|
||
res.status(200).json({ | ||
success: true, | ||
data: bookmark | ||
}) | ||
}) | ||
|
||
// @desc Update bookmark | ||
// @route PUT /api/bookmarks/:id | ||
// @access Public | ||
exports.updateBookmark = asyncWrapper(async (req, res, next) => { | ||
let bookmark = await Bookmark.findOne({ | ||
where: { id: req.params.id } | ||
}); | ||
|
||
if (!bookmark) { | ||
return next(new ErrorResponse(`Bookmark with id of ${req.params.id} was not found`, 404)); | ||
} | ||
|
||
bookmark = await bookmark.update({ ...req.body }); | ||
|
||
res.status(200).json({ | ||
success: true, | ||
data: bookmark | ||
}) | ||
}) | ||
|
||
// @desc Delete bookmark | ||
// @route DELETE /api/bookmarks/:id | ||
// @access Public | ||
exports.deleteBookmark = asyncWrapper(async (req, res, next) => { | ||
await Bookmark.destroy({ | ||
where: { id: req.params.id } | ||
}); | ||
|
||
res.status(200).json({ | ||
success: true, | ||
data: {} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
|
||
const { | ||
createBookmark, | ||
getBookmarks, | ||
getBookmark, | ||
updateBookmark, | ||
deleteBookmark | ||
} = require('../controllers/bookmark'); | ||
|
||
router | ||
.route('/') | ||
.post(createBookmark) | ||
.get(getBookmarks); | ||
|
||
router | ||
.route('/:id') | ||
.get(getBookmark) | ||
.put(updateBookmark) | ||
.delete(deleteBookmark); | ||
|
||
module.exports = router; |