|
1 | | -import instance from "lib/axios"; |
2 | 1 | import { APIPretalxSessions } from "models/api/session"; |
| 2 | +import SESSIONS from "./sessions.json"; |
3 | 3 |
|
4 | 4 | export const listSessions = async () => { |
5 | | - const result = await instance.get("/2024/sessions/"); |
6 | | - switch (result.status) { |
7 | | - case 200: |
8 | | - return result.data as APIPretalxSessions; |
9 | | - default: |
10 | | - throw new Error("세션 목록을 불러오는데 실패했습니다,\n잠시 후 다시 시도해주세요."); |
11 | | - } |
| 5 | + // const result = await instance.get("/2024/sessions/"); |
| 6 | + // switch (result.status) { |
| 7 | + // case 200: |
| 8 | + // return result.data as APIPretalxSessions; |
| 9 | + // default: |
| 10 | + // throw new Error("세션 목록을 불러오는데 실패했습니다,\n잠시 후 다시 시도해주세요."); |
| 11 | + // } |
| 12 | + |
| 13 | + return SESSIONS as APIPretalxSessions; |
12 | 14 | }; |
13 | 15 |
|
14 | 16 | export const retrieveSession = async (code: string) => { |
15 | | - const result = await instance.get(`/2024/sessions/${code}/`); |
16 | | - switch (result.status) { |
17 | | - case 200: |
18 | | - return result.data as APIPretalxSessions[0]; |
19 | | - default: |
20 | | - throw new Error("세션을 불러오는데 실패했습니다,\n잠시 후 다시 시도해주세요."); |
21 | | - } |
| 17 | + // const result = await instance.get(`/2024/sessions/${code}/`); |
| 18 | + // switch (result.status) { |
| 19 | + // case 200: |
| 20 | + // return result.data as APIPretalxSessions[0]; |
| 21 | + // default: |
| 22 | + // throw new Error("세션을 불러오는데 실패했습니다,\n잠시 후 다시 시도해주세요."); |
| 23 | + // } |
| 24 | + |
| 25 | + const filtered = (SESSIONS as APIPretalxSessions).filter((session) => session.code === code); |
| 26 | + if (filtered.length !== 1) |
| 27 | + throw new Error("세션을 불러오는데 실패했습니다,\n잠시 후 다시 시도해주세요."); |
| 28 | + |
| 29 | + return filtered[0]; |
22 | 30 | }; |
0 commit comments