Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/ccci-stolaf-college/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ api.get('/transit/modes', transit.modes)
// streams
api.get('/streams/archived', streams.archived)
api.get('/streams/upcoming', streams.upcoming)
api.get('/streams/search', streams.search)

// stoprint
api.get('/printing/color-printers', printing.colorPrinters)
Expand Down
23 changes: 22 additions & 1 deletion source/ccci-stolaf-college/v1/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const GetStreamsParamsSchema = z.object({
dateFrom: z.string().date().optional(),
dateTo: z.string().date().optional(),
sort: z.enum(['ascending', 'descending']).default('ascending'),
query: z.string().optional(),
})

type StOlafStreamsParamsType = z.infer<typeof StOlafStreamsParamsSchema>
Expand All @@ -39,10 +40,11 @@ const StOlafStreamsParamsSchema = z.object({
date_to: z.string().date(),
sort: z.enum(['ascending', 'descending']),
class: z.enum(['current', 'archived']),
squery: z.string().optional(),
})

const getStreams = mem(
async (params: StOlafStreamsParamsType) => {
async (params: StOlafStreamsParamsType & { squery?: string }) => {
const url = 'https://www.stolaf.edu/multimedia/api/collection'
const response = await get(url, {searchParams: params})
const json = (await response.clone().json()) as Promise<
Expand Down Expand Up @@ -94,3 +96,22 @@ export async function archived(ctx: Context) {
sort,
})
}

export async function search(ctx: Context) {
ctx.cacheControl(ONE_HOUR)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have an issue with caching with this endpoint? I'm seeing stale results on subsequent searches

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot could you look into whether there are caching concerns with the way this pull request is changing things for a search endpoint?


const {
dateFrom = moment().subtract(30, 'year').tz('America/Chicago').format('YYYY-MM-DD'),
dateTo = moment().tz('America/Chicago').format('YYYY-MM-DD'),
sort,
query,
} = GetStreamsParamsSchema.parse(Object.fromEntries(ctx.URL.searchParams.entries()))

ctx.body = await getStreams({
class: 'archived',
date_from: dateFrom,
date_to: dateTo,
sort,
...(query ? { squery: query } : {}),
})
}