From e4a04a675f306408a70870c276b9cbbbb5b31d5b Mon Sep 17 00:00:00 2001 From: stickyPiston Date: Sat, 21 Sep 2019 15:45:43 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Added=20jsdoc=20comments=20to=20?= =?UTF-8?q?DataService.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Trying my best to keep this up. --- src/app/services/data.service.ts | 33 +++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/app/services/data.service.ts b/src/app/services/data.service.ts index 1dc65ad..b885774 100644 --- a/src/app/services/data.service.ts +++ b/src/app/services/data.service.ts @@ -2,6 +2,12 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; +/** + * The DataService handles all data traffic to and from the API. + * @example Get a song by id. + * // returns something like {result: {id: 0, name: "Thunderstruck", artist: "AC/DC"}} + * DataService.getSong(0); + */ @Injectable({ providedIn: 'root' }) @@ -10,27 +16,52 @@ export class DataService { private apiUrl = 'http://localhost:673'; constructor(private http: HttpClient) { } - + /** + * @param type The type of the thing you want to get. The type is a string containing either 'artist', 'album' or 'song'. + * @param id The id of the artist. It can be a number representing the id, multiple numbers seperated by commas or the string 'all'. + * @returns An Observable containing the returned data from the API. + */ get(type: string, id: string | number): Observable { return this.http.get(`${this.apiUrl}/get/${type}/${id}`); } + /** + * @param id The id of the artist. It can be a number representing the id, multiple numbers seperated by commas or the string 'all'. + * @returns An Observable containing the returned data from the API. + */ getSong(id: number | string): Observable { return this.get('song', id); } + /** + * @param id The id of the artist. It can be a number representing the id, multiple numbers seperated by commas or the string 'all'. + * @returns An Observable containing the returned data from the API. + */ getAlbum(id: number | string): Observable { return this.get('album', id); } + /** + * A function to get one, multiple or all artists. + * @param id The id of the artist. It can be a number representing the id, multiple numbers seperated by commas or the string 'all'. + * @returns An Observable containing the returned data from the API. + */ getArtist(id: number | string): Observable { return this.get('artist', id); } + /** + * A function to get all albums from the API. + * @returns An Observable containing the returned data from the API. + */ getAllAlbums(): Observable { return this.get('album', 'all'); } + /** + * A function to get all artists from the API. + * @returns An Observable containing the returned data from the API. + */ getAllArtists(): Observable { return this.get('artist', 'all'); }