📝 Added jsdoc comments to DataService.
Trying my best to keep this up.
This commit is contained in:
parent
de242382a7
commit
e4a04a675f
@ -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<object> containing the returned data from the API.
|
||||
*/
|
||||
get(type: string, id: string | number): Observable<object> {
|
||||
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<object> containing the returned data from the API.
|
||||
*/
|
||||
getSong(id: number | string): Observable<object> {
|
||||
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<object> containing the returned data from the API.
|
||||
*/
|
||||
getAlbum(id: number | string): Observable<object> {
|
||||
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<object> containing the returned data from the API.
|
||||
*/
|
||||
getArtist(id: number | string): Observable<object> {
|
||||
return this.get('artist', id);
|
||||
}
|
||||
|
||||
/**
|
||||
* A function to get all albums from the API.
|
||||
* @returns An Observable<object> containing the returned data from the API.
|
||||
*/
|
||||
getAllAlbums(): Observable<object> {
|
||||
return this.get('album', 'all');
|
||||
}
|
||||
|
||||
/**
|
||||
* A function to get all artists from the API.
|
||||
* @returns An Observable<object> containing the returned data from the API.
|
||||
*/
|
||||
getAllArtists(): Observable<object> {
|
||||
return this.get('artist', 'all');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user