Skip to content

Commit

Permalink
🌱 Remove APIClient, update affected rest functions
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

Resolves: konveyor#1821
Part-of: konveyor#1411

Signed-off-by: Scott J Dickerson <[email protected]>
  • Loading branch information
sjd78 committed Apr 19, 2024
1 parent 7dfc262 commit f6c3bad
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 90 deletions.
21 changes: 10 additions & 11 deletions client/src/app/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,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 +190,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
41 changes: 17 additions & 24 deletions client/src/app/api/rest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import axios, { AxiosPromise } from "axios";
import { APIClient } from "@app/axios-config";

import {
AnalysisDependency,
Expand Down Expand Up @@ -136,7 +135,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 +178,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 +236,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 f6c3bad

Please sign in to comment.