diff --git a/.env b/.env new file mode 100644 index 0000000..0a6ea68 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +VITE_API_BASE_URL=REPLACE_ME diff --git a/src/api/authFactor.ts b/src/api/authFactor.ts new file mode 100644 index 0000000..4163362 --- /dev/null +++ b/src/api/authFactor.ts @@ -0,0 +1,18 @@ +import { type Model } from "codeforlife/lib/esm/helpers/rtkQuery" + +import api from "." + +export type AuthFactor = Model< + number, + { + user: number + type: "otp" + } +> + +const authFactorApi = api.injectEndpoints({ + endpoints: build => ({}), +}) + +export default authFactorApi +export const {} = authFactorApi diff --git a/src/api/index.ts b/src/api/index.ts new file mode 100644 index 0000000..ee07753 --- /dev/null +++ b/src/api/index.ts @@ -0,0 +1,11 @@ +import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react" + +const api = createApi({ + baseQuery: fetchBaseQuery({ + baseUrl: import.meta.env.VITE_API_BASE_URL, + }), + tagTypes: ["User", "Teacher", "Student", "School", "Class"], + endpoints: () => ({}), +}) + +export default api diff --git a/src/api/klass.ts b/src/api/klass.ts new file mode 100644 index 0000000..a6b4a5d --- /dev/null +++ b/src/api/klass.ts @@ -0,0 +1,21 @@ +import { type Model } from "codeforlife/lib/esm/helpers/rtkQuery" + +import api from "." + +export type Class = Model< + string, + { + name: string + teacher: number + school: number + read_classmates_data: boolean + receive_requests_until?: Date + } +> + +const classApi = api.injectEndpoints({ + endpoints: build => ({}), +}) + +export default classApi +export const {} = classApi diff --git a/src/api/otpBypassToken.ts b/src/api/otpBypassToken.ts new file mode 100644 index 0000000..049c231 --- /dev/null +++ b/src/api/otpBypassToken.ts @@ -0,0 +1,8 @@ +import api from "." + +const otpBypassTokenApi = api.injectEndpoints({ + endpoints: build => ({}), +}) + +export default otpBypassTokenApi +export const {} = otpBypassTokenApi diff --git a/src/api/school.ts b/src/api/school.ts new file mode 100644 index 0000000..34e861c --- /dev/null +++ b/src/api/school.ts @@ -0,0 +1,392 @@ +import { type Model } from "codeforlife/lib/esm/helpers/rtkQuery" + +import api from "." + +const country_iso_codes = [ + "AF", + "AX", + "AL", + "DZ", + "AS", + "AD", + "AO", + "AI", + "AQ", + "AG", + "AR", + "AM", + "AW", + "AU", + "AT", + "AZ", + "BS", + "BH", + "BD", + "BB", + "BY", + "BE", + "BZ", + "BJ", + "BM", + "BT", + "BO", + "BQ", + "BA", + "BW", + "BV", + "BR", + "IO", + "BN", + "BG", + "BF", + "BI", + "KH", + "CM", + "CA", + "CV", + "KY", + "CF", + "TD", + "CL", + "CN", + "CX", + "CC", + "CO", + "KM", + "CG", + "CD", + "CK", + "CR", + "CI", + "HR", + "CU", + "CW", + "CY", + "CZ", + "DK", + "DJ", + "DM", + "DO", + "EC", + "EG", + "SV", + "GQ", + "ER", + "EE", + "ET", + "FK", + "FO", + "FJ", + "FI", + "FR", + "GF", + "PF", + "TF", + "GA", + "GM", + "GE", + "DE", + "GH", + "GI", + "GR", + "GL", + "GD", + "GP", + "GU", + "GT", + "GG", + "GN", + "GW", + "GY", + "HT", + "HM", + "VA", + "HN", + "HK", + "HU", + "IS", + "IN", + "ID", + "IR", + "IQ", + "IE", + "IM", + "IL", + "IT", + "JM", + "JP", + "JE", + "JO", + "KZ", + "KE", + "KI", + "KP", + "KR", + "KW", + "KG", + "LA", + "LV", + "LB", + "LS", + "LR", + "LY", + "LI", + "LT", + "LU", + "MO", + "MK", + "MG", + "MW", + "MY", + "MV", + "ML", + "MT", + "MH", + "MQ", + "MR", + "MU", + "YT", + "MX", + "FM", + "MD", + "MC", + "MN", + "ME", + "MS", + "MA", + "MZ", + "MM", + "NA", + "NR", + "NP", + "NL", + "NC", + "NZ", + "NI", + "NE", + "NG", + "NU", + "NF", + "MP", + "NO", + "OM", + "PK", + "PW", + "PS", + "PA", + "PG", + "PY", + "PE", + "PH", + "PN", + "PL", + "PT", + "PR", + "QA", + "RE", + "RO", + "RU", + "RW", + "BL", + "SH", + "KN", + "LC", + "MF", + "PM", + "VC", + "WS", + "SM", + "ST", + "SA", + "SN", + "RS", + "SC", + "SL", + "SG", + "SX", + "SK", + "SI", + "SB", + "SO", + "ZA", + "GS", + "SS", + "ES", + "LK", + "SD", + "SR", + "SJ", + "SZ", + "SE", + "CH", + "SY", + "TW", + "TJ", + "TZ", + "TH", + "TL", + "TG", + "TK", + "TO", + "TT", + "TN", + "TR", + "TM", + "TC", + "TV", + "UG", + "UA", + "AE", + "GB", + "US", + "UM", + "UY", + "UZ", + "VU", + "VE", + "VN", + "VG", + "VI", + "WF", + "EH", + "YE", + "ZM", + "ZW", +] as const + +const uk_counties = [ + "Aberdeen City", + "Aberdeenshire", + "Angus", + "Argyll and Bute", + "Bedfordshire", + "Belfast", + "Belfast Greater", + "Berkshire", + "Blaenau Gwent", + "Bridgend", + "Buckinghamshire", + "Caerphilly", + "Cambridgeshire", + "Cardiff", + "Carmarthenshire", + "Ceredigion", + "Channel Islands", + "Cheshire", + "City of Edinburgh", + "Clackmannanshire", + "Conwy", + "Cornwall", + "County Antrim", + "County Armagh", + "County Down", + "County Fermanagh", + "County Londonderry", + "County Tyrone", + "County of Bristol", + "Cumbria", + "Denbighshire", + "Derbyshire", + "Devon", + "Dorset", + "Dumfries and Galloway", + "Dunbartonshire", + "Dundee City", + "Durham", + "East Ayrshire", + "East Dunbartonshire", + "East Lothian", + "East Renfrewshire", + "East Riding of Yorkshire", + "East Sussex", + "Essex", + "Falkirk", + "Fife", + "Flintshire", + "Glasgow City", + "Gloucestershire", + "Greater London", + "Greater Manchester", + "Guernsey Channel Islands", + "Gwynedd", + "Hampshire", + "Hereford and Worcester", + "Herefordshire", + "Hertfordshire", + "Highland", + "Inverclyde", + "Inverness", + "Isle of Anglesey", + "Isle of Barra", + "Isle of Man", + "Isle of Wight", + "Jersey Channel Islands", + "Kent", + "Lancashire", + "Leicestershire", + "Lincolnshire", + "Merseyside", + "Merthyr Tydfil", + "Midlothian", + "Monmouthshire", + "Moray", + "Neath Port Talbot", + "Newport", + "Norfolk", + "North Ayrshire", + "North Lanarkshire", + "North Yorkshire", + "Northamptonshire", + "Northumberland", + "Nottinghamshire", + "Orkney", + "Orkney Islands", + "Oxfordshire", + "Pembrokeshire", + "Perth and Kinross", + "Powys", + "Renfrewshire", + "Rhondda Cynon Taff", + "Rutland", + "Scottish Borders", + "Shetland Islands", + "Shropshire", + "Somerset", + "South Ayrshire", + "South Lanarkshire", + "South Yorkshire", + "Staffordshire", + "Stirling", + "Suffolk", + "Surrey", + "Swansea", + "Torfaen", + "Tyne and Wear", + "Vale of Glamorgan", + "Warwickshire", + "West Dunbart", + "West Lothian", + "West Midlands", + "West Sussex", + "West Yorkshire", + "Western Isles", + "Wiltshire", + "Worcestershire", + "Wrexham", +] as const + +export type School = Model< + number, + { + name: string + country?: (typeof country_iso_codes)[number] + uk_county?: (typeof uk_counties)[number] + } +> + +const schoolApi = api.injectEndpoints({ + endpoints: build => ({}), +}) + +export default schoolApi +export const {} = schoolApi diff --git a/src/api/schoolTeacherInvitation.ts b/src/api/schoolTeacherInvitation.ts new file mode 100644 index 0000000..0e54819 --- /dev/null +++ b/src/api/schoolTeacherInvitation.ts @@ -0,0 +1,12 @@ +import { type Model } from "codeforlife/lib/esm/helpers/rtkQuery" + +import api from "." + +export type SchoolTeacherInvitation = Model + +const schoolTeacherInvitationApi = api.injectEndpoints({ + endpoints: build => ({}), +}) + +export default schoolTeacherInvitationApi +export const {} = schoolTeacherInvitationApi diff --git a/src/api/student.ts b/src/api/student.ts new file mode 100644 index 0000000..077402d --- /dev/null +++ b/src/api/student.ts @@ -0,0 +1,18 @@ +import { type Model } from "codeforlife/lib/esm/helpers/rtkQuery" + +import api from "." + +export type Student = Model< + number, + { + school: number + klass: number + } +> + +const studentApi = api.injectEndpoints({ + endpoints: build => ({}), +}) + +export default studentApi +export const {} = studentApi diff --git a/src/api/teacher.ts b/src/api/teacher.ts new file mode 100644 index 0000000..7a83ce5 --- /dev/null +++ b/src/api/teacher.ts @@ -0,0 +1,18 @@ +import { type Model } from "codeforlife/lib/esm/helpers/rtkQuery" + +import api from "." + +export type Teacher = Model< + number, + { + school?: number + is_admin: boolean + } +> + +const teacherApi = api.injectEndpoints({ + endpoints: build => ({}), +}) + +export default teacherApi +export const {} = teacherApi diff --git a/src/api/user.ts b/src/api/user.ts new file mode 100644 index 0000000..080b260 --- /dev/null +++ b/src/api/user.ts @@ -0,0 +1,45 @@ +import { + type CreateArg, + type CreateResult, + type Model, +} from "codeforlife/lib/esm/helpers/rtkQuery" + +import api from "." +import { type Student } from "./student" +import { type Teacher } from "./teacher" + +export type User = Model< + number, + { + password: string + last_login?: Date + first_name: string + last_name?: string + email?: string + is_staff: boolean + is_active: boolean + date_joined: Date + requesting_to_join_class?: string + teacher?: Teacher + student?: Student + } +> + +const userApi = api.injectEndpoints({ + endpoints: build => ({ + createIndependentUser: build.mutation< + CreateResult, + CreateArg + >({ + query: body => ({ + url: "", + method: "POST", + body, + }), + invalidatesTags: () => ["User"], + }), + }), +}) + +export default userApi +export const { useCreateIndependentUserMutation } = userApi