From b99290b1d5d736083513fb8f66e91f61bfe07e0b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 23 Jan 2017 22:32:43 +0100 Subject: Client: lazy load admin area --- .../src/app/+admin/friends/shared/friend.model.ts | 6 +++ .../app/+admin/friends/shared/friend.service.ts | 47 ++++++++++++++++++++++ client/src/app/+admin/friends/shared/index.ts | 2 + 3 files changed, 55 insertions(+) create mode 100644 client/src/app/+admin/friends/shared/friend.model.ts create mode 100644 client/src/app/+admin/friends/shared/friend.service.ts create mode 100644 client/src/app/+admin/friends/shared/index.ts (limited to 'client/src/app/+admin/friends/shared') diff --git a/client/src/app/+admin/friends/shared/friend.model.ts b/client/src/app/+admin/friends/shared/friend.model.ts new file mode 100644 index 000000000..462cc82ed --- /dev/null +++ b/client/src/app/+admin/friends/shared/friend.model.ts @@ -0,0 +1,6 @@ +export interface Friend { + id: string; + host: string; + score: number; + createdAt: Date; +} diff --git a/client/src/app/+admin/friends/shared/friend.service.ts b/client/src/app/+admin/friends/shared/friend.service.ts new file mode 100644 index 000000000..e97459385 --- /dev/null +++ b/client/src/app/+admin/friends/shared/friend.service.ts @@ -0,0 +1,47 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/operator/catch'; +import 'rxjs/add/operator/map'; + +import { Friend } from './friend.model'; +import { AuthHttp, RestExtractor, ResultList } from '../../../shared'; + +@Injectable() +export class FriendService { + private static BASE_FRIEND_URL: string = '/api/v1/pods/'; + + constructor ( + private authHttp: AuthHttp, + private restExtractor: RestExtractor + ) {} + + getFriends() { + return this.authHttp.get(FriendService.BASE_FRIEND_URL) + .map(this.restExtractor.extractDataList) + .map(this.extractFriends) + .catch((res) => this.restExtractor.handleError(res)); + } + + makeFriends(notEmptyHosts) { + const body = { + hosts: notEmptyHosts + }; + + return this.authHttp.post(FriendService.BASE_FRIEND_URL + 'makefriends', body) + .map(this.restExtractor.extractDataBool) + .catch((res) => this.restExtractor.handleError(res)); + } + + quitFriends() { + return this.authHttp.get(FriendService.BASE_FRIEND_URL + 'quitfriends') + .map(res => res.status) + .catch((res) => this.restExtractor.handleError(res)); + } + + private extractFriends(result: ResultList) { + const friends: Friend[] = result.data; + const totalFriends = result.total; + + return { friends, totalFriends }; + } +} diff --git a/client/src/app/+admin/friends/shared/index.ts b/client/src/app/+admin/friends/shared/index.ts new file mode 100644 index 000000000..0d671637d --- /dev/null +++ b/client/src/app/+admin/friends/shared/index.ts @@ -0,0 +1,2 @@ +export * from './friend.model'; +export * from './friend.service'; -- cgit v1.2.3