This repository has no description
1import { Router } from 'express';
2import { AddUrlToLibraryController } from '../controllers/AddUrlToLibraryController';
3import { AddCardToLibraryController } from '../controllers/AddCardToLibraryController';
4import { AddCardToCollectionController } from '../controllers/AddCardToCollectionController';
5import { UpdateNoteCardController } from '../controllers/UpdateNoteCardController';
6import { RemoveCardFromLibraryController } from '../controllers/RemoveCardFromLibraryController';
7import { RemoveCardFromCollectionController } from '../controllers/RemoveCardFromCollectionController';
8import { GetUrlMetadataController } from '../controllers/GetUrlMetadataController';
9import { GetUrlCardViewController } from '../controllers/GetUrlCardViewController';
10import { GetLibrariesForCardController } from '../controllers/GetLibrariesForCardController';
11import { GetMyUrlCardsController } from '../controllers/GetMyUrlCardsController';
12import { GetUserUrlCardsController } from '../controllers/GetUserUrlCardsController';
13import { GetUrlStatusForMyLibraryController } from '../controllers/GetUrlStatusForMyLibraryController';
14import { AuthMiddleware } from 'src/shared/infrastructure/http/middleware';
15
16export function createCardRoutes(
17 authMiddleware: AuthMiddleware,
18 addUrlToLibraryController: AddUrlToLibraryController,
19 addCardToLibraryController: AddCardToLibraryController,
20 addCardToCollectionController: AddCardToCollectionController,
21 updateNoteCardController: UpdateNoteCardController,
22 removeCardFromLibraryController: RemoveCardFromLibraryController,
23 removeCardFromCollectionController: RemoveCardFromCollectionController,
24 getUrlMetadataController: GetUrlMetadataController,
25 getUrlCardViewController: GetUrlCardViewController,
26 getLibrariesForCardController: GetLibrariesForCardController,
27 getMyUrlCardsController: GetMyUrlCardsController,
28 getUserUrlCardsController: GetUserUrlCardsController,
29 getUrlStatusForMyLibraryController: GetUrlStatusForMyLibraryController,
30): Router {
31 const router = Router();
32
33 // Query routes
34 // GET /api/cards/metadata - Get URL metadata
35 router.get('/metadata', authMiddleware.optionalAuth(), (req, res) =>
36 getUrlMetadataController.execute(req, res),
37 );
38
39 // GET /api/cards/my - Get my URL cards
40 router.get('/my', authMiddleware.ensureAuthenticated(), (req, res) =>
41 getMyUrlCardsController.execute(req, res),
42 );
43
44 // GET /api/cards/library/status - Get URL status for my library
45 router.get(
46 '/library/status',
47 authMiddleware.ensureAuthenticated(),
48 (req, res) => getUrlStatusForMyLibraryController.execute(req, res),
49 );
50
51 // GET /api/cards/user/:identifier - Get user's URL cards by identifier
52 router.get('/user/:identifier', authMiddleware.optionalAuth(), (req, res) =>
53 getUserUrlCardsController.execute(req, res),
54 );
55
56 // GET /api/cards/:cardId - Get URL card view
57 router.get('/:cardId', authMiddleware.optionalAuth(), (req, res) =>
58 getUrlCardViewController.execute(req, res),
59 );
60
61 // GET /api/cards/:cardId/libraries - Get libraries for card
62 router.get('/:cardId/libraries', authMiddleware.optionalAuth(), (req, res) =>
63 getLibrariesForCardController.execute(req, res),
64 );
65
66 // Command routes
67 // POST /api/cards/library/urls - Add URL to library (with optional note and collections)
68 router.post(
69 '/library/urls',
70 authMiddleware.ensureAuthenticated(),
71 (req, res) => addUrlToLibraryController.execute(req, res),
72 );
73
74 // POST /api/cards/library - Add existing card to library
75 router.post('/library', authMiddleware.ensureAuthenticated(), (req, res) =>
76 addCardToLibraryController.execute(req, res),
77 );
78
79 // POST /api/cards/collections - Add card to collections
80 router.post(
81 '/collections',
82 authMiddleware.ensureAuthenticated(),
83 (req, res) => addCardToCollectionController.execute(req, res),
84 );
85
86 // PUT /api/cards/:cardId/note - Update note card content
87 router.put(
88 '/:cardId/note',
89 authMiddleware.ensureAuthenticated(),
90 (req, res) => updateNoteCardController.execute(req, res),
91 );
92
93 // DELETE /api/cards/:cardId/library - Remove card from user's library
94 router.delete(
95 '/:cardId/library',
96 authMiddleware.ensureAuthenticated(),
97 (req, res) => removeCardFromLibraryController.execute(req, res),
98 );
99
100 // DELETE /api/cards/:cardId/collections - Remove card from specified collections
101 router.delete(
102 '/:cardId/collections',
103 authMiddleware.ensureAuthenticated(),
104 (req, res) => removeCardFromCollectionController.execute(req, res),
105 );
106
107 return router;
108}