AlbumQuery and ArtistQuery types on MusicService

This commit is contained in:
simojenki
2021-03-02 10:24:55 +11:00
parent bdee01d2c7
commit 06024e8e36
5 changed files with 39 additions and 76 deletions

View File

@@ -9,7 +9,8 @@ import {
AuthFailure,
Artist,
MusicLibrary,
Paging,
ArtistQuery,
AlbumQuery,
slice2,
asResult,
} from "../src/music_service";
@@ -57,9 +58,9 @@ export class InMemoryMusicService implements MusicService {
if (this.users[credentials.username] != credentials.password)
return Promise.reject("Invalid auth token");
return Promise.resolve({
artists: (paging: Paging) =>
artists: (q: ArtistQuery) =>
Promise.resolve(this.artists.map(artistWithAlbumsToArtist))
.then(slice2(paging))
.then(slice2(q))
.then(asResult),
artist: (id: string) =>
pipe(
@@ -68,26 +69,18 @@ export class InMemoryMusicService implements MusicService {
O.map(artistWithAlbumsToArtist),
getOrThrow(`No artist with id '${id}'`)
),
albums: ({
artistId,
_index,
_count,
}: {
artistId?: string;
_index?: number;
_count?: number;
}) =>
albums: (q: AlbumQuery) =>
Promise.resolve(
this.artists.filter(
pipe(
O.fromNullable(artistId),
O.fromNullable(q.artistId),
O.map(artistWithId),
O.getOrElse(() => all)
)
)
)
.then((artists) => artists.flatMap((it) => it.albums))
.then(slice2({ _index, _count }))
.then(slice2(q))
.then(asResult),
});
}