-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
87 lines (79 loc) · 2.38 KB
/
router.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//This file list urls/routes we looking for in get. post
const express = require("express");
const router = express.Router();
const userController = require("./controllers/userController");
const postController = require("./controllers/postController");
const followController = require("./controllers/followController");
const threadController = require("./controllers/threadController");
// Thread related routes
router.get("/thread", userController.mustBeLoggedIn, threadController.down);
router.post("/thread", userController.mustBeLoggedIn, threadController.create);
router.post("/threads", userController.mustBeLoggedIn, threadController.deleteItem);
router.get("/threads", userController.mustBeLoggedIn, threadController.show);
// User related routes
router.get("/", userController.home);
router.post("/register", userController.register);
router.post("/login", userController.login);
router.post("/logout", userController.logout);
router.post("/doesUsernameExist", userController.doesUsernameExist);
router.post("/doesEmailExist", userController.doesEmailExist);
// Profile related routes
router.get(
"/profile/:username",
userController.ifUserExists,
userController.sharedProfileData,
userController.profilePostsScreen
);
router.get(
"/profile/:username/followers",
userController.ifUserExists,
userController.sharedProfileData,
userController.profileFollowersScreen
);
router.get(
"/profile/:username/following",
userController.ifUserExists,
userController.sharedProfileData,
userController.profileFollowingScreen
);
// post related routes
router.get(
"/create-post",
userController.mustBeLoggedIn,
postController.viewCreateScreen
);
router.post(
"/create-post",
userController.mustBeLoggedIn,
postController.create
);
router.get("/post/:id", postController.viewSingle);
router.get(
"/post/:id/edit",
userController.mustBeLoggedIn,
postController.viewEditScreen
);
router.post(
"/post/:id/edit",
userController.mustBeLoggedIn,
postController.edit
);
router.post(
"/post/:id/delete",
userController.mustBeLoggedIn,
postController.delete
);
router.post("/search", postController.search);
// Follow related routes
router.post(
"/addFollow/:username",
userController.mustBeLoggedIn,
followController.addFollow
);
router.post(
"/removeFollow/:username",
userController.mustBeLoggedIn,
followController.removeFollow
);
//Export router
module.exports = router;