From 7617f6c54e6a1a85dea6b5f59d2077e7b1484456 Mon Sep 17 00:00:00 2001 From: ctc-devops <90984711+ctc-devops@users.noreply.github.com> Date: Thu, 25 Jan 2024 16:13:32 -0800 Subject: [PATCH 1/6] Create a pull trequest for branch 36-retreive-published-schedule-events-by-season From 1310260211da4dfe2f82b6cec81329d8a90c26bf Mon Sep 17 00:00:00 2001 From: Cheryl Chen Date: Thu, 25 Jan 2024 17:36:55 -0800 Subject: [PATCH 2/6] added season/year routes (untested) --- routes/publishedSchedule.js | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index 6793999..d43c3cb 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -30,6 +30,74 @@ publishedScheduleRouter.get('/', async (req, res) => { } }); +// GET /published-schedule/season - returns rows that match the season +publishedScheduleRouter.get('/season', async (req, res) => { + try { + const { year, season } = req.query; + const seasonResult = await db.query( + ` + WITH seasonPS AS + ( + SELECT + PS.id, + C.title, + C.event_type, + C.year, + PS.start_time, + PS.end_time, + PS.confirmed, + PS.confirmed_on, + PS.cohort, + PS.notes + FROM published_schedule PS + LEFT JOIN catalog C ON PS.event_id = C.id + WHERE + C.season = $1 AND + EXTRACT(YEAR FROM PS.start_time) = $2 + ) + SELECT seasonPS.start_time, JSON_AGG(seasonPS.*) AS data + FROM seasonPS + GROUP BY start_time + ORDER BY start_time ASC; + `, + [season, year], + ); + res.status(200).json(keysToCamel(seasonResult)); + } catch (err) { + res.status(400).send(err.message); + } +}); + +// GET /published-schedule/date - returns all events occurring on a specific date +publishedScheduleRouter.get('/date', async (req, res) => { + try { + const { date } = req.query; + const seasonResult = await db.query( + ` + SELECT + PS.id, + C.title, + C.event_type, + C.year, + PS.start_time, + PS.end_time, + PS.confirmed, + PS.confirmed_on, + PS.cohort, + PS.notes + FROM published_schedule PS + LEFT JOIN catalog C ON PS.event_id = C.id + DATE(PS.start_time) = $1 + ORDER BY start_time ASC; + `, + [date], + ); + res.status(200).json(keysToCamel(seasonResult)); + } catch (err) { + res.status(400).send(err.message); + } +}); + // GET/:id - returns the rows that match the given id publishedScheduleRouter.get('/:id', async (req, res) => { try { From 4e0682e05c59637b0b984e38ad9f4cf1ebbe433a Mon Sep 17 00:00:00 2001 From: Cheryl Chen Date: Mon, 29 Jan 2024 16:39:11 -0800 Subject: [PATCH 3/6] group by date instead of timestamp --- routes/publishedSchedule.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index d43c3cb..18b5c44 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -33,7 +33,7 @@ publishedScheduleRouter.get('/', async (req, res) => { // GET /published-schedule/season - returns rows that match the season publishedScheduleRouter.get('/season', async (req, res) => { try { - const { year, season } = req.query; + const { season, year } = req.query; const seasonResult = await db.query( ` WITH seasonPS AS @@ -55,10 +55,10 @@ publishedScheduleRouter.get('/season', async (req, res) => { C.season = $1 AND EXTRACT(YEAR FROM PS.start_time) = $2 ) - SELECT seasonPS.start_time, JSON_AGG(seasonPS.*) AS data + SELECT DATE(seasonPS.start_time), JSON_AGG(seasonPS.*) AS data FROM seasonPS - GROUP BY start_time - ORDER BY start_time ASC; + GROUP BY DATE(start_time) + ORDER BY DATE(start_time) ASC; `, [season, year], ); From 1cc91b644db97fd07da7de1dbe811f372690d5d4 Mon Sep 17 00:00:00 2001 From: Cheryl Chen Date: Fri, 2 Feb 2024 10:59:22 -0800 Subject: [PATCH 4/6] mapped season to month --- routes/publishedSchedule.js | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index 18b5c44..8073522 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -33,7 +33,38 @@ publishedScheduleRouter.get('/', async (req, res) => { // GET /published-schedule/season - returns rows that match the season publishedScheduleRouter.get('/season', async (req, res) => { try { + // start and end times for the first interval (ie. JAN 1 2012 -> FEB 29 2012) + let startTime; + let endTime; + // start and end times for the second interval (ie. DEC 1 2012 -> DEC 31 2012) + let secondstartTime; + let secondendTime; + const { season, year } = req.query; + + // getting the intervals for each season + if (season.toLowerCase() === 'winter') { + startTime = `${year}-01-01`; + endTime = `${year}-02-29`; + secondstartTime = `${year}-12-01`; + secondendTime = `${year}-12-31`; + } else if (season.toLowerCase() === 'spring') { + startTime = `${year}-03-01`; + endTime = `${year}-05-31`; + secondstartTime = `${year}-03-01`; + secondendTime = `${year}-05-31`; + } else if (season.toLowerCase() === 'summer') { + startTime = `${year}-06-01`; + endTime = `${year}-08-31`; + secondstartTime = `${year}-06-01`; + secondendTime = `${year}-08-31`; + } else { + startTime = `${year}-09-01`; + endTime = `${year}-11-30`; + secondstartTime = `${year}-09-01`; + secondendTime = `${year}-11-30`; + } + const seasonResult = await db.query( ` WITH seasonPS AS @@ -52,15 +83,15 @@ publishedScheduleRouter.get('/season', async (req, res) => { FROM published_schedule PS LEFT JOIN catalog C ON PS.event_id = C.id WHERE - C.season = $1 AND - EXTRACT(YEAR FROM PS.start_time) = $2 + (DATE(start_time) >= $1::date AND DATE(start_time) <= $2::date) OR + (DATE(start_time) >= $3::date AND DATE(start_time) <= $4::date) ) SELECT DATE(seasonPS.start_time), JSON_AGG(seasonPS.*) AS data FROM seasonPS GROUP BY DATE(start_time) ORDER BY DATE(start_time) ASC; `, - [season, year], + [startTime, endTime, secondstartTime, secondendTime], ); res.status(200).json(keysToCamel(seasonResult)); } catch (err) { From 1958d443b98b8e235ce8df57a6256430240936c8 Mon Sep 17 00:00:00 2001 From: Cheryl Chen Date: Fri, 2 Feb 2024 11:13:27 -0800 Subject: [PATCH 5/6] fixed mapping december --- routes/publishedSchedule.js | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index 8073522..d275316 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -33,36 +33,24 @@ publishedScheduleRouter.get('/', async (req, res) => { // GET /published-schedule/season - returns rows that match the season publishedScheduleRouter.get('/season', async (req, res) => { try { - // start and end times for the first interval (ie. JAN 1 2012 -> FEB 29 2012) let startTime; let endTime; - // start and end times for the second interval (ie. DEC 1 2012 -> DEC 31 2012) - let secondstartTime; - let secondendTime; const { season, year } = req.query; // getting the intervals for each season if (season.toLowerCase() === 'winter') { - startTime = `${year}-01-01`; + startTime = `${year - 1}-12-01`; endTime = `${year}-02-29`; - secondstartTime = `${year}-12-01`; - secondendTime = `${year}-12-31`; } else if (season.toLowerCase() === 'spring') { startTime = `${year}-03-01`; endTime = `${year}-05-31`; - secondstartTime = `${year}-03-01`; - secondendTime = `${year}-05-31`; } else if (season.toLowerCase() === 'summer') { startTime = `${year}-06-01`; endTime = `${year}-08-31`; - secondstartTime = `${year}-06-01`; - secondendTime = `${year}-08-31`; } else { startTime = `${year}-09-01`; endTime = `${year}-11-30`; - secondstartTime = `${year}-09-01`; - secondendTime = `${year}-11-30`; } const seasonResult = await db.query( @@ -83,15 +71,14 @@ publishedScheduleRouter.get('/season', async (req, res) => { FROM published_schedule PS LEFT JOIN catalog C ON PS.event_id = C.id WHERE - (DATE(start_time) >= $1::date AND DATE(start_time) <= $2::date) OR - (DATE(start_time) >= $3::date AND DATE(start_time) <= $4::date) + DATE(start_time) >= $1::date AND DATE(start_time) <= $2::date ) SELECT DATE(seasonPS.start_time), JSON_AGG(seasonPS.*) AS data FROM seasonPS GROUP BY DATE(start_time) ORDER BY DATE(start_time) ASC; `, - [startTime, endTime, secondstartTime, secondendTime], + [startTime, endTime], ); res.status(200).json(keysToCamel(seasonResult)); } catch (err) { From 240d2a6847ed7606b30419f270f3449c5cea017a Mon Sep 17 00:00:00 2001 From: michellelin1 Date: Sun, 4 Feb 2024 20:03:40 -0800 Subject: [PATCH 6/6] added where clause --- routes/publishedSchedule.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index d275316..43c8376 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -57,7 +57,7 @@ publishedScheduleRouter.get('/season', async (req, res) => { ` WITH seasonPS AS ( - SELECT + SELECT PS.id, C.title, C.event_type, @@ -70,7 +70,7 @@ publishedScheduleRouter.get('/season', async (req, res) => { PS.notes FROM published_schedule PS LEFT JOIN catalog C ON PS.event_id = C.id - WHERE + WHERE DATE(start_time) >= $1::date AND DATE(start_time) <= $2::date ) SELECT DATE(seasonPS.start_time), JSON_AGG(seasonPS.*) AS data @@ -92,7 +92,7 @@ publishedScheduleRouter.get('/date', async (req, res) => { const { date } = req.query; const seasonResult = await db.query( ` - SELECT + SELECT PS.id, C.title, C.event_type, @@ -105,7 +105,7 @@ publishedScheduleRouter.get('/date', async (req, res) => { PS.notes FROM published_schedule PS LEFT JOIN catalog C ON PS.event_id = C.id - DATE(PS.start_time) = $1 + WHERE DATE(PS.start_time) = $1 ORDER BY start_time ASC; `, [date],