Add orval and backend integration
This commit is contained in:
22
app/composeables/api/axios-instance.ts
Normal file
22
app/composeables/api/axios-instance.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import Axios, { type AxiosRequestConfig, type AxiosResponse } from 'axios';
|
||||
export const AXIOS_INSTANCE = Axios.create();
|
||||
|
||||
export const axiosInstance = <T>(
|
||||
config: AxiosRequestConfig,
|
||||
options?: AxiosRequestConfig,
|
||||
): Promise<AxiosResponse<T, any>> => {
|
||||
const baseURL = useRuntimeConfig().public.apiBaseUrl;
|
||||
console.log(baseURL)
|
||||
const source = Axios.CancelToken.source();
|
||||
const promise = AXIOS_INSTANCE({
|
||||
...config,
|
||||
...{
|
||||
...options,
|
||||
baseURL: baseURL
|
||||
},
|
||||
cancelToken: source.token,
|
||||
});
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
11
app/composeables/api/models/index.ts
Normal file
11
app/composeables/api/models/index.ts
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Generated by orval v7.16.0 🍺
|
||||
* Do not edit manually.
|
||||
* OpenAPI definition
|
||||
* OpenAPI spec version: v0
|
||||
*/
|
||||
|
||||
export * from './playlistCreateDTO';
|
||||
export * from './playlistReadDTO';
|
||||
export * from './readParams';
|
||||
export * from './uploadBody';
|
||||
10
app/composeables/api/models/playlistCreateDTO.ts
Normal file
10
app/composeables/api/models/playlistCreateDTO.ts
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Generated by orval v7.16.0 🍺
|
||||
* Do not edit manually.
|
||||
* OpenAPI definition
|
||||
* OpenAPI spec version: v0
|
||||
*/
|
||||
|
||||
export interface PlaylistCreateDTO {
|
||||
title?: string;
|
||||
}
|
||||
14
app/composeables/api/models/playlistReadDTO.ts
Normal file
14
app/composeables/api/models/playlistReadDTO.ts
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Generated by orval v7.16.0 🍺
|
||||
* Do not edit manually.
|
||||
* OpenAPI definition
|
||||
* OpenAPI spec version: v0
|
||||
*/
|
||||
|
||||
export interface PlaylistReadDTO {
|
||||
id?: number;
|
||||
ownerId?: number;
|
||||
title?: string;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
}
|
||||
10
app/composeables/api/models/readParams.ts
Normal file
10
app/composeables/api/models/readParams.ts
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Generated by orval v7.16.0 🍺
|
||||
* Do not edit manually.
|
||||
* OpenAPI definition
|
||||
* OpenAPI spec version: v0
|
||||
*/
|
||||
|
||||
export type ReadParams = {
|
||||
document: string;
|
||||
};
|
||||
10
app/composeables/api/models/uploadBody.ts
Normal file
10
app/composeables/api/models/uploadBody.ts
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Generated by orval v7.16.0 🍺
|
||||
* Do not edit manually.
|
||||
* OpenAPI definition
|
||||
* OpenAPI spec version: v0
|
||||
*/
|
||||
|
||||
export type UploadBody = {
|
||||
document: Blob;
|
||||
};
|
||||
161
app/composeables/api/playlist-controller/playlist-controller.ts
Normal file
161
app/composeables/api/playlist-controller/playlist-controller.ts
Normal file
@ -0,0 +1,161 @@
|
||||
/**
|
||||
* Generated by orval v7.16.0 🍺
|
||||
* Do not edit manually.
|
||||
* OpenAPI definition
|
||||
* OpenAPI spec version: v0
|
||||
*/
|
||||
import {
|
||||
useMutation,
|
||||
useQuery
|
||||
} from '@tanstack/vue-query';
|
||||
import type {
|
||||
DataTag,
|
||||
MutationFunction,
|
||||
QueryClient,
|
||||
QueryFunction,
|
||||
QueryKey,
|
||||
UseMutationOptions,
|
||||
UseMutationReturnType,
|
||||
UseQueryOptions,
|
||||
UseQueryReturnType
|
||||
} from '@tanstack/vue-query';
|
||||
|
||||
import {
|
||||
unref
|
||||
} from 'vue';
|
||||
import type {
|
||||
MaybeRef
|
||||
} from 'vue';
|
||||
|
||||
import type {
|
||||
PlaylistCreateDTO,
|
||||
PlaylistReadDTO
|
||||
} from '.././models';
|
||||
|
||||
import { axiosInstance } from '.././axios-instance';
|
||||
|
||||
|
||||
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
|
||||
|
||||
|
||||
|
||||
export const createPlaylist = (
|
||||
playlistCreateDTO: MaybeRef<PlaylistCreateDTO>,
|
||||
options?: SecondParameter<typeof axiosInstance>,signal?: AbortSignal
|
||||
) => {
|
||||
playlistCreateDTO = unref(playlistCreateDTO);
|
||||
|
||||
return axiosInstance<PlaylistReadDTO>(
|
||||
{url: `/playlist`, method: 'POST',
|
||||
headers: {'Content-Type': 'application/json', },
|
||||
data: playlistCreateDTO, signal
|
||||
},
|
||||
options);
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const getCreatePlaylistMutationOptions = <TError = unknown,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createPlaylist>>, TError,{data: PlaylistCreateDTO}, TContext>, request?: SecondParameter<typeof axiosInstance>}
|
||||
): UseMutationOptions<Awaited<ReturnType<typeof createPlaylist>>, TError,{data: PlaylistCreateDTO}, TContext> => {
|
||||
|
||||
const mutationKey = ['createPlaylist'];
|
||||
const {mutation: mutationOptions, request: requestOptions} = options ?
|
||||
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
||||
options
|
||||
: {...options, mutation: {...options.mutation, mutationKey}}
|
||||
: {mutation: { mutationKey, }, request: undefined};
|
||||
|
||||
|
||||
|
||||
|
||||
const mutationFn: MutationFunction<Awaited<ReturnType<typeof createPlaylist>>, {data: PlaylistCreateDTO}> = (props) => {
|
||||
const {data} = props ?? {};
|
||||
|
||||
return createPlaylist(data,requestOptions)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return { mutationFn, ...mutationOptions }}
|
||||
|
||||
export type CreatePlaylistMutationResult = NonNullable<Awaited<ReturnType<typeof createPlaylist>>>
|
||||
export type CreatePlaylistMutationBody = PlaylistCreateDTO
|
||||
export type CreatePlaylistMutationError = unknown
|
||||
|
||||
export const useCreatePlaylist = <TError = unknown,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createPlaylist>>, TError,{data: PlaylistCreateDTO}, TContext>, request?: SecondParameter<typeof axiosInstance>}
|
||||
, queryClient?: QueryClient): UseMutationReturnType<
|
||||
Awaited<ReturnType<typeof createPlaylist>>,
|
||||
TError,
|
||||
{data: PlaylistCreateDTO},
|
||||
TContext
|
||||
> => {
|
||||
|
||||
const mutationOptions = getCreatePlaylistMutationOptions(options);
|
||||
|
||||
return useMutation(mutationOptions, queryClient);
|
||||
}
|
||||
export const playlists = (
|
||||
|
||||
options?: SecondParameter<typeof axiosInstance>,signal?: AbortSignal
|
||||
) => {
|
||||
|
||||
|
||||
return axiosInstance<PlaylistReadDTO[]>(
|
||||
{url: `/playlists`, method: 'GET', signal
|
||||
},
|
||||
options);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export const getPlaylistsQueryKey = () => {
|
||||
return [
|
||||
'playlists'
|
||||
] as const;
|
||||
}
|
||||
|
||||
|
||||
export const getPlaylistsQueryOptions = <TData = Awaited<ReturnType<typeof playlists>>, TError = unknown>( options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof playlists>>, TError, TData>>, request?: SecondParameter<typeof axiosInstance>}
|
||||
) => {
|
||||
|
||||
const {query: queryOptions, request: requestOptions} = options ?? {};
|
||||
|
||||
const queryKey = getPlaylistsQueryKey();
|
||||
|
||||
|
||||
|
||||
const queryFn: QueryFunction<Awaited<ReturnType<typeof playlists>>> = ({ signal }) => playlists(requestOptions, signal);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof playlists>>, TError, TData>
|
||||
}
|
||||
|
||||
export type PlaylistsQueryResult = NonNullable<Awaited<ReturnType<typeof playlists>>>
|
||||
export type PlaylistsQueryError = unknown
|
||||
|
||||
|
||||
|
||||
export function usePlaylists<TData = Awaited<ReturnType<typeof playlists>>, TError = unknown>(
|
||||
options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof playlists>>, TError, TData>>, request?: SecondParameter<typeof axiosInstance>}
|
||||
, queryClient?: QueryClient
|
||||
): UseQueryReturnType<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
|
||||
|
||||
const queryOptions = getPlaylistsQueryOptions(options)
|
||||
|
||||
const query = useQuery(queryOptions, queryClient) as UseQueryReturnType<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
|
||||
|
||||
query.queryKey = unref(queryOptions).queryKey as DataTag<QueryKey, TData, TError>;
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
164
app/composeables/api/s-3-controller/s-3-controller.ts
Normal file
164
app/composeables/api/s-3-controller/s-3-controller.ts
Normal file
@ -0,0 +1,164 @@
|
||||
/**
|
||||
* Generated by orval v7.16.0 🍺
|
||||
* Do not edit manually.
|
||||
* OpenAPI definition
|
||||
* OpenAPI spec version: v0
|
||||
*/
|
||||
import {
|
||||
useMutation,
|
||||
useQuery
|
||||
} from '@tanstack/vue-query';
|
||||
import type {
|
||||
DataTag,
|
||||
MutationFunction,
|
||||
QueryClient,
|
||||
QueryFunction,
|
||||
QueryKey,
|
||||
UseMutationOptions,
|
||||
UseMutationReturnType,
|
||||
UseQueryOptions,
|
||||
UseQueryReturnType
|
||||
} from '@tanstack/vue-query';
|
||||
|
||||
import {
|
||||
unref
|
||||
} from 'vue';
|
||||
import type {
|
||||
MaybeRef
|
||||
} from 'vue';
|
||||
|
||||
import type {
|
||||
ReadParams,
|
||||
UploadBody
|
||||
} from '.././models';
|
||||
|
||||
import { axiosInstance } from '.././axios-instance';
|
||||
|
||||
|
||||
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
|
||||
|
||||
|
||||
|
||||
export const upload = (
|
||||
uploadBody: MaybeRef<UploadBody>,
|
||||
options?: SecondParameter<typeof axiosInstance>,signal?: AbortSignal
|
||||
) => {
|
||||
uploadBody = unref(uploadBody);
|
||||
const formData = new FormData();
|
||||
formData.append(`document`, uploadBody.document)
|
||||
|
||||
return axiosInstance<string>(
|
||||
{url: `/upload`, method: 'POST',
|
||||
headers: {'Content-Type': 'multipart/form-data', },
|
||||
data: formData, signal
|
||||
},
|
||||
options);
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const getUploadMutationOptions = <TError = unknown,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof upload>>, TError,{data: UploadBody}, TContext>, request?: SecondParameter<typeof axiosInstance>}
|
||||
): UseMutationOptions<Awaited<ReturnType<typeof upload>>, TError,{data: UploadBody}, TContext> => {
|
||||
|
||||
const mutationKey = ['upload'];
|
||||
const {mutation: mutationOptions, request: requestOptions} = options ?
|
||||
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
||||
options
|
||||
: {...options, mutation: {...options.mutation, mutationKey}}
|
||||
: {mutation: { mutationKey, }, request: undefined};
|
||||
|
||||
|
||||
|
||||
|
||||
const mutationFn: MutationFunction<Awaited<ReturnType<typeof upload>>, {data: UploadBody}> = (props) => {
|
||||
const {data} = props ?? {};
|
||||
|
||||
return upload(data,requestOptions)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return { mutationFn, ...mutationOptions }}
|
||||
|
||||
export type UploadMutationResult = NonNullable<Awaited<ReturnType<typeof upload>>>
|
||||
export type UploadMutationBody = UploadBody
|
||||
export type UploadMutationError = unknown
|
||||
|
||||
export const useUpload = <TError = unknown,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof upload>>, TError,{data: UploadBody}, TContext>, request?: SecondParameter<typeof axiosInstance>}
|
||||
, queryClient?: QueryClient): UseMutationReturnType<
|
||||
Awaited<ReturnType<typeof upload>>,
|
||||
TError,
|
||||
{data: UploadBody},
|
||||
TContext
|
||||
> => {
|
||||
|
||||
const mutationOptions = getUploadMutationOptions(options);
|
||||
|
||||
return useMutation(mutationOptions, queryClient);
|
||||
}
|
||||
export const read = (
|
||||
params: MaybeRef<ReadParams>,
|
||||
options?: SecondParameter<typeof axiosInstance>,signal?: AbortSignal
|
||||
) => {
|
||||
params = unref(params);
|
||||
|
||||
return axiosInstance<string>(
|
||||
{url: `/read`, method: 'GET',
|
||||
params: unref(params), signal
|
||||
},
|
||||
options);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export const getReadQueryKey = (params?: MaybeRef<ReadParams>,) => {
|
||||
return [
|
||||
'read', ...(params ? [params]: [])
|
||||
] as const;
|
||||
}
|
||||
|
||||
|
||||
export const getReadQueryOptions = <TData = Awaited<ReturnType<typeof read>>, TError = unknown>(params: MaybeRef<ReadParams>, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof read>>, TError, TData>>, request?: SecondParameter<typeof axiosInstance>}
|
||||
) => {
|
||||
|
||||
const {query: queryOptions, request: requestOptions} = options ?? {};
|
||||
|
||||
const queryKey = getReadQueryKey(params);
|
||||
|
||||
|
||||
|
||||
const queryFn: QueryFunction<Awaited<ReturnType<typeof read>>> = ({ signal }) => read(params, requestOptions, signal);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof read>>, TError, TData>
|
||||
}
|
||||
|
||||
export type ReadQueryResult = NonNullable<Awaited<ReturnType<typeof read>>>
|
||||
export type ReadQueryError = unknown
|
||||
|
||||
|
||||
|
||||
export function useRead<TData = Awaited<ReturnType<typeof read>>, TError = unknown>(
|
||||
params: MaybeRef<ReadParams>, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof read>>, TError, TData>>, request?: SecondParameter<typeof axiosInstance>}
|
||||
, queryClient?: QueryClient
|
||||
): UseQueryReturnType<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
|
||||
|
||||
const queryOptions = getReadQueryOptions(params,options)
|
||||
|
||||
const query = useQuery(queryOptions, queryClient) as UseQueryReturnType<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
|
||||
|
||||
query.queryKey = unref(queryOptions).queryKey as DataTag<QueryKey, TData, TError>;
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user