mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
feat: introduce new report "Top Albums"
This commit is contained in:
parent
09858076bf
commit
9896ea31ff
16 changed files with 246 additions and 9 deletions
|
|
@ -5,6 +5,8 @@ import { ListenReportItem } from "./entities/listen-report-item";
|
|||
import { ListenReportOptions } from "./entities/listen-report-options";
|
||||
import { Pagination } from "./entities/pagination";
|
||||
import { PaginationOptions } from "./entities/pagination-options";
|
||||
import { TopAlbumsItem } from "./entities/top-albums-item";
|
||||
import { TopAlbumsOptions } from "./entities/top-albums-options";
|
||||
import { TopArtistsItem } from "./entities/top-artists-item";
|
||||
import { TopArtistsOptions } from "./entities/top-artists-options";
|
||||
|
||||
|
|
@ -110,3 +112,40 @@ export const getTopArtists = async (
|
|||
} = res;
|
||||
return items;
|
||||
};
|
||||
|
||||
export const getTopAlbums = async (
|
||||
options: TopAlbumsOptions,
|
||||
client: AxiosInstance
|
||||
): Promise<TopAlbumsItem[]> => {
|
||||
const {
|
||||
time: { timePreset, customTimeStart, customTimeEnd },
|
||||
} = options;
|
||||
|
||||
const res = await client.get<{ items: TopAlbumsItem[] }>(
|
||||
`/api/v1/reports/top-albums`,
|
||||
{
|
||||
params: {
|
||||
timePreset,
|
||||
customTimeStart: formatISO(customTimeStart),
|
||||
customTimeEnd: formatISO(customTimeEnd),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
switch (res.status) {
|
||||
case 200: {
|
||||
break;
|
||||
}
|
||||
case 401: {
|
||||
throw new UnauthenticatedError(`No token or token expired`);
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unable to getTopAlbums: ${res.status}`);
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
data: { items },
|
||||
} = res;
|
||||
return items;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import { Artist } from "./artist";
|
||||
import { SpotifyInfo } from "./spotify-info";
|
||||
|
||||
export interface Album {
|
||||
id: string;
|
||||
name: string;
|
||||
spotify?: SpotifyInfo;
|
||||
artists?: Artist[];
|
||||
}
|
||||
|
|
|
|||
6
frontend/src/api/entities/top-albums-item.ts
Normal file
6
frontend/src/api/entities/top-albums-item.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import { Album } from "./album";
|
||||
|
||||
export interface TopAlbumsItem {
|
||||
album: Album;
|
||||
count: number;
|
||||
}
|
||||
5
frontend/src/api/entities/top-albums-options.ts
Normal file
5
frontend/src/api/entities/top-albums-options.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { TimeOptions } from "./time-options";
|
||||
|
||||
export interface TopAlbumsOptions {
|
||||
time: TimeOptions;
|
||||
}
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
import { TimePreset } from "./time-preset.enum";
|
||||
import { TimeOptions } from "./time-options";
|
||||
|
||||
export interface TopArtistsOptions {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue