Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate date query schema across endpoints #74

Closed
andrew-wang0 opened this issue Jan 10, 2025 · 1 comment
Closed

Consolidate date query schema across endpoints #74

andrew-wang0 opened this issue Jan 10, 2025 · 1 comment

Comments

@andrew-wang0
Copy link
Member

andrew-wang0 commented Jan 10, 2025

Follow up to #73

Possible Solution

See #73, but apply this to the date param

@laggycomputer
Copy link
Member

The choices currently available are z.coerce.date() (WebSoc endpoints) and z.string().openapi({ format: "date-time" }) (study room endpoints). Note that all dates are simply marked as strings in GraphQL.

andrew-wang0 added a commit that referenced this issue Jan 15, 2025
## Description

Adds study room slots and availability to study room endpoint.

As previously implemented in the data pipeline, availability is
available in on the days between the day of the current time in UCI's
timezone (`America/Los_Angeles`) and exactly 3 days later, inclusive.
Data is updated every 2 minutes.

This PR simply exposes that data. We use ISO 8601 dates ~~(most
precisely, `z.string().datetime({ local: true })`) which are given with
the `Z` indicating UTC but should be interpreted as being in UCI's
timezone~~. We ask Postgres to interpret the `TIMESTAMP NO TIMEZONE` in
`America/Los_Angeles` and format as zoned ISO 8601, avoiding adding a JS
timezone library.

**Note**: The `slots` field on returned study rooms is now guaranteed to
exist. This is not a breaking change.

We use a materialized view to precompute the JSON structure of the
response. The refreshing of this view is relatively light and is done as
part of the study room and slot scraping process every 2 minutes.
However, it is not completely trivial; see below demonstrating that it
produces a significant speed improvement per request which will accrue
over time. **This design decision is a database schema change.** Since
we have this JSON structure beforehand, we need only `SELECT` with
conditions when serving a response.

## Related Issue

Feature update as requested in #46. ~~Also closes the inconsistency
raised in #74 since study room data was one of the offenders and is
within the jurisdiction of this PR.~~ It doesn't.

## Motivation and Context

>be me
>want study room slots
>no study room slots

mfw

## How Has This Been Tested?

Tested with Postman on a local deployment.

## Screenshots (if appropriate):

### Old screenshots (before timezone correction):

REST is functional:

![Screenshot_20250111_192159](https://github.com/user-attachments/assets/64d72053-79a4-4c39-93b6-5903e0a80e49)

GraphQL is functional:

![Screenshot_20250111_192242](https://github.com/user-attachments/assets/576fa5d9-f2cf-4dc1-ab3d-afd638568ca7)

### New screenshots (latest):


![Screenshot_20250114_145739](https://github.com/user-attachments/assets/30801e4f-d5c4-46cd-b543-e96d57dce5a9)


![Screenshot_20250114_150118](https://github.com/user-attachments/assets/9a4dde1b-c394-49e8-b481-9251e5a8dfa7)

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

## Checklist:

- [x] My code involves a change to the database schema.
- [ ] My code requires a change to the documentation.

---------

Co-authored-by: Andrew Wang <[email protected]>
@andrew-wang0 andrew-wang0 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants