👽 Created code for the DataService.

Just some simple get commands.
This commit is contained in:
corner 2019-09-21 15:14:44 +02:00
parent 6957c17907
commit e620e01037
2 changed files with 33 additions and 2 deletions

View File

@ -1,6 +1,8 @@
import { BrowserModule } from '@angular/platform-browser'; import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { AppRoutingModule } from './app-routing.module'; import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { HomeComponent } from './components/home/home.component'; import { HomeComponent } from './components/home/home.component';
@ -18,7 +20,8 @@ import { AlbumsComponent } from './components/albums/albums.component';
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
AppRoutingModule AppRoutingModule,
HttpClientModule
], ],
providers: [], providers: [],
bootstrap: [AppComponent] bootstrap: [AppComponent]

View File

@ -1,9 +1,37 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class DataService { 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');
}
} }