diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 61ccfaa..eb5544b 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -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] diff --git a/src/app/services/data.service.ts b/src/app/services/data.service.ts index 750557b..1dc65ad 100644 --- a/src/app/services/data.service.ts +++ b/src/app/services/data.service.ts @@ -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 { + return this.http.get(`${this.apiUrl}/get/${type}/${id}`); + } + + getSong(id: number | string): Observable { + return this.get('song', id); + } + + getAlbum(id: number | string): Observable { + return this.get('album', id); + } + + getArtist(id: number | string): Observable { + return this.get('artist', id); + } + + getAllAlbums(): Observable { + return this.get('album', 'all'); + } + + getAllArtists(): Observable { + return this.get('artist', 'all'); + } }