Create container request service
[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 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 { UserService } from './user-service/user-service';
18 import { AncestorService } from "~/services/ancestors-service/ancestors-service";
19 import { ResourceKind } from "~/models/resource";
20 import { ContainerRequestService } from './container-request-service/container-request-service';
21
22 export type ServiceRepository = ReturnType<typeof createServices>;
23
24 export const createServices = (config: Config) => {
25     const apiClient = Axios.create();
26     apiClient.defaults.baseURL = config.baseUrl;
27
28     const webdavClient = new WebDAV();
29     webdavClient.defaults.baseURL = config.keepWebServiceUrl;
30
31     const groupsService = new GroupsService(apiClient);
32     const keepService = new KeepService(apiClient);
33     const linkService = new LinkService(apiClient);
34     const projectService = new ProjectService(apiClient);
35     const userService = new UserService(apiClient);
36     const containerRequestService = new ContainerRequestService(apiClient);
37     
38     const ancestorsService = new AncestorService(groupsService, userService);
39     const authService = new AuthService(apiClient, config.rootUrl);
40     const collectionService = new CollectionService(apiClient, webdavClient, authService);
41     const collectionFilesService = new CollectionFilesService(collectionService);
42     const favoriteService = new FavoriteService(linkService, groupsService);
43     const tagService = new TagService(linkService);
44
45     return {
46         ancestorsService,
47         apiClient,
48         authService,
49         collectionFilesService,
50         collectionService,
51         containerRequestService,
52         favoriteService,
53         groupsService,
54         keepService,
55         linkService,
56         projectService,
57         tagService,
58         userService,
59         webdavClient,
60     };
61 };
62
63 export const getResourceService = (kind?: ResourceKind) => (serviceRepository: ServiceRepository) => {
64     switch (kind) {
65         case ResourceKind.USER:
66             return serviceRepository.userService;
67         case ResourceKind.GROUP:
68             return serviceRepository.groupsService;
69         case ResourceKind.COLLECTION:
70             return serviceRepository.collectionService;
71         default:
72             return undefined;
73     }
74 };