mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
feat: top genres report
This commit is contained in:
parent
62119d44b0
commit
a0c28e2324
21 changed files with 317 additions and 104 deletions
|
|
@ -9,6 +9,8 @@ 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";
|
||||
import { TopGenresItem } from "./entities/top-genres-item";
|
||||
import { TopGenresOptions } from "./entities/top-genres-options";
|
||||
import { TopTracksItem } from "./entities/top-tracks-item";
|
||||
import { TopTracksOptions } from "./entities/top-tracks-options";
|
||||
|
||||
|
|
@ -188,3 +190,40 @@ export const getTopTracks = async (
|
|||
} = res;
|
||||
return items;
|
||||
};
|
||||
|
||||
export const getTopGenres = async (
|
||||
options: TopGenresOptions,
|
||||
client: AxiosInstance
|
||||
): Promise<TopGenresItem[]> => {
|
||||
const {
|
||||
time: { timePreset, customTimeStart, customTimeEnd },
|
||||
} = options;
|
||||
|
||||
const res = await client.get<{ items: TopGenresItem[] }>(
|
||||
`/api/v1/reports/top-Genres`,
|
||||
{
|
||||
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 getTopGenres: ${res.status}`);
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
data: { items },
|
||||
} = res;
|
||||
return items;
|
||||
};
|
||||
|
|
|
|||
4
frontend/src/api/entities/genre.ts
Normal file
4
frontend/src/api/entities/genre.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
export interface Genre {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
8
frontend/src/api/entities/top-genres-item.ts
Normal file
8
frontend/src/api/entities/top-genres-item.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { Genre } from "./genre";
|
||||
import { TopArtistsItem } from "./top-artists-item";
|
||||
|
||||
export interface TopGenresItem {
|
||||
genre: Genre;
|
||||
artists: TopArtistsItem[];
|
||||
count: number;
|
||||
}
|
||||
5
frontend/src/api/entities/top-genres-options.ts
Normal file
5
frontend/src/api/entities/top-genres-options.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { TimeOptions } from "./time-options";
|
||||
|
||||
export interface TopGenresOptions {
|
||||
time: TimeOptions;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue