Skip to content

Commit

Permalink
refactor(coral): Add DYNAMIC_API_PATHS (#1480)
Browse files Browse the repository at this point in the history
- Add DYNAMIC_API_PATHS
- Format

---------

Signed-off-by: Mathieu Anderson <mathieu.anderson@aiven.io>
  • Loading branch information
Mathieu Anderson committed Jul 19, 2023
1 parent ee3f0f4 commit 9342551
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
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

0 comments on commit 9342551

Please sign in to comment.