-
Notifications
You must be signed in to change notification settings - Fork 0
Init design doc #53
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
base: main
Are you sure you want to change the base?
Init design doc #53
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,73 @@ | ||||||||||||||
| ### Overview | ||||||||||||||
|
|
||||||||||||||
| - This API lists matches from database | ||||||||||||||
|
|
||||||||||||||
| ### Endpoints | ||||||||||||||
|
|
||||||||||||||
| | Method | Path | Description | | ||||||||||||||
| |--------|------|-------------| | ||||||||||||||
| | GET | /api/matches/{year} | List pairings by year | | ||||||||||||||
| | GET | /api/matches/{year}/{month} | List pairings by month | | ||||||||||||||
| | GET | /api/matches/member/{id} | List pairings by member id | | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| Response: `ApiResponder<Match[]>` | ||||||||||||||
| ```typescript | ||||||||||||||
| interface Match { | ||||||||||||||
| match_id: string // UUID | ||||||||||||||
| member_a_id: string // UUID | ||||||||||||||
| member_b_id: string // UUID | ||||||||||||||
| month: string // YYYY-MM, from match_cycles.run_at | ||||||||||||||
| status: string | ||||||||||||||
| } | ||||||||||||||
| ``` | ||||||||||||||
| * Figured a flat list is more flexible for rendering instead of grouping by month server side | ||||||||||||||
|
|
||||||||||||||
| ## /api/matches/{year} | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just have /api/matches/{match_cycle.id} instead of a year. |
||||||||||||||
| * Join on match_cycles, filtered by run_at within year | ||||||||||||||
| ```sql | ||||||||||||||
| SELECT m.id, m.member_a_id, m.member_b_id, m.status, | ||||||||||||||
| to_char(c.run_at, 'YYYY-MM') AS month | ||||||||||||||
| FROM matches m | ||||||||||||||
| JOIN match_cycles c ON m.cycle_id = c.id | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change match_cycle.id to an int |
||||||||||||||
| WHERE c.run_at >= TIMESTAMPTZ '2026-01-01' | ||||||||||||||
| AND c.run_at < TIMESTAMPTZ '2027-01-01'; | ||||||||||||||
|
Comment on lines
+33
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The SQL query uses hardcoded dates Fix: Replace with parameterized dates: WHERE c.run_at >= TIMESTAMPTZ :year || '-01-01'
AND c.run_at < TIMESTAMPTZ (:year + 1) || '-01-01'
Suggested change
Spotted by Graphite |
||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| ## /api/matches/{year}/{month} | ||||||||||||||
| * Join on match_cycles, filtered by run_at within month | ||||||||||||||
| ```sql | ||||||||||||||
| SELECT m.id, m.member_a_id, m.member_b_id, m.status, | ||||||||||||||
| to_char(c.run_at, 'YYYY-MM') AS month | ||||||||||||||
| FROM matches m | ||||||||||||||
| JOIN match_cycles c ON m.cycle_id = c.id | ||||||||||||||
| WHERE c.run_at >= TIMESTAMPTZ '2026-01-01' | ||||||||||||||
| AND c.run_at < TIMESTAMPTZ '2026-02-01'; | ||||||||||||||
| ``` | ||||||||||||||
|
Comment on lines
+37
to
+46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to break this up by year |
||||||||||||||
|
|
||||||||||||||
| ## /api/matches/member/{id} | ||||||||||||||
| * Filter matches by member id | ||||||||||||||
| ```sql | ||||||||||||||
| SELECT m.id, m.member_a_id, m.member_b_id, m.status, | ||||||||||||||
| to_char(c.run_at, 'YYYY-MM') AS month | ||||||||||||||
| FROM matches m | ||||||||||||||
| JOIN match_cycles c ON m.cycle_id = c.id | ||||||||||||||
| WHERE m.member_a_id = :id | ||||||||||||||
| OR m.member_b_id = :id | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| ### Layering | ||||||||||||||
|
|
||||||||||||||
| Controller: | ||||||||||||||
| - `MatchController` (`/api/matches`) | ||||||||||||||
| * `listByYear(year)` | ||||||||||||||
| * `listByMonth(year, month)` | ||||||||||||||
| * `listByMember(id)` | ||||||||||||||
|
|
||||||||||||||
| Repository: `MatchRepository` (Spring JDBC, `NamedParameterJdbcTemplate`) | ||||||||||||||
| - owns the SQL above; returns `List<Match>` | ||||||||||||||
|
|
||||||||||||||
| DTO: `Match` (interface Match) | ||||||||||||||
| - `ApiResponder<List<Match>>` | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a /api/matches/list endpoint that takes in search params