-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisting.js
41 lines (34 loc) · 1.12 KB
/
listing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const express = require("express");
const router = express.Router();
const wrapAsync = require("../utils/wrapAsync.js");
const Listing = require("../models/listing.js");
const { isLoggedIn, isOwner, validateListing } = require("../middleware.js");
const listingController = require("../controllers/listing.js");
const multer = require("multer");
const { storage } = require("../cloudConfig.js");
const upload = multer({ storage });
//index route
router.route("/").get(wrapAsync(listingController.index)).post(
isLoggedIn,
upload.single("listing[image]"),
validateListing,
wrapAsync(listingController.create)
);
//new route
router.get("/new", isLoggedIn, listingController.renderNewForm);
//show route
router.get("/:id", wrapAsync(listingController.show));
//edit route
router.get("/:id/edit", isLoggedIn, isOwner, wrapAsync(listingController.edit));
//update route
router.put(
"/:id",
isLoggedIn,
isOwner,
upload.single("listing[image]"),
validateListing,
wrapAsync(listingController.update)
);
//delete route
router.delete("/:id", isLoggedIn, isOwner, wrapAsync(listingController.delete));
module.exports = router;