Creating Stores and using Observables

Change-Id: I214692e64df065beaddee0e0ec8759de540c269d
diff --git a/src/app/datasources/rest/auth.rest.ts b/src/app/datasources/rest/auth.rest.ts
new file mode 100644
index 0000000..a94599a
--- /dev/null
+++ b/src/app/datasources/rest/auth.rest.ts
@@ -0,0 +1,41 @@
+import {AppConfig} from '../../config/app.config';
+import IHttpPromiseCallbackArg = angular.IHttpPromiseCallbackArg;
+export interface IAuthRequestData {
+  username: string;
+  password: string;
+}
+
+export interface IAuthResponseData extends IHttpPromiseCallbackArg<any> {
+  data: {
+    user: string;
+    xoscsrftoken: string;
+    xossessionid: string;
+  };
+}
+export class AuthService {
+
+
+  /** @ngInject */
+  constructor(
+    private $http: angular.IHttpService,
+    private $q: angular.IQService,
+    private $cookies: angular.cookies.ICookiesService
+  ) {
+  }
+
+  public login(data: IAuthRequestData): Promise<any> {
+    const d = this.$q.defer();
+    this.$http.post(`${AppConfig.apiEndpoint}/utility/login/`, data)
+      .then((res: IAuthResponseData) => {
+        this.$cookies.put('xoscsrftoken', res.data.xoscsrftoken);
+        this.$cookies.put('xossessionid', res.data.xossessionid);
+        this.$cookies.put('xosuser', res.data.user);
+        res.data.user = JSON.parse(res.data.user);
+        d.resolve(res.data);
+      })
+      .catch(e => {
+        d.reject(e);
+      });
+    return d.promise;
+  }
+}
diff --git a/src/app/datasources/rest/core.rest.ts b/src/app/datasources/rest/core.rest.ts
new file mode 100644
index 0000000..2c10e10
--- /dev/null
+++ b/src/app/datasources/rest/core.rest.ts
@@ -0,0 +1,18 @@
+import {AppConfig} from '../../config/app.config';
+export class CoreRest {
+
+  /** @ngInject */
+  constructor(
+    private $http: angular.IHttpService,
+    private $q: angular.IQService
+  ) {
+  }
+
+  public query(): Promise<any> {
+    const d = this.$q.defer();
+    this.$http.get(`${AppConfig.apiEndpoint}/core/`)
+      .then(res => d.resolve(res.data))
+      .catch(d.reject);
+    return d.promise;
+  }
+}
diff --git a/src/app/datasources/rest/slices.rest.ts b/src/app/datasources/rest/slices.rest.ts
new file mode 100644
index 0000000..a5b7e5c
--- /dev/null
+++ b/src/app/datasources/rest/slices.rest.ts
@@ -0,0 +1,21 @@
+import {AppConfig} from '../../config/app.config';
+
+export interface IXosResourceService {
+  getResource(): ng.resource.IResourceClass<any>;
+}
+
+export class SlicesRest implements IXosResourceService {
+  static $inject = ['$resource'];
+  private resource: angular.resource.IResourceClass<any>;
+
+  /** @ngInject */
+  constructor(
+    private $resource: ng.resource.IResourceService
+  ) {
+    this.resource = this.$resource(`${AppConfig.apiEndpoint}/core/slices/`);
+  }
+
+  public getResource(): ng.resource.IResourceClass<ng.resource.IResource<any>> {
+    return this.resource;
+  }
+}