Implement resource moving
[arvados-workbench2.git] / src / services / services.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import Axios, { AxiosInstance } from "axios";
6 import { AuthService } from "./auth-service/auth-service";
7 import { GroupsService } from "./groups-service/groups-service";
8 import { ProjectService } from "./project-service/project-service";
9 import { LinkService } from "./link-service/link-service";
10 import { FavoriteService } from "./favorite-service/favorite-service";
11 import { CollectionService } from "./collection-service/collection-service";
12 import { TagService } from "./tag-service/tag-service";
13 import { CollectionFilesService } from "./collection-files-service/collection-files-service";
14 import { KeepService } from "./keep-service/keep-service";
15 import { WebDAV } from "../common/webdav";
16 import { Config } from "../common/config";
17 import { ResourceKind } from '~/models/resource';
18
19 export type ServiceRepository = ReturnType<typeof createServices>;
20
21 export const createServices = (config: Config) => {
22     const apiClient = Axios.create();
23     apiClient.defaults.baseURL = `${config.apiHost}/arvados/v1`;
24
25     const webdavClient = new WebDAV();
26     webdavClient.defaults.baseURL = config.keepWebHost;
27
28     const authService = new AuthService(apiClient, config.apiHost);
29     const keepService = new KeepService(apiClient);
30     const groupsService = new GroupsService(apiClient);
31     const projectService = new ProjectService(apiClient);
32     const linkService = new LinkService(apiClient);
33     const favoriteService = new FavoriteService(linkService, groupsService);
34     const collectionService = new CollectionService(apiClient, webdavClient, authService);
35     const tagService = new TagService(linkService);
36     const collectionFilesService = new CollectionFilesService(collectionService);
37
38     return {
39         apiClient,
40         webdavClient,
41         authService,
42         keepService,
43         groupsService,
44         projectService,
45         linkService,
46         favoriteService,
47         collectionService,
48         tagService,
49         collectionFilesService
50     };
51 };
52
53 export const getResourceService = (resourceKind: ResourceKind, serviceRepository: ServiceRepository) => {
54     switch (resourceKind) {
55         case ResourceKind.PROJECT:
56             return serviceRepository.projectService;
57         case ResourceKind.COLLECTION:
58             return serviceRepository.collectionService;
59         default:
60             return undefined;
61     }
62 };
63