wip 16
This commit is contained in:
@@ -30,6 +30,7 @@ import type {
|
||||
DirectoryListResponse,
|
||||
DocumentResponse,
|
||||
DocumentsResponse,
|
||||
EditDocumentBody,
|
||||
ErrorResponse,
|
||||
GetActivityParams,
|
||||
GetAdmin200,
|
||||
@@ -56,6 +57,7 @@ import type {
|
||||
StreaksResponse,
|
||||
UpdateSettingsRequest,
|
||||
UpdateUserBody,
|
||||
UploadDocumentCoverBody,
|
||||
UserStatisticsResponse,
|
||||
UsersResponse
|
||||
} from './model';
|
||||
@@ -442,6 +444,118 @@ export function useGetDocument<TData = Awaited<ReturnType<typeof getDocument>>,
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @summary Update document editable fields
|
||||
*/
|
||||
export type editDocumentResponse200 = {
|
||||
data: DocumentResponse
|
||||
status: 200
|
||||
}
|
||||
|
||||
export type editDocumentResponse400 = {
|
||||
data: ErrorResponse
|
||||
status: 400
|
||||
}
|
||||
|
||||
export type editDocumentResponse401 = {
|
||||
data: ErrorResponse
|
||||
status: 401
|
||||
}
|
||||
|
||||
export type editDocumentResponse404 = {
|
||||
data: ErrorResponse
|
||||
status: 404
|
||||
}
|
||||
|
||||
export type editDocumentResponse500 = {
|
||||
data: ErrorResponse
|
||||
status: 500
|
||||
}
|
||||
|
||||
export type editDocumentResponseSuccess = (editDocumentResponse200) & {
|
||||
headers: Headers;
|
||||
};
|
||||
export type editDocumentResponseError = (editDocumentResponse400 | editDocumentResponse401 | editDocumentResponse404 | editDocumentResponse500) & {
|
||||
headers: Headers;
|
||||
};
|
||||
|
||||
export type editDocumentResponse = (editDocumentResponseSuccess | editDocumentResponseError)
|
||||
|
||||
export const getEditDocumentUrl = (id: string,) => {
|
||||
|
||||
|
||||
|
||||
|
||||
return `/api/v1/documents/${id}`
|
||||
}
|
||||
|
||||
export const editDocument = async (id: string,
|
||||
editDocumentBody: EditDocumentBody, options?: RequestInit): Promise<editDocumentResponse> => {
|
||||
|
||||
const res = await fetch(getEditDocumentUrl(id),
|
||||
{
|
||||
...options,
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...options?.headers },
|
||||
body: JSON.stringify(
|
||||
editDocumentBody,)
|
||||
}
|
||||
)
|
||||
|
||||
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
||||
|
||||
const data: editDocumentResponse['data'] = body ? JSON.parse(body) : {}
|
||||
return { data, status: res.status, headers: res.headers } as editDocumentResponse
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export const getEditDocumentMutationOptions = <TError = ErrorResponse,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof editDocument>>, TError,{id: string;data: EditDocumentBody}, TContext>, fetch?: RequestInit}
|
||||
): UseMutationOptions<Awaited<ReturnType<typeof editDocument>>, TError,{id: string;data: EditDocumentBody}, TContext> => {
|
||||
|
||||
const mutationKey = ['editDocument'];
|
||||
const {mutation: mutationOptions, fetch: fetchOptions} = options ?
|
||||
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
||||
options
|
||||
: {...options, mutation: {...options.mutation, mutationKey}}
|
||||
: {mutation: { mutationKey, }, fetch: undefined};
|
||||
|
||||
|
||||
|
||||
|
||||
const mutationFn: MutationFunction<Awaited<ReturnType<typeof editDocument>>, {id: string;data: EditDocumentBody}> = (props) => {
|
||||
const {id,data} = props ?? {};
|
||||
|
||||
return editDocument(id,data,fetchOptions)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { mutationFn, ...mutationOptions }}
|
||||
|
||||
export type EditDocumentMutationResult = NonNullable<Awaited<ReturnType<typeof editDocument>>>
|
||||
export type EditDocumentMutationBody = EditDocumentBody
|
||||
export type EditDocumentMutationError = ErrorResponse
|
||||
|
||||
/**
|
||||
* @summary Update document editable fields
|
||||
*/
|
||||
export const useEditDocument = <TError = ErrorResponse,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof editDocument>>, TError,{id: string;data: EditDocumentBody}, TContext>, fetch?: RequestInit}
|
||||
, queryClient?: QueryClient): UseMutationResult<
|
||||
Awaited<ReturnType<typeof editDocument>>,
|
||||
TError,
|
||||
{id: string;data: EditDocumentBody},
|
||||
TContext
|
||||
> => {
|
||||
return useMutation(getEditDocumentMutationOptions(options), queryClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary Get document cover image
|
||||
*/
|
||||
@@ -581,6 +695,120 @@ export function useGetDocumentCover<TData = Awaited<ReturnType<typeof getDocumen
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @summary Upload document cover image
|
||||
*/
|
||||
export type uploadDocumentCoverResponse200 = {
|
||||
data: DocumentResponse
|
||||
status: 200
|
||||
}
|
||||
|
||||
export type uploadDocumentCoverResponse400 = {
|
||||
data: ErrorResponse
|
||||
status: 400
|
||||
}
|
||||
|
||||
export type uploadDocumentCoverResponse401 = {
|
||||
data: ErrorResponse
|
||||
status: 401
|
||||
}
|
||||
|
||||
export type uploadDocumentCoverResponse404 = {
|
||||
data: ErrorResponse
|
||||
status: 404
|
||||
}
|
||||
|
||||
export type uploadDocumentCoverResponse500 = {
|
||||
data: ErrorResponse
|
||||
status: 500
|
||||
}
|
||||
|
||||
export type uploadDocumentCoverResponseSuccess = (uploadDocumentCoverResponse200) & {
|
||||
headers: Headers;
|
||||
};
|
||||
export type uploadDocumentCoverResponseError = (uploadDocumentCoverResponse400 | uploadDocumentCoverResponse401 | uploadDocumentCoverResponse404 | uploadDocumentCoverResponse500) & {
|
||||
headers: Headers;
|
||||
};
|
||||
|
||||
export type uploadDocumentCoverResponse = (uploadDocumentCoverResponseSuccess | uploadDocumentCoverResponseError)
|
||||
|
||||
export const getUploadDocumentCoverUrl = (id: string,) => {
|
||||
|
||||
|
||||
|
||||
|
||||
return `/api/v1/documents/${id}/cover`
|
||||
}
|
||||
|
||||
export const uploadDocumentCover = async (id: string,
|
||||
uploadDocumentCoverBody: UploadDocumentCoverBody, options?: RequestInit): Promise<uploadDocumentCoverResponse> => {
|
||||
const formData = new FormData();
|
||||
formData.append(`cover_file`, uploadDocumentCoverBody.cover_file);
|
||||
|
||||
const res = await fetch(getUploadDocumentCoverUrl(id),
|
||||
{
|
||||
...options,
|
||||
method: 'POST'
|
||||
,
|
||||
body:
|
||||
formData,
|
||||
}
|
||||
)
|
||||
|
||||
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
|
||||
|
||||
const data: uploadDocumentCoverResponse['data'] = body ? JSON.parse(body) : {}
|
||||
return { data, status: res.status, headers: res.headers } as uploadDocumentCoverResponse
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export const getUploadDocumentCoverMutationOptions = <TError = ErrorResponse,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof uploadDocumentCover>>, TError,{id: string;data: UploadDocumentCoverBody}, TContext>, fetch?: RequestInit}
|
||||
): UseMutationOptions<Awaited<ReturnType<typeof uploadDocumentCover>>, TError,{id: string;data: UploadDocumentCoverBody}, TContext> => {
|
||||
|
||||
const mutationKey = ['uploadDocumentCover'];
|
||||
const {mutation: mutationOptions, fetch: fetchOptions} = options ?
|
||||
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
||||
options
|
||||
: {...options, mutation: {...options.mutation, mutationKey}}
|
||||
: {mutation: { mutationKey, }, fetch: undefined};
|
||||
|
||||
|
||||
|
||||
|
||||
const mutationFn: MutationFunction<Awaited<ReturnType<typeof uploadDocumentCover>>, {id: string;data: UploadDocumentCoverBody}> = (props) => {
|
||||
const {id,data} = props ?? {};
|
||||
|
||||
return uploadDocumentCover(id,data,fetchOptions)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { mutationFn, ...mutationOptions }}
|
||||
|
||||
export type UploadDocumentCoverMutationResult = NonNullable<Awaited<ReturnType<typeof uploadDocumentCover>>>
|
||||
export type UploadDocumentCoverMutationBody = UploadDocumentCoverBody
|
||||
export type UploadDocumentCoverMutationError = ErrorResponse
|
||||
|
||||
/**
|
||||
* @summary Upload document cover image
|
||||
*/
|
||||
export const useUploadDocumentCover = <TError = ErrorResponse,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof uploadDocumentCover>>, TError,{id: string;data: UploadDocumentCoverBody}, TContext>, fetch?: RequestInit}
|
||||
, queryClient?: QueryClient): UseMutationResult<
|
||||
Awaited<ReturnType<typeof uploadDocumentCover>>,
|
||||
TError,
|
||||
{id: string;data: UploadDocumentCoverBody},
|
||||
TContext
|
||||
> => {
|
||||
return useMutation(getUploadDocumentCoverMutationOptions(options), queryClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary Download document file
|
||||
*/
|
||||
|
||||
@@ -6,9 +6,7 @@
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*/
|
||||
import type { Activity } from './activity';
|
||||
import type { UserData } from './userData';
|
||||
|
||||
export interface ActivityResponse {
|
||||
activities: Activity[];
|
||||
user: UserData;
|
||||
}
|
||||
|
||||
@@ -7,10 +7,8 @@
|
||||
*/
|
||||
import type { Document } from './document';
|
||||
import type { Progress } from './progress';
|
||||
import type { UserData } from './userData';
|
||||
|
||||
export interface DocumentResponse {
|
||||
document: Document;
|
||||
user: UserData;
|
||||
progress?: Progress;
|
||||
}
|
||||
|
||||
16
frontend/src/generated/model/editDocumentBody.ts
Normal file
16
frontend/src/generated/model/editDocumentBody.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Generated by orval v8.5.3 🍺
|
||||
* Do not edit manually.
|
||||
* AnthoLume API v1
|
||||
* REST API for AnthoLume document management system
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*/
|
||||
|
||||
export type EditDocumentBody = {
|
||||
title?: string;
|
||||
author?: string;
|
||||
description?: string;
|
||||
isbn10?: string;
|
||||
isbn13?: string;
|
||||
cover_gbid?: string;
|
||||
};
|
||||
@@ -6,9 +6,7 @@
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*/
|
||||
import type { GraphDataPoint } from './graphDataPoint';
|
||||
import type { UserData } from './userData';
|
||||
|
||||
export interface GraphDataResponse {
|
||||
graph_data: GraphDataPoint[];
|
||||
user: UserData;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
import type { DatabaseInfo } from './databaseInfo';
|
||||
import type { GraphDataResponse } from './graphDataResponse';
|
||||
import type { StreaksResponse } from './streaksResponse';
|
||||
import type { UserData } from './userData';
|
||||
import type { UserStatisticsResponse } from './userStatisticsResponse';
|
||||
|
||||
export interface HomeResponse {
|
||||
@@ -16,5 +15,4 @@ export interface HomeResponse {
|
||||
streaks: StreaksResponse;
|
||||
graph_data: GraphDataResponse;
|
||||
user_statistics: UserStatisticsResponse;
|
||||
user: UserData;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ export * from './directoryListResponse';
|
||||
export * from './document';
|
||||
export * from './documentResponse';
|
||||
export * from './documentsResponse';
|
||||
export * from './editDocumentBody';
|
||||
export * from './errorResponse';
|
||||
export * from './getActivityParams';
|
||||
export * from './getAdmin200';
|
||||
@@ -55,8 +56,10 @@ export * from './searchResponse';
|
||||
export * from './setting';
|
||||
export * from './settingsResponse';
|
||||
export * from './streaksResponse';
|
||||
export * from './updateDocumentBody';
|
||||
export * from './updateSettingsRequest';
|
||||
export * from './updateUserBody';
|
||||
export * from './uploadDocumentCoverBody';
|
||||
export * from './user';
|
||||
export * from './userData';
|
||||
export * from './usersResponse';
|
||||
|
||||
@@ -6,11 +6,9 @@
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*/
|
||||
import type { Progress } from './progress';
|
||||
import type { UserData } from './userData';
|
||||
|
||||
export interface ProgressListResponse {
|
||||
progress?: Progress[];
|
||||
user?: UserData;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
next_page?: number;
|
||||
|
||||
@@ -6,9 +6,7 @@
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*/
|
||||
import type { Progress } from './progress';
|
||||
import type { UserData } from './userData';
|
||||
|
||||
export interface ProgressResponse {
|
||||
progress?: Progress;
|
||||
user?: UserData;
|
||||
}
|
||||
|
||||
@@ -5,10 +5,8 @@
|
||||
* REST API for AnthoLume document management system
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*/
|
||||
import type { UserData } from './userData';
|
||||
import type { UserStreak } from './userStreak';
|
||||
|
||||
export interface StreaksResponse {
|
||||
streaks: UserStreak[];
|
||||
user: UserData;
|
||||
}
|
||||
|
||||
15
frontend/src/generated/model/updateDocumentBody.ts
Normal file
15
frontend/src/generated/model/updateDocumentBody.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Generated by orval v8.5.3 🍺
|
||||
* Do not edit manually.
|
||||
* AnthoLume API v1
|
||||
* REST API for AnthoLume document management system
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*/
|
||||
|
||||
export type UpdateDocumentBody = {
|
||||
title?: string;
|
||||
author?: string;
|
||||
description?: string;
|
||||
isbn10?: string;
|
||||
isbn13?: string;
|
||||
};
|
||||
11
frontend/src/generated/model/uploadDocumentCoverBody.ts
Normal file
11
frontend/src/generated/model/uploadDocumentCoverBody.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Generated by orval v8.5.3 🍺
|
||||
* Do not edit manually.
|
||||
* AnthoLume API v1
|
||||
* REST API for AnthoLume document management system
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*/
|
||||
|
||||
export type UploadDocumentCoverBody = {
|
||||
cover_file: Blob;
|
||||
};
|
||||
@@ -6,11 +6,9 @@
|
||||
* OpenAPI spec version: 1.0.0
|
||||
*/
|
||||
import type { LeaderboardData } from './leaderboardData';
|
||||
import type { UserData } from './userData';
|
||||
|
||||
export interface UserStatisticsResponse {
|
||||
wpm: LeaderboardData;
|
||||
duration: LeaderboardData;
|
||||
words: LeaderboardData;
|
||||
user: UserData;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user