[ARVADOS-WORKBENCH2] updated: 1.1.4-327-ge9ddb40

Git user git at public.curoverse.com
Wed Jul 18 05:28:42 EDT 2018


Summary of changes:
 src/models/link.ts                                | 10 ++--
 src/services/favorite-service/favorite-service.ts | 62 +++++++++++++++++++++++
 src/services/link-service/link-service.ts         |  6 +--
 src/services/services.ts                          |  2 +
 4 files changed, 74 insertions(+), 6 deletions(-)
 create mode 100644 src/services/favorite-service/favorite-service.ts

       via  e9ddb402bae21b72cc23ac71d492bca9d92eb356 (commit)
      from  8cc7e7304d11fb7940a9c68092c7f614e4e5fcea (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit e9ddb402bae21b72cc23ac71d492bca9d92eb356
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Wed Jul 18 11:28:26 2018 +0200

    Create FavoriteService
    
    Feature #13840
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/models/link.ts b/src/models/link.ts
index 26cce6e..8686528 100644
--- a/src/models/link.ts
+++ b/src/models/link.ts
@@ -1,13 +1,17 @@
-import { Resource } from "./resource";
-
 // Copyright (C) The Arvados Authors. All rights reserved.
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-export interface Link extends Resource {
+import { Resource } from "./resource";
+
+export interface LinkResource extends Resource {
     headUuid: string;
     tailUuid: string;
     linkClass: string;
     name: string;
     properties: {};
 }
+
+export enum LinkClass {
+    STAR = 'star'
+}
\ No newline at end of file
diff --git a/src/services/favorite-service/favorite-service.ts b/src/services/favorite-service/favorite-service.ts
new file mode 100644
index 0000000..3d852ce
--- /dev/null
+++ b/src/services/favorite-service/favorite-service.ts
@@ -0,0 +1,62 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import LinkService from "../link-service/link-service";
+import GroupsService, { GroupContentsResource } from "../groups-service/groups-service";
+import { LinkResource, LinkClass } from "../../models/link";
+import FilterBuilder from "../../common/api/filter-builder";
+import { ListArguments, ListResults } from "../../common/api/common-resource-service";
+
+export default class FavoriteService {
+    constructor(
+        private linkService: LinkService,
+        private groupsService: GroupsService
+    ) { }
+
+    create(data: { userUuid: string; resourceUuid: string; }) {
+        return this.linkService.create({
+            ownerUuid: data.userUuid,
+            tailUuid: data.userUuid,
+            headUuid: data.resourceUuid,
+            linkClass: LinkClass.STAR,
+            name: data.resourceUuid
+        });
+    }
+
+    delete(data: { userUuid: string; resourceUuid: string; }) {
+        return this.linkService
+            .list({
+                filters: FilterBuilder
+                    .create<LinkResource>()
+                    .addEqual('tailUuid', data.userUuid)
+                    .addEqual('headUuid', data.resourceUuid)
+                    .addEqual('linkClass', LinkClass.STAR)
+            })
+            .then(results => Promise.all(
+                results.items.map(item => this.linkService.delete(item.uuid))));
+    }
+
+    list(userUuid: string, args: ListArguments = {}): Promise<ListResults<GroupContentsResource>> {
+        const listFilter = FilterBuilder
+            .create<LinkResource>()
+            .addEqual('tailUuid', userUuid)
+            .addEqual('linkClass', LinkClass.STAR);
+
+        return this.linkService
+            .list({
+                ...args,
+                filters: args.filters ? args.filters.concat(listFilter) : listFilter
+            })
+            .then(results => {
+                const uuids = results.items.map(item => item.headUuid);
+                return this.groupsService.contents(userUuid, {
+                    limit: args.limit,
+                    offset: args.offset,
+                    filters: FilterBuilder.create<GroupContentsResource>().addIn('uuid', uuids)
+                });
+            });
+    }
+
+
+}
\ No newline at end of file
diff --git a/src/services/link-service/link-service.ts b/src/services/link-service/link-service.ts
index 49e6d1f..2fb75d5 100644
--- a/src/services/link-service/link-service.ts
+++ b/src/services/link-service/link-service.ts
@@ -3,10 +3,10 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import CommonResourceService from "../../common/api/common-resource-service";
-import { Link } from "../../models/link";
-import { AxiosInstance } from "../../../node_modules/axios";
+import { LinkResource } from "../../models/link";
+import { AxiosInstance } from "axios";
 
-export default class LinkService<T extends Link = Link> extends CommonResourceService<T> {
+export default class LinkService extends CommonResourceService<LinkResource> {
     constructor(serverApi: AxiosInstance) {
         super(serverApi, "links");
     }
diff --git a/src/services/services.ts b/src/services/services.ts
index fbd2f6e..6f3d3a9 100644
--- a/src/services/services.ts
+++ b/src/services/services.ts
@@ -7,8 +7,10 @@ import GroupsService from "./groups-service/groups-service";
 import { serverApi } from "../common/api/server-api";
 import ProjectService from "./project-service/project-service";
 import LinkService from "./link-service/link-service";
+import FavoriteService from "./favorite-service/favorite-service";
 
 export const authService = new AuthService(serverApi);
 export const groupsService = new GroupsService(serverApi);
 export const projectService = new ProjectService(serverApi);
 export const linkService = new LinkService(serverApi);
+export const favoriteService = new FavoriteService(linkService, groupsService);

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list