Api: generate RTK Query for Edge
This commit adds the Edge API to RTK Query in preparation of porting edge source code to image-builder-frontend
This commit is contained in:
parent
85ab893c2b
commit
e266073718
7 changed files with 5801 additions and 0 deletions
1
api.sh
1
api.sh
|
|
@ -5,6 +5,7 @@ npx @rtk-query/codegen-openapi ./api/config/imageBuilder.ts &
|
|||
npx @rtk-query/codegen-openapi ./api/config/rhsm.ts &
|
||||
npx @rtk-query/codegen-openapi ./api/config/contentSources.ts &
|
||||
npx @rtk-query/codegen-openapi ./api/config/provisioning.ts &
|
||||
npx @rtk-query/codegen-openapi ./api/config/edge.ts &
|
||||
|
||||
# Wait for all background jobs to finish
|
||||
wait
|
||||
|
|
|
|||
13
api/config/edge.ts
Normal file
13
api/config/edge.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import type { ConfigFile } from '@rtk-query/codegen-openapi';
|
||||
|
||||
const config: ConfigFile = {
|
||||
schemaFile: '../schema/edge.json',
|
||||
apiFile: '../../src/store/emptyEdgeApi.ts',
|
||||
apiImport: 'emptyEdgeApi',
|
||||
outputFile: '../../src/store/edgeApi.ts',
|
||||
exportName: 'edgeApi',
|
||||
hooks: true,
|
||||
filterEndpoints: ['getAllImages', 'getImageStatusByID', 'getImageByID'],
|
||||
};
|
||||
|
||||
export default config;
|
||||
5722
api/schema/edge.json
Normal file
5722
api/schema/edge.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,6 @@
|
|||
export const IMAGE_BUILDER_API = '/api/image-builder/v1';
|
||||
export const RHSM_API = '/api/rhsm/v2';
|
||||
export const EDGE_API = '/api/edge/v1';
|
||||
export const CONTENT_SOURCES_API = '/api/content-sources/v1';
|
||||
export const PROVISIONING_API = '/api/provisioning/v1';
|
||||
export const RHEL_8 = 'rhel-88';
|
||||
|
|
|
|||
51
src/store/edgeApi.ts
Normal file
51
src/store/edgeApi.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import { emptyEdgeApi as api } from './emptyEdgeApi';
|
||||
const injectedRtkApi = api.injectEndpoints({
|
||||
endpoints: (build) => ({
|
||||
getAllImages: build.query<GetAllImagesApiResponse, GetAllImagesApiArg>({
|
||||
query: (queryArg) => ({
|
||||
url: `/images`,
|
||||
params: {
|
||||
limit: queryArg.limit,
|
||||
offset: queryArg.offset,
|
||||
sort_by: queryArg.sortBy,
|
||||
name: queryArg.name,
|
||||
status: queryArg.status,
|
||||
distribution: queryArg.distribution,
|
||||
created_at: queryArg.createdAt,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
overrideExisting: false,
|
||||
});
|
||||
export { injectedRtkApi as edgeApi };
|
||||
export type GetAllImagesApiResponse =
|
||||
/** status 200 OK */ ModelsSuccessPlaceholderResponse;
|
||||
export type GetAllImagesApiArg = {
|
||||
/** Return number of images until limit is reached. */
|
||||
limit?: number;
|
||||
/** Return number of images beginning at the offset */
|
||||
offset?: number;
|
||||
/** created_at, distribution, name,status. To sort DESC use -before the fields */
|
||||
sortBy?: string;
|
||||
/** Filter by name. */
|
||||
name?: string;
|
||||
/** Filter by status. */
|
||||
status?: string;
|
||||
/** Filter by distribution. */
|
||||
distribution?: string;
|
||||
/** Filter by creation date. */
|
||||
createdAt?: string;
|
||||
};
|
||||
export type ModelsSuccessPlaceholderResponse = object;
|
||||
export type ErrorsBadRequest = {
|
||||
Code?: string;
|
||||
Status?: number;
|
||||
Title?: string;
|
||||
};
|
||||
export type ErrorsInternalServerError = {
|
||||
Code?: string;
|
||||
Status?: number;
|
||||
Title?: string;
|
||||
};
|
||||
export const { useGetAllImagesQuery } = injectedRtkApi;
|
||||
10
src/store/emptyEdgeApi.ts
Normal file
10
src/store/emptyEdgeApi.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
||||
|
||||
import { EDGE_API } from '../constants';
|
||||
|
||||
// initialize an empty api service that we'll inject endpoints into later as needed
|
||||
export const emptyEdgeApi = createApi({
|
||||
reducerPath: 'edgeApi',
|
||||
baseQuery: fetchBaseQuery({ baseUrl: EDGE_API }),
|
||||
endpoints: () => ({}),
|
||||
});
|
||||
|
|
@ -5,6 +5,7 @@ import promiseMiddleware from 'redux-promise-middleware';
|
|||
import clonesSlice from './clonesSlice';
|
||||
import composesSlice from './composesSlice';
|
||||
import { contentSourcesApi } from './contentSourcesApi';
|
||||
import { edgeApi } from './edgeApi';
|
||||
import { imageBuilderApi } from './imageBuilderApi';
|
||||
import { provisioningApi } from './provisioningApi';
|
||||
import { rhsmApi } from './rhsmApi';
|
||||
|
|
@ -13,6 +14,7 @@ export const reducer = {
|
|||
clones: clonesSlice,
|
||||
composes: composesSlice,
|
||||
[contentSourcesApi.reducerPath]: contentSourcesApi.reducer,
|
||||
[edgeApi.reducerPath]: edgeApi.reducer,
|
||||
[imageBuilderApi.reducerPath]: imageBuilderApi.reducer,
|
||||
[rhsmApi.reducerPath]: rhsmApi.reducer,
|
||||
[provisioningApi.reducerPath]: provisioningApi.reducer,
|
||||
|
|
@ -23,6 +25,7 @@ export const middleware = (getDefaultMiddleware) =>
|
|||
getDefaultMiddleware()
|
||||
.concat(promiseMiddleware)
|
||||
.concat(contentSourcesApi.middleware)
|
||||
.concat(edgeApi.middleware)
|
||||
.concat(imageBuilderApi.middleware)
|
||||
.concat(rhsmApi.middleware)
|
||||
.concat(provisioningApi.middleware);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue