Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(coral): Add DYNAMIC_API_PATHS #1480

Merged
merged 3 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions coral/src/domain/team/team-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import api, { API_PATHS } from "src/services/api";
import api, { API_PATHS, DYNAMIC_API_PATHS } from "src/services/api";
import { KlawApiRequest, KlawApiResponse } from "types/utils";

const getTeams = () => {
Expand Down Expand Up @@ -31,11 +31,7 @@ const updateTeam = ({

const getTeamsOfUser = ({ userName }: { userName: string }) => {
return api.get<KlawApiResponse<"getSwitchTeams">>(
// API_PATH does not cover arguments,
// follow up ticket: https://github.com/aiven/klaw/issues/1021
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
`/user/${userName}/switchTeamsList`
DYNAMIC_API_PATHS.getSwitchTeams({ userId: userName })
);
};

Expand Down
36 changes: 32 additions & 4 deletions coral/src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ const CONTENT_TYPE_JSON = "application/json" as const;

const API_BASE_URL = getHTTPBaseAPIUrl();

const API_PATHS: { [key in keyof ApiOperations]: keyof ApiPaths } = {
const API_PATHS = {
restartConnector: "/connector/restart",
getConnectorsToManage: "/getConnectorsToManage",
resetCacheClusterApi: "/schemas/resetCache",
updateSyncSchemas: "/schemas",
getSchemaOfTopicFromSource:
"/schemas/source/{source}/kafkaEnv/{kafkaEnvId}/topic/{topicName}/schemaVersion/{schemaVersion}",
getSchemasOfEnvironment: "/schemas",
validateSchema: "/validate/schema",
updateUserTeamFromSwitchTeams: "/user/updateTeam",
Expand Down Expand Up @@ -105,7 +103,6 @@ const API_PATHS: { [key in keyof ApiOperations]: keyof ApiPaths } = {
addNewTeam: "/addNewTeam",
addNewEnv: "/addNewEnv",
addNewCluster: "/addNewCluster",
getSwitchTeams: "/user/{userId}/switchTeamsList",
testClusterApiConnection: "/testClusterApiConnection",
shutdownApp: "/shutdownContext",
showUsers: "/showUserList",
Expand Down Expand Up @@ -191,6 +188,36 @@ const API_PATHS: { [key in keyof ApiOperations]: keyof ApiPaths } = {
getAclRequests: "/getAclRequests",
getAclRequestsForApprover: "/getAclRequestsForApprover",
getAclCommand: "/getAclCommands",
} satisfies {
[key in keyof Omit<
ApiOperations,
"getSchemaOfTopicFromSource" | "getSwitchTeams"
>]: keyof ApiPaths;
};

type GetSchemaOfTopicFromSource = (params: {
source: string;
kafkaEnvId: string;
topicName: string;
schemaVersion: string;
}) => keyof ApiPaths;
type GetSwitchTeams = (params: { userId: string }) => keyof ApiPaths;

const DYNAMIC_API_PATHS = {
getSchemaOfTopicFromSource: ({
source,
kafkaEnvId,
topicName,
schemaVersion,
}: Parameters<GetSchemaOfTopicFromSource>[0]) =>
`/schemas/source/${source}/kafkaEnv/${kafkaEnvId}/topic/${topicName}/schemaVersion/${schemaVersion}` as keyof ApiPaths,
getSwitchTeams: ({ userId }: Parameters<GetSwitchTeams>[0]) =>
`/user/${userId}/switchTeamsList` as keyof ApiPaths,
} satisfies {
[key in keyof Pick<
ApiOperations,
"getSchemaOfTopicFromSource" | "getSwitchTeams"
>]: GetSchemaOfTopicFromSource | GetSwitchTeams;
};

type Params = URLSearchParams;
Expand Down Expand Up @@ -519,6 +546,7 @@ export default {
export type { HTTPError, KlawApiResponse, KlawApiError };
export {
API_PATHS,
DYNAMIC_API_PATHS,
HTTPMethod,
isUnauthorizedError,
isServerError,
Expand Down