WIP Simplify ELS Service

Next step: use function
This commit is contained in:
2017-10-29 02:39:59 +02:00
parent 4cb5dc44e3
commit ab493346a5

View File

@@ -101,8 +101,6 @@ export class ElsService {
getMostPlayedTrack(): Observable<Song[]> {
// Thank to http://chariotsolutions.com/blog/post/angular2-observables-http-separating-services-components/
// for the map part
// Could be shorter but I think it's more readable like this.
return this.http
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
JSON.stringify({
@@ -114,23 +112,12 @@ export class ElsService {
'size': 5
}), {headers: this.headers})
.map(res => {
return res.json().hits.hits;
})
.map((hits: Array<any>) => {
const result: Array<Song> = [];
hits.forEach((hit) => {
result.push(hit._source);
res.json().hits.hits.forEach(element => {
result.push(element._source);
});
return result;
});
// Shorter way:
// .map(res => {
// let result: Array<Song> = [];
// res.json().hits.hits.forEach(element => {
// result.push(element._source);
// });
// return result;
// });
}
getAlbumSongs(albumName: string, from: number = 0): Observable<Song[]> {
@@ -145,11 +132,8 @@ export class ElsService {
'from': from
}), {headers: this.headers})
.map(res => {
return res.json().hits.hits;
})
.map((hits: Array<any>) => {
const result: Array<Song> = [];
hits.forEach((hit) => {
res.json().hits.hits.forEach((hit) => {
result.push(hit._source);
});
return result;
@@ -169,11 +153,8 @@ export class ElsService {
'from': from
}), {headers: this.headers})
.map(res => {
return res.json().hits.hits;
})
.map((hits: Array<any>) => {
const result: Array<Song> = [];
hits.forEach((hit) => {
res.json().hits.hits.forEach((hit) => {
result.push(hit._source);
});
return result;
@@ -197,11 +178,8 @@ export class ElsService {
'from': from
}), {headers: this.headers})
.map(res => {
return res.json().hits.hits;
})
.map((hits: Array<any>) => {
const result: Array<Song> = [];
hits.forEach((hit) => {
res.json().hits.hits.forEach((hit) => {
result.push(hit._source);
});
return result;
@@ -310,7 +288,7 @@ export class ElsService {
'album' : {
'terms' : {
'field' : 'Album.original',
'size': 10
'size': 150
}
}
},