-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add api foundation * install cfl package * fix configs * quick save * add remaining api endpoints * use new package * remove pointless include * fix: tag types and update arg * install new package version * ignore vscode files * fix urls
- Loading branch information
Showing
15 changed files
with
1,945 additions
and
763 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VITE_API_BASE_URL=REPLACE_ME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
**/*.json | ||
**/*.yaml | ||
**/*.yml | ||
**/*.code-workspace | ||
**/*.code-snippets | ||
**/*.code-* | ||
**/*.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { urls, type AuthFactor } from "codeforlife/lib/esm/api" | ||
import { | ||
buildUrl, | ||
tagData, | ||
type CreateArg, | ||
type CreateResult, | ||
type DestroyArg, | ||
type DestroyResult, | ||
type ListArg, | ||
type ListResult, | ||
} from "codeforlife/lib/esm/helpers/rtkQuery" | ||
|
||
import api from "." | ||
|
||
const authFactorApi = api.injectEndpoints({ | ||
endpoints: build => ({ | ||
createAuthFactor: build.mutation< | ||
CreateResult<AuthFactor>, | ||
CreateArg<AuthFactor, "type"> | ||
>({ | ||
query: body => ({ | ||
url: urls.authFactor.list, | ||
method: "POST", | ||
body, | ||
}), | ||
}), | ||
destroyAuthFactor: build.mutation<DestroyResult, DestroyArg<AuthFactor>>({ | ||
query: id => ({ | ||
url: buildUrl(urls.authFactor.detail, { url: { id } }), | ||
method: "DELETE", | ||
}), | ||
invalidatesTags: tagData("AuthFactor"), | ||
}), | ||
listAuthFactors: build.query<ListResult<AuthFactor, "type">, ListArg>({ | ||
query: search => ({ | ||
url: buildUrl(urls.authFactor.list, { search }), | ||
method: "GET", | ||
}), | ||
providesTags: tagData("AuthFactor"), | ||
}), | ||
}), | ||
}) | ||
|
||
export default authFactorApi | ||
export const { | ||
useCreateAuthFactorMutation, | ||
useDestroyAuthFactorMutation, | ||
useListAuthFactorsQuery, | ||
useLazyListAuthFactorsQuery, | ||
} = authFactorApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react" | ||
import { tagTypes } from "codeforlife/lib/esm/api" | ||
|
||
const api = createApi({ | ||
baseQuery: fetchBaseQuery({ | ||
baseUrl: import.meta.env.VITE_API_BASE_URL, | ||
}), | ||
tagTypes: [...tagTypes, "SchoolTeacherInvitation"], | ||
endpoints: () => ({}), | ||
}) | ||
|
||
export default api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { urls, type Class } from "codeforlife/lib/esm/api" | ||
import { | ||
buildUrl, | ||
tagData, | ||
type CreateArg, | ||
type CreateResult, | ||
type DestroyArg, | ||
type DestroyResult, | ||
type ListArg, | ||
type ListResult, | ||
type RetrieveArg, | ||
type RetrieveResult, | ||
type UpdateArg, | ||
type UpdateResult, | ||
} from "codeforlife/lib/esm/helpers/rtkQuery" | ||
|
||
import api from "." | ||
|
||
const classApi = api.injectEndpoints({ | ||
endpoints: build => ({ | ||
createClass: build.mutation< | ||
CreateResult<Class>, | ||
CreateArg< | ||
Class, | ||
"name" | "read_classmates_data", | ||
"teacher" | "receive_requests_until" | ||
> | ||
>({ | ||
query: body => ({ | ||
url: urls.class.list, | ||
method: "POST", | ||
body, | ||
}), | ||
}), | ||
destroyClass: build.mutation<DestroyResult, DestroyArg<Class>>({ | ||
query: id => ({ | ||
url: buildUrl(urls.class.detail, { url: { id } }), | ||
method: "DELETE", | ||
}), | ||
invalidatesTags: tagData("Class"), | ||
}), | ||
updateClass: build.mutation< | ||
UpdateResult<Class>, | ||
UpdateArg< | ||
Class, | ||
never, | ||
"name" | "read_classmates_data" | "receive_requests_until" | "teacher" | ||
> | ||
>({ | ||
query: ([id, body]) => ({ | ||
url: buildUrl(urls.class.detail, { url: { id } }), | ||
method: "PATCH", | ||
body, | ||
}), | ||
invalidatesTags: tagData("Class"), | ||
}), | ||
retrieveClass: build.query< | ||
RetrieveResult< | ||
Class, | ||
| "name" | ||
| "read_classmates_data" | ||
| "receive_requests_until" | ||
| "school" | ||
| "teacher" | ||
>, | ||
RetrieveArg<Class> | ||
>({ | ||
query: id => ({ | ||
url: buildUrl(urls.class.detail, { url: { id } }), | ||
method: "GET", | ||
}), | ||
providesTags: tagData("Class"), | ||
}), | ||
listClasses: build.query< | ||
ListResult< | ||
Class, | ||
| "name" | ||
| "read_classmates_data" | ||
| "receive_requests_until" | ||
| "school" | ||
| "teacher" | ||
>, | ||
ListArg | ||
>({ | ||
query: search => ({ | ||
url: buildUrl(urls.class.list, { search }), | ||
method: "GET", | ||
}), | ||
providesTags: tagData("Class"), | ||
}), | ||
}), | ||
}) | ||
|
||
export default classApi | ||
export const { | ||
useCreateClassMutation, | ||
useDestroyClassMutation, | ||
useUpdateClassMutation, | ||
useRetrieveClassQuery, | ||
useLazyRetrieveClassQuery, | ||
useListClassesQuery, | ||
useLazyListClassesQuery, | ||
} = classApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { urls } from "codeforlife/lib/esm/api" | ||
|
||
import api from "." | ||
|
||
const otpBypassTokenApi = api.injectEndpoints({ | ||
endpoints: build => ({ | ||
generateOtpBypassTokens: build.mutation<string[], null>({ | ||
query: () => ({ | ||
url: urls.otpBypassToken.list, | ||
method: "POST", | ||
}), | ||
}), | ||
}), | ||
}) | ||
|
||
export default otpBypassTokenApi | ||
export const { useGenerateOtpBypassTokensMutation } = otpBypassTokenApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { urls, type School } from "codeforlife/lib/esm/api" | ||
import { | ||
buildUrl, | ||
tagData, | ||
type CreateArg, | ||
type CreateResult, | ||
type RetrieveArg, | ||
type RetrieveResult, | ||
type UpdateArg, | ||
type UpdateResult, | ||
} from "codeforlife/lib/esm/helpers/rtkQuery" | ||
|
||
import api from "." | ||
|
||
const schoolApi = api.injectEndpoints({ | ||
endpoints: build => ({ | ||
retrieveSchool: build.query< | ||
RetrieveResult<School, "name" | "country" | "uk_county">, | ||
RetrieveArg<School> | ||
>({ | ||
query: id => ({ | ||
url: buildUrl(urls.school.detail, { url: { id } }), | ||
method: "GET", | ||
}), | ||
providesTags: tagData("School"), | ||
}), | ||
createSchool: build.mutation< | ||
CreateResult<School>, | ||
CreateArg<School, "name", "country" | "uk_county"> | ||
>({ | ||
query: body => ({ | ||
url: urls.school.list, | ||
method: "POST", | ||
body, | ||
}), | ||
}), | ||
updateSchool: build.mutation< | ||
UpdateResult<School>, | ||
UpdateArg<School, never, "name" | "country" | "uk_county"> | ||
>({ | ||
query: ([id, body]) => ({ | ||
url: buildUrl(urls.school.detail, { url: { id } }), | ||
method: "PATCH", | ||
body, | ||
}), | ||
invalidatesTags: tagData("School"), | ||
}), | ||
}), | ||
}) | ||
|
||
export default schoolApi | ||
export const { | ||
useRetrieveSchoolQuery, | ||
useLazyRetrieveSchoolQuery, | ||
useCreateSchoolMutation, | ||
useUpdateSchoolMutation, | ||
} = schoolApi |
Oops, something went wrong.