👽 Created code for the DataService.
Just some simple get commands.
This commit is contained in:
parent
6957c17907
commit
e620e01037
@ -1,6 +1,8 @@
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
|
||||
import { AppRoutingModule } from './app-routing.module';
|
||||
import { AppComponent } from './app.component';
|
||||
import { HomeComponent } from './components/home/home.component';
|
||||
@ -18,7 +20,8 @@ import { AlbumsComponent } from './components/albums/albums.component';
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
AppRoutingModule
|
||||
AppRoutingModule,
|
||||
HttpClientModule
|
||||
],
|
||||
providers: [],
|
||||
bootstrap: [AppComponent]
|
||||
|
@ -1,9 +1,37 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DataService {
|
||||
|
||||
constructor() { }
|
||||
private apiUrl = 'http://localhost:673';
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
get(type: string, id: string | number): Observable<object> {
|
||||
return this.http.get(`${this.apiUrl}/get/${type}/${id}`);
|
||||
}
|
||||
|
||||
getSong(id: number | string): Observable<object> {
|
||||
return this.get('song', id);
|
||||
}
|
||||
|
||||
getAlbum(id: number | string): Observable<object> {
|
||||
return this.get('album', id);
|
||||
}
|
||||
|
||||
getArtist(id: number | string): Observable<object> {
|
||||
return this.get('artist', id);
|
||||
}
|
||||
|
||||
getAllAlbums(): Observable<object> {
|
||||
return this.get('album', 'all');
|
||||
}
|
||||
|
||||
getAllArtists(): Observable<object> {
|
||||
return this.get('artist', 'all');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user