Skip to content

Commit

Permalink
DN-4: Sending post path in query param since it was thinking it was a…
Browse files Browse the repository at this point in the history
…n end point.
  • Loading branch information
dereckmezquita committed Jul 15, 2024
1 parent 7bb24ed commit 7c9f4fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/src/app/test/api/demos/comments/CommentsDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function CommentsDemo() {
try {
const encodedPathname = encodeURIComponent(pathname);
const response = await api.get<CommentsResponse>(
`/comments/${encodedPathname}?page=${page}&limit=10`
`/comments?post=${encodedPathname}&page=${page}&limit=10`
);
setComments((prevComments) => [
...prevComments,
Expand Down
9 changes: 6 additions & 3 deletions server/src/routes/comments/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ const router = express.Router();
/**
* Allows fetching top-level comments and replies
*/
router.get('/comments/:post', async (req: Request, res: Response) => {
const { post } = req.params;
const { depth = 1, limit = 10, page = 1 } = req.query;
router.get('/comments', async (req: Request, res: Response) => {
const { post, depth = 1, limit = 10, page = 1 } = req.query;

if (!post || typeof post !== 'string') {
return res.status(400).json({ message: 'Post parameter is required' });
}

const decodedPost = decodeURIComponent(post);

Expand Down

0 comments on commit 7c9f4fd

Please sign in to comment.