From 13b0cae09e9509de8f58281cdf7c747154640700 Mon Sep 17 00:00:00 2001 From: subinqkim Date: Fri, 26 Jan 2024 15:07:33 -0800 Subject: [PATCH 1/4] init branch --- routes/catalog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/catalog.js b/routes/catalog.js index 6d914b2..aaf6593 100644 --- a/routes/catalog.js +++ b/routes/catalog.js @@ -4,7 +4,7 @@ const { db } = require('../server/db'); const catalogRouter = express.Router(); const { keysToCamel } = require('../common/utils'); - +// modify /catalog // -- GET - Returns all data from the catalog table catalogRouter.get('/', async (req, res) => { try { From 492c83c0989ba5d0912c5ab0197739fa80908863 Mon Sep 17 00:00:00 2001 From: subinqkim Date: Wed, 31 Jan 2024 13:54:53 -0800 Subject: [PATCH 2/4] modified get route to take in req.query w/ fields title, subject, event_type, season, and year --- routes/catalog.js | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/routes/catalog.js b/routes/catalog.js index aaf6593..5eb767a 100644 --- a/routes/catalog.js +++ b/routes/catalog.js @@ -8,8 +8,47 @@ const { keysToCamel } = require('../common/utils'); // -- GET - Returns all data from the catalog table catalogRouter.get('/', async (req, res) => { try { - const allInfo = await db.query(`SELECT * from catalog;`); - res.status(200).json(keysToCamel(allInfo)); + const { title, eventType, subject, season, year } = req.query; + let query = 'SELECT * FROM catalog WHERE 1=1'; + const params = []; + + if (title) { + query += ' AND title = $1'; + params.push(title); + } else { + params.push(''); + } + + if (subject) { + query += ' AND subject = $2'; + params.push(subject); + } else { + params.push(''); + } + + if (eventType) { + query += ' AND event_type = $3'; + params.push(eventType); + } else { + params.push(''); + } + + if (season) { + query += ' AND season = $4'; + params.push(season); + } else { + params.push(''); + } + + if (year) { + query += ' AND year = $5'; + params.push(year); + } else { + params.push(''); + } + + const reqInfo = await db.query(query, params); + res.status(200).json(keysToCamel(reqInfo)); } catch (err) { res.status(500).send(err.message); } From aa48acc1317c46264dd97e0e505fe2c498fda2e8 Mon Sep 17 00:00:00 2001 From: subinqkim Date: Wed, 31 Jan 2024 14:04:02 -0800 Subject: [PATCH 3/4] ordered by title in ascending order --- routes/catalog.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/routes/catalog.js b/routes/catalog.js index 5eb767a..a0080a4 100644 --- a/routes/catalog.js +++ b/routes/catalog.js @@ -47,6 +47,8 @@ catalogRouter.get('/', async (req, res) => { params.push(''); } + query += ' ORDER BY title ASC'; + const reqInfo = await db.query(query, params); res.status(200).json(keysToCamel(reqInfo)); } catch (err) { From 043f0f593fb845cd32b624b87d7f36195bc77834 Mon Sep 17 00:00:00 2001 From: subinqkim Date: Sat, 3 Feb 2024 12:13:03 -0800 Subject: [PATCH 4/4] = changed to ILIKE op for title input --- routes/catalog.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/catalog.js b/routes/catalog.js index a0080a4..2c5ed3a 100644 --- a/routes/catalog.js +++ b/routes/catalog.js @@ -13,8 +13,8 @@ catalogRouter.get('/', async (req, res) => { const params = []; if (title) { - query += ' AND title = $1'; - params.push(title); + query += ' AND title ILIKE $1'; + params.push(`%${title}%`); } else { params.push(''); }