Skip to content

Commit

Permalink
🌱 Remove APIClient, update effected rest functions (#1822)
Browse files Browse the repository at this point in the history
Changes:
  - Remove `APIClient`
  - Update the affected functions in `rest.ts` to use axios directly
  - Double check the return types of the effected functions
  - Updated a few API model types based on current hub handler function
    responses
  - `getApplicationSummaryCSV()` URL query param was incorrectly named and
    could lead to more results returned than expected. Query param updated
    to the correct name as per the OpenAPI definition / golang handler code.

Resolves: #1821
Part-of: #1411

---------

Signed-off-by: Scott J Dickerson <[email protected]>
  • Loading branch information
sjd78 committed Apr 19, 2024
1 parent 7dfc262 commit 8b13af6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 90 deletions.
23 changes: 12 additions & 11 deletions client/src/app/api/models.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// hub OpenAPI definition: https://github.com/konveyor/tackle2-hub/blob/main/docs/openapi3.json

export enum MimeType {
TAR = "tar",
YAML = "yaml",
Expand Down Expand Up @@ -158,11 +160,11 @@ export interface ApplicationDependency {
export interface ApplicationAdoptionPlan {
applicationId: number;
applicationName: string;
positionX: number;
positionY: number;
effort: number;
decision: ProposedAction;
effortEstimate: string;
effort: number;
positionX: number;
positionY: number;
}

export interface ApplicationImportSummary {
Expand Down Expand Up @@ -190,18 +192,17 @@ export type IdentityKind =

export interface Identity {
id: number;
createUser?: string;
updateUser?: string;
createTime?: string;

kind: IdentityKind;
name: string;
description?: string;
kind?: IdentityKind;
createUser?: string;
encrypted?: string;
key?: string;
keyFilename?: string;
password?: string;
user?: string;
updateUser?: string;
password?: string;
key?: string;
settings?: string;
settingsFilename?: string;
}

export interface Proxy {
Expand Down
43 changes: 19 additions & 24 deletions client/src/app/api/rest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// hub OpenAPI definition: https://github.com/konveyor/tackle2-hub/blob/main/docs/openapi3.json

import axios, { AxiosPromise } from "axios";
import { APIClient } from "@app/axios-config";

import {
AnalysisDependency,
Expand Down Expand Up @@ -136,7 +137,7 @@ export const getApplicationDependencies = (
return axios
.get(`${APPLICATION_DEPENDENCY}`, {
params,
headers: jsonHeaders,
headers: jsonHeaders.headers,
})
.then((response) => response.data);
};
Expand Down Expand Up @@ -179,21 +180,17 @@ export const deleteReview = (id: number): Promise<Review> => {
return axios.delete(`${REVIEWS}/${id}`);
};

export const getApplicationAdoptionPlan = (
applicationIds: number[]
): AxiosPromise<ApplicationAdoptionPlan[]> => {
return APIClient.post(
export const getApplicationAdoptionPlan = (applicationIds: number[]) => {
return axios.post<ApplicationAdoptionPlan[]>(
`${REPORT}/adoptionplan`,
applicationIds.map((f) => ({
applicationId: f,
}))
applicationIds.map((f) => ({ applicationId: f }))
);
};

export const getApplicationSummaryCSV = (id: string): AxiosPromise => {
return APIClient.get(`${APP_IMPORT_CSV}?importSummaryId=${id}`, {
export const getApplicationSummaryCSV = (id: string) => {
return axios.get<ArrayBuffer>(`${APP_IMPORT_CSV}?importSummary.id=${id}`, {
responseType: "arraybuffer",
headers: { Accept: "text/csv", responseType: "blob" },
headers: { Accept: "text/csv" },
});
};

Expand Down Expand Up @@ -241,28 +238,26 @@ export const getAssessmentById = (id: number | string): Promise<Assessment> => {
return axios.get(`${ASSESSMENTS}/${id}`).then((response) => response.data);
};

export const deleteAssessment = (id: number): AxiosPromise => {
return APIClient.delete(`${ASSESSMENTS}/${id}`);
export const deleteAssessment = (id: number) => {
return axios.delete<void>(`${ASSESSMENTS}/${id}`);
};

export const getIdentities = (): AxiosPromise<Array<Identity>> => {
return APIClient.get(`${IDENTITIES}`, jsonHeaders);
export const getIdentities = () => {
return axios.get<Identity[]>(`${IDENTITIES}`, jsonHeaders);
};

export const createIdentity = (obj: New<Identity>): AxiosPromise<Identity> => {
return APIClient.post(`${IDENTITIES}`, obj);
export const createIdentity = (obj: New<Identity>) => {
return axios.post<Identity>(`${IDENTITIES}`, obj);
};

export const updateIdentity = (obj: Identity): AxiosPromise<Identity> => {
return APIClient.put(`${IDENTITIES}/${obj.id}`, obj);
export const updateIdentity = (obj: Identity) => {
return axios.put<void>(`${IDENTITIES}/${obj.id}`, obj);
};

export const deleteIdentity = (identity: Identity): AxiosPromise => {
return APIClient.delete(`${IDENTITIES}/${identity.id}`);
export const deleteIdentity = (identity: Identity) => {
return axios.delete<void>(`${IDENTITIES}/${identity.id}`);
};

// Axios direct

// success with code 201 and created entity as response data
export const createApplication = (application: New<Application>) =>
axios
Expand Down
53 changes: 0 additions & 53 deletions client/src/app/axios-config/apiClient.tsx

This file was deleted.

1 change: 0 additions & 1 deletion client/src/app/axios-config/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { APIClient } from "./apiClient";
export { initInterceptors } from "./apiInit";
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type UserCredentials = "userpass" | "source";
interface IdentityFormValues {
name: string;
description: string;
kind?: IdentityKind;
kind: IdentityKind;
settings: string;
settingsFilename: string;
userCredentials?: UserCredentials;
Expand Down

0 comments on commit 8b13af6

Please sign in to comment.