WIP Simplify ELS Service
Next step: use function
This commit is contained in:
@@ -101,8 +101,6 @@ export class ElsService {
|
|||||||
getMostPlayedTrack(): Observable<Song[]> {
|
getMostPlayedTrack(): Observable<Song[]> {
|
||||||
// Thank to http://chariotsolutions.com/blog/post/angular2-observables-http-separating-services-components/
|
// Thank to http://chariotsolutions.com/blog/post/angular2-observables-http-separating-services-components/
|
||||||
// for the map part
|
// for the map part
|
||||||
|
|
||||||
// Could be shorter but I think it's more readable like this.
|
|
||||||
return this.http
|
return this.http
|
||||||
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
|
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -114,23 +112,12 @@ export class ElsService {
|
|||||||
'size': 5
|
'size': 5
|
||||||
}), {headers: this.headers})
|
}), {headers: this.headers})
|
||||||
.map(res => {
|
.map(res => {
|
||||||
return res.json().hits.hits;
|
|
||||||
})
|
|
||||||
.map((hits: Array<any>) => {
|
|
||||||
const result: Array<Song> = [];
|
const result: Array<Song> = [];
|
||||||
hits.forEach((hit) => {
|
res.json().hits.hits.forEach(element => {
|
||||||
result.push(hit._source);
|
result.push(element._source);
|
||||||
});
|
});
|
||||||
return result;
|
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[]> {
|
getAlbumSongs(albumName: string, from: number = 0): Observable<Song[]> {
|
||||||
@@ -145,11 +132,8 @@ export class ElsService {
|
|||||||
'from': from
|
'from': from
|
||||||
}), {headers: this.headers})
|
}), {headers: this.headers})
|
||||||
.map(res => {
|
.map(res => {
|
||||||
return res.json().hits.hits;
|
|
||||||
})
|
|
||||||
.map((hits: Array<any>) => {
|
|
||||||
const result: Array<Song> = [];
|
const result: Array<Song> = [];
|
||||||
hits.forEach((hit) => {
|
res.json().hits.hits.forEach((hit) => {
|
||||||
result.push(hit._source);
|
result.push(hit._source);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
@@ -169,11 +153,8 @@ export class ElsService {
|
|||||||
'from': from
|
'from': from
|
||||||
}), {headers: this.headers})
|
}), {headers: this.headers})
|
||||||
.map(res => {
|
.map(res => {
|
||||||
return res.json().hits.hits;
|
|
||||||
})
|
|
||||||
.map((hits: Array<any>) => {
|
|
||||||
const result: Array<Song> = [];
|
const result: Array<Song> = [];
|
||||||
hits.forEach((hit) => {
|
res.json().hits.hits.forEach((hit) => {
|
||||||
result.push(hit._source);
|
result.push(hit._source);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
@@ -197,11 +178,8 @@ export class ElsService {
|
|||||||
'from': from
|
'from': from
|
||||||
}), {headers: this.headers})
|
}), {headers: this.headers})
|
||||||
.map(res => {
|
.map(res => {
|
||||||
return res.json().hits.hits;
|
|
||||||
})
|
|
||||||
.map((hits: Array<any>) => {
|
|
||||||
const result: Array<Song> = [];
|
const result: Array<Song> = [];
|
||||||
hits.forEach((hit) => {
|
res.json().hits.hits.forEach((hit) => {
|
||||||
result.push(hit._source);
|
result.push(hit._source);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
@@ -310,7 +288,7 @@ export class ElsService {
|
|||||||
'album' : {
|
'album' : {
|
||||||
'terms' : {
|
'terms' : {
|
||||||
'field' : 'Album.original',
|
'field' : 'Album.original',
|
||||||
'size': 10
|
'size': 150
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user