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'); }