MSP-3107 add appService
This commit is contained in:
1 parent
c60a8dc825
commit
8a65a03a13
4 files changed
+81
-3
No files matched your search
@@ -1,5 +1,7 @@
|
||||
type PathKeys =
|
||||
| 'baseUrl'
|
||||
| 'baseSystemUrl'
|
||||
| 'baseConfigUrl'
|
||||
| 'getAllRoles'
|
||||
| 'createRole'
|
||||
| 'updateRole'
|
||||
@@ -7,8 +9,11 @@ type PathKeys =
|
||||
| 'login'
|
||||
| 'logout'
|
||||
| 'getProfile'
|
||||
| 'getSystemTree'
|
||||
export const apiPaths: Record<PathKeys, string> = {
|
||||
baseUrl: '/api/admin',
|
||||
baseSystemUrl: '/api/system',
|
||||
baseConfigUrl: '/api/config',
|
||||
// ======= ROLES ======
|
||||
getAllRoles: '/role/all',
|
||||
createRole: '/role/create',
|
||||
@@ -18,5 +23,7 @@ export const apiPaths: Record<PathKeys, string> = {
|
||||
login: '/api/admin/auth/login',
|
||||
logout: '/api/admin/auth/logout',
|
||||
// ======= PROFILE ======
|
||||
getProfile: '/api/admin/user/get_profile'
|
||||
getProfile: '/api/admin/user/get_profile',
|
||||
// ======= APPLICATIONS ======
|
||||
getSystemTree: '/application/get_system_tree'
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react'
|
||||
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
|
||||
import { axiosBaseQuery } from '@utils/apiUtils.ts'
|
||||
|
||||
import { AppApiResponseType, DomainType } from '@type/app.type.ts'
|
||||
|
||||
|
||||
const appApi = createApi({
|
||||
reducerPath: 'appService',
|
||||
refetchOnFocus: true,
|
||||
tagTypes: ['SystemTreeApps'],
|
||||
baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseSystemUrl }),
|
||||
endpoints: (builder) => ({
|
||||
getSystemTree: builder.query<AppApiResponseType, void>({
|
||||
query: () => ({ url: apiPaths.getSystemTree }),
|
||||
transformResponse: (response: DomainType[]) => {
|
||||
const apps = response.flatMap(({ services }) =>
|
||||
services.flatMap(({ apps }) => apps)
|
||||
)
|
||||
|
||||
return {
|
||||
originalResponse: response,
|
||||
appList: apps
|
||||
}
|
||||
},
|
||||
providesTags: () => ['SystemTreeApps']
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
export default appApi
|
||||
@@ -3,6 +3,7 @@ import { theme } from 'antd'
|
||||
import { MapToken, SeedToken } from 'antd/es/theme/interface'
|
||||
import { createContext, Dispatch, SetStateAction } from 'react'
|
||||
|
||||
import appApi from '@services/appService.ts'
|
||||
import roleApi from '@services/roleService.ts'
|
||||
|
||||
import profileReducer from './redusers/ProfileSlice.ts'
|
||||
@@ -20,14 +21,18 @@ export const Context = createContext<ContextProps>({
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
profileReducer,
|
||||
[roleApi.reducerPath]: roleApi.reducer
|
||||
[roleApi.reducerPath]: roleApi.reducer,
|
||||
[appApi.reducerPath]: appApi.reducer,
|
||||
})
|
||||
|
||||
export const setupStore = () =>
|
||||
configureStore({
|
||||
reducer: rootReducer,
|
||||
middleware: (getDefaultMiddleware) =>
|
||||
getDefaultMiddleware().concat([roleApi.middleware])
|
||||
getDefaultMiddleware().concat(
|
||||
roleApi.middleware,
|
||||
appApi.middleware,
|
||||
)
|
||||
})
|
||||
|
||||
export type RootState = ReturnType<typeof rootReducer>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
interface TokenType {
|
||||
appId: boolean
|
||||
createdAt: string
|
||||
expireTime: boolean
|
||||
token: string
|
||||
}
|
||||
|
||||
export interface SystemTreeAppType {
|
||||
description: string
|
||||
id: boolean
|
||||
name: string
|
||||
tokens: TokenType[]
|
||||
type: string
|
||||
}
|
||||
|
||||
interface SystemServiceType {
|
||||
apps: SystemTreeAppType[]
|
||||
description: string
|
||||
id: boolean
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface DomainType {
|
||||
description: string
|
||||
id: boolean
|
||||
name: string
|
||||
services: SystemServiceType[]
|
||||
}
|
||||
|
||||
export interface AppApiResponseType {
|
||||
originalResponse: DomainType[]
|
||||
appList: SystemTreeAppType[]
|
||||
}
|
||||
Reference in new issue
Block a user