From e620e01037feb681d63d078d4165a76b1699808a Mon Sep 17 00:00:00 2001 From: stickyPiston Date: Sat, 21 Sep 2019 15:14:44 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=BD=20Created=20code=20for=20the=20Dat?= =?UTF-8?q?aService.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Just some simple get commands. --- src/app/app.module.ts | 5 ++++- src/app/services/data.service.ts | 30 +++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) 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'); + } }