2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 import { IAuthor } from '../models/author';
20 import * as $ from 'jquery';
22 const base_url = 'https://api.mfico.de/v1/authors';
25 * Represents a web api accessor service for all author related actions.
30 * Gets all known authors from the backend.
31 * @returns A promise of the type array of @see {@link IAuthor} containing all known authors.
33 public getAllAuthors(): Promise<IAuthor[]> {
34 return new Promise((resolve: (value: IAuthor[]) => void, reject: (err: any) => void) => {
35 $.ajax({ method: 'GET', url: base_url })
36 .then((data) => { resolve(data); }, (err) => { reject(err); });
41 * Gets an author by its id from the backend.
42 * @returns A promise of the type @see {@link IAuthor} containing the author to get.
44 public getAuthorById(id: string | number): Promise<IAuthor> {
45 return new Promise((resolve: (value: IAuthor) => void, reject: (err: any) => void) => {
46 $.ajax({ method: 'GET', url: base_url + '/' + id })
47 .then((data) => { resolve(data); }, (err) => { reject(err); });
53 * Saves the given author to the backend api.
54 * @returns A promise of the type @see {@link IAuthor} containing the autor returned by the backend api.
56 public saveAuthor(author: IAuthor): Promise<IAuthor> {
57 return new Promise((resolve: (value: IAuthor) => void, reject: (err: any) => void) => {
58 // simulate server save
59 window.setTimeout(() => {
60 if (Math.random() > 0.8) {
61 reject('Could not save author.');
65 }, 800); // simulate a short network delay
70 // return as a singleton
71 export const authorService = new AuthorService();
72 export default authorService;