Skip to content

Commit

Permalink
feat(api-client): Add methods to list and retrieve timetable courses
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian325 committed May 6, 2024
1 parent 736de4c commit d795bb2
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/api-client/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,33 @@ public getTimetableByDate({
- `userId`: (Optional) User ID.
- Returns: A Promise resolving to the AxiosResponse containing the timetable.

##### `getTimetableCourses`

```typescript
public getTimetableCourses(userId?: number | string): Promise<AxiosResponse<BaseResponse<TTimetableCourseResponse.Course[]>>>
```

- Lists available courses for the user's timetable.
- Parameters:
- `userId`: (Optional) User ID.
- Returns: A Promise resolving to the AxiosResponse containing timetable courses.

##### `getTimetableCoursesById`

```typescript
public getTimetableCoursesById({
courseId
}: {
courseId: number
}, userId?: number | string): Promise<AxiosResponse<BaseResponse<TTimetableCourseResponse.Course>>>
```

- Retreives timetable course by id.
- Parameters:
- `courseId`: Course Id
- `userId`: (Optional) User ID.
- Returns: A Promise resolving to the AxiosResponse containing timetable courses.

##### `getUser`

```typescript
Expand Down
22 changes: 22 additions & 0 deletions packages/api-client/src/client/AxiosApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
NewsResponse,
SurveyResponse,
SurveyVoteRequest,
TimetableCourseResponse,
TimetableResponse,
TimetableTimeResponse,
UserActivitySummaryResponse,
Expand Down Expand Up @@ -172,6 +173,27 @@ class AxiosApiClient {
return response
}

public getTimetableCourses = async (userId: number | string = "self") => {
const response = await this.instance.get<
BaseResponse<TimetableCourseResponse.Course[]>
>(`users/${userId}/timetable/courses`)
return response
}

public getTimetableCourseById = async (
{
courseId,
}: {
courseId: number
},
userId: number | string = "self"
) => {
const response = await this.instance.get<
BaseResponse<TimetableCourseResponse.Course>
>(`users/${userId}/timetable/courses/${courseId}`)
return response
}

public getUser = async (userId: number | string = "self") => {
const response = await this.instance.get<
BaseResponse<UserResponse.User>
Expand Down
1 change: 1 addition & 0 deletions packages/api-client/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export * as ChatsResponse from "./chats"
export * as ChatMessagesResponse from "./chat_message"
export * as ChatMemberResponse from "./chat_member"
export * as CloudResponse from "./cloud"
export * as TimetableCourseResponse from "./timetable_course"
9 changes: 9 additions & 0 deletions packages/api-client/src/types/timetable_course.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface Course {
id: number
name: string | null
description: string | null
subject_id: number
meta: {
displayname: string
}
}

0 comments on commit d795bb2

Please sign in to comment.