From 3bc166bfb0cb7dcf2a01297c04ff5d3655fbd5d7 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Thu, 7 Apr 2022 13:35:36 +0300 Subject: [PATCH] add route to get all channels --- src/routes/api/v1/channels.ts | 10 ++++++++++ test.rest | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/routes/api/v1/channels.ts b/src/routes/api/v1/channels.ts index 0352c07..7ab2a5f 100644 --- a/src/routes/api/v1/channels.ts +++ b/src/routes/api/v1/channels.ts @@ -122,4 +122,14 @@ router.get( } ); +router.get( + "/", + authenticateRoute(), + async (req, res) => { + const result = await query("SELECT id, name, owner_id FROM channels"); + + return res.status(200).send(result.rows); + } +); + export default router; \ No newline at end of file diff --git a/test.rest b/test.rest index c10fe23..4911d6f 100644 --- a/test.rest +++ b/test.rest @@ -28,7 +28,7 @@ content-type: application/json Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidHlwZSI6MSwiaWF0IjoxNjQ5MTg3MDc5LCJleHAiOjE2NDkzNTk4Nzl9.tVzJWnBP7IFhA88XRwByKGXQ4cihWdJSoxUkrWHkIVU { - "name": "my channel" + "name": "another channel" } ### @@ -52,3 +52,8 @@ Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidHlwZSI6M GET http://localhost:3000/api/v1/channels/1 HTTP/1.1 Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidHlwZSI6MSwiaWF0IjoxNjQ5MTg3MDc5LCJleHAiOjE2NDkzNTk4Nzl9.tVzJWnBP7IFhA88XRwByKGXQ4cihWdJSoxUkrWHkIVU + +### + +GET http://localhost:3000/api/v1/channels HTTP/1.1 +Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidHlwZSI6MSwiaWF0IjoxNjQ5MTg3MDc5LCJleHAiOjE2NDkzNTk4Nzl9.tVzJWnBP7IFhA88XRwByKGXQ4cihWdJSoxUkrWHkIVU