hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { client } from "../client"; |
| 2 | import { appendPageParams, normalizePage, type Page, type PageParams } from "../client"; |
| 3 | import type { Course } from "../client"; |
| 4 | |
| 5 | /** |
| 6 | * `GET /courses` and `GET /courses/me` take `limit`/`offset` and nothing else — |
| 7 | * the backend has no kind/term/search filter, and serde drops unknown query |
| 8 | * keys silently, so any extra param would look applied while doing nothing. |
| 9 | * Narrow the list in the caller instead (see `courses-page.tsx`). |
| 10 | */ |
| 11 | export type CourseListParams = PageParams; |
| 12 | |
| 13 | export function courseListQuery(params?: CourseListParams): string { |
| 14 | if (!params) return ""; |
| 15 | const query = new URLSearchParams(); |
| 16 | appendPageParams(query, params); |
| 17 | const value = query.toString(); |
| 18 | return value ? `?${value}` : ""; |
| 19 | } |
| 20 | |
| 21 | export async function getCourses(params?: CourseListParams, signal?: AbortSignal): Promise<Page<Course>> { |
| 22 | const data = await client<unknown>(`/courses${courseListQuery(params)}`, { signal }); |
| 23 | return normalizePage<Course>(data); |
| 24 | } |