add some tabs and api
This commit is contained in:
1 parent
f0bd330d04
commit
d3fdba1139
5 files changed
+1072
-5
No files matched your search
+149
-4
@@ -1,5 +1,27 @@
|
||||
import _axios, { AxiosInstance } from 'axios'
|
||||
|
||||
export type IType = 'character' | 'vocabulary' | 'sentence'
|
||||
|
||||
export interface IEntry {
|
||||
id: string
|
||||
entry: string[]
|
||||
reading: string[]
|
||||
english: string[]
|
||||
type: IType
|
||||
description: string
|
||||
tag: string[]
|
||||
}
|
||||
|
||||
export type ILookup<T> = T & {
|
||||
offset?: number
|
||||
limit?: number
|
||||
}
|
||||
|
||||
export interface ILookupResult<T> {
|
||||
result: T[]
|
||||
count: number
|
||||
}
|
||||
|
||||
class Api {
|
||||
axios: AxiosInstance
|
||||
_isAuthorized = true
|
||||
@@ -89,8 +111,8 @@ class Api {
|
||||
)
|
||||
}
|
||||
|
||||
async quiz_create(params: { entries: string[]; type: string }) {
|
||||
return await this.axios.put('/api/quiz', params).then(
|
||||
async quiz_create(payload: { entries: string[]; type: IType }) {
|
||||
return await this.axios.put('/api/quiz', payload).then(
|
||||
(r) =>
|
||||
r.data as {
|
||||
result: {
|
||||
@@ -100,15 +122,138 @@ class Api {
|
||||
)
|
||||
}
|
||||
|
||||
async quiz_deleteMany(params: { entries: string[]; type: string }) {
|
||||
async quiz_deleteMany(params: { entries: string[]; type: IType }) {
|
||||
return await this.axios.post('/api/quiz/deleteMany', params)
|
||||
}
|
||||
|
||||
async extra_getQuery(params: ILookup<{ q: string }>) {
|
||||
params.offset = params.offset || 0
|
||||
params.limit = params.limit || 5
|
||||
|
||||
return await this.axios
|
||||
.get('/api/extra/q', { params })
|
||||
.then((r) => r.data as ILookupResult<IEntry>)
|
||||
}
|
||||
|
||||
async extra_create(payload: Omit<IEntry, 'id'>) {
|
||||
return await this.axios
|
||||
.put('/api/extra', payload)
|
||||
.then((r) => r.data as { id: string })
|
||||
}
|
||||
|
||||
async extra_update(payload: IEntry) {
|
||||
return await this.axios.patch('/api/extra', payload, {
|
||||
params: { id: payload.id },
|
||||
})
|
||||
}
|
||||
|
||||
async extra_delete(params: { id: string }) {
|
||||
return await this.axios.delete('/extra/delete', {
|
||||
return await this.axios.delete('/api/extra/delete', {
|
||||
params,
|
||||
})
|
||||
}
|
||||
|
||||
async character_getRadical(params: { entry: string }) {
|
||||
return await this.axios.get('/api/character/radical', { params }).then(
|
||||
(r) =>
|
||||
r.data as {
|
||||
result: {
|
||||
sub: string[]
|
||||
sup: string[]
|
||||
variant: string[]
|
||||
visual: string[]
|
||||
} | null
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async character_getVocabulary(params: ILookup<{ entry: string }>) {
|
||||
return await this.axios.get('/api/character/vocabulary', { params }).then(
|
||||
(r) =>
|
||||
r.data as ILookupResult<{
|
||||
entry: string
|
||||
}>
|
||||
)
|
||||
}
|
||||
|
||||
async character_getSentence(params: ILookup<{ entry: string }>) {
|
||||
return await this.axios.get('/api/character/sentence', { params }).then(
|
||||
(r) =>
|
||||
r.data as ILookupResult<{
|
||||
entry: string
|
||||
}>
|
||||
)
|
||||
}
|
||||
|
||||
async all_getRandom(params: { type: IType }) {
|
||||
return await this.axios.get('/api/all/random', { params }).then(
|
||||
(r) =>
|
||||
r.data as {
|
||||
result: string
|
||||
level: number
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async all_getQuery(params: ILookup<{ q: string }>) {
|
||||
params.offset = params.offset || 0
|
||||
params.limit = params.limit || 5
|
||||
|
||||
return await this.axios.get('/api/all/q', { params }).then(
|
||||
(r) =>
|
||||
r.data as ILookupResult<{
|
||||
entry: string
|
||||
type: IType
|
||||
}>
|
||||
)
|
||||
}
|
||||
|
||||
async all_getLookup(params: ILookup<{ entry: string; type: IType }>) {
|
||||
params.offset = params.offset || 0
|
||||
params.limit = params.limit || 5
|
||||
|
||||
return await this.axios
|
||||
.get('/api/all', {
|
||||
params,
|
||||
})
|
||||
.then(
|
||||
(r) =>
|
||||
r.data as ILookupResult<
|
||||
IEntry & {
|
||||
level?: number
|
||||
}
|
||||
>
|
||||
)
|
||||
}
|
||||
|
||||
async all_getReading(params: { entry: string }) {
|
||||
return await this.axios
|
||||
.get('/api/all/reading', {
|
||||
params,
|
||||
})
|
||||
.then(
|
||||
(r) =>
|
||||
r.data as {
|
||||
result: string
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async all_getMeaning(params: { entry: string }) {
|
||||
return await this.axios
|
||||
.get('/api/all/meaning', {
|
||||
params,
|
||||
})
|
||||
.then(
|
||||
(r) =>
|
||||
r.data as {
|
||||
result: {
|
||||
entry?: string
|
||||
meaning: string
|
||||
}[]
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export const api = new Api()
|
||||
Reference in new issue
Block a user