forked from pedroavpereira/bookswap-api
-
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
217e5ef
commit 9c73009
Showing
2 changed files
with
44 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,49 @@ | ||
const Wishlist = require('../models/Wishlist'); | ||
const Wishlist = require("../models/Wishlist"); | ||
|
||
async function create(req, res) { | ||
try { | ||
const data = req.body; | ||
const newWishlist = await Wishlist.create(data); | ||
res.status(201).json(newWishlist); | ||
} catch (err) { | ||
console.error("Error creating review:", err); | ||
res.status(400).json({ error: err.message || "An unknown error occurred" }); | ||
} | ||
try { | ||
const data = req.body; | ||
const newWishlist = await Wishlist.create(data); | ||
res.status(201).json(newWishlist); | ||
} catch (err) { | ||
console.error("Error creating review:", err); | ||
res.status(400).json({ error: err.message || "An unknown error occurred" }); | ||
} | ||
} | ||
|
||
// show function: | ||
async function show(req, res) { | ||
try { | ||
const userId = parseInt(req.params.user_id); | ||
const wishlists= await Wishlist.findByUserId(userId); | ||
res.status(200).json(wishlists); | ||
} catch (err) { | ||
console.error("Error fetching wishlists:", err); | ||
res.status(404).json({ error: err.message || "Wishlists not found." }); | ||
} | ||
try { | ||
const userId = parseInt(req.params.user_id); | ||
const wishlists = await Wishlist.findByUserId(userId); | ||
res.status(200).json(wishlists); | ||
} catch (err) { | ||
console.error("Error fetching wishlists:", err); | ||
res.status(404).json({ error: err.message || "Wishlists not found." }); | ||
} | ||
} | ||
|
||
async function showMine(req, res) { | ||
try { | ||
const userId = req.user_id; | ||
const wishlists = await Wishlist.findByUserId(userId); | ||
res.status(200).json(wishlists); | ||
} catch (err) { | ||
console.error("Error fetching wishlists:", err); | ||
res.status(404).json({ error: err.message || "Wishlists not found." }); | ||
} | ||
} | ||
|
||
async function destroy(req, res) { | ||
try { | ||
const wishlistId = parseInt(req.params.wishlist_id); | ||
const wishlist= await Wishlist.findByWishlistId(wishlistId); | ||
await wishlist.destroy(); | ||
res.status(204).end(); | ||
} catch (err) { | ||
console.error("Error deleting wishlist:", err); | ||
res.status(404).json({ error: err.message || "Wishlist not found" }); | ||
} | ||
try { | ||
const wishlistId = parseInt(req.params.wishlist_id); | ||
const wishlist = await Wishlist.findByWishlistId(wishlistId); | ||
await wishlist.destroy(); | ||
res.status(204).end(); | ||
} catch (err) { | ||
console.error("Error deleting wishlist:", err); | ||
res.status(404).json({ error: err.message || "Wishlist not found" }); | ||
} | ||
} | ||
|
||
module.exports = { create, show, destroy }; | ||
module.exports = { create, show, destroy, showMine }; |
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