Allow songs to be searched and filtered by genres
This commit is contained in:
@@ -39,15 +39,17 @@ export class SearchController {
|
||||
@ApiUnauthorizedResponse({ description: "Invalid token" })
|
||||
async searchSong(
|
||||
@Request() req: any,
|
||||
@Param("query") query: string,
|
||||
@Param("artistId") artistId: number,
|
||||
@Query("include") include: string,
|
||||
@Query("skip", new DefaultValuePipe(0), ParseIntPipe) skip: number,
|
||||
@Query("take", new DefaultValuePipe(20), ParseIntPipe) take: number,
|
||||
@Param('query') query: string,
|
||||
@Query('artistId') artistId: number,
|
||||
@Query('genreId') genreId: number,
|
||||
@Query('include') include: string,
|
||||
@Query('skip', new DefaultValuePipe(0), ParseIntPipe) skip: number,
|
||||
@Query('take', new DefaultValuePipe(20), ParseIntPipe) take: number,
|
||||
): Promise<Song[] | null> {
|
||||
return await this.searchService.searchSong(
|
||||
query,
|
||||
artistId,
|
||||
genreId,
|
||||
mapInclude(include, req, SongController.includableFields),
|
||||
skip,
|
||||
take,
|
||||
|
||||
@@ -15,6 +15,7 @@ export class SearchService {
|
||||
async searchSong(
|
||||
query: string,
|
||||
artistId?: number,
|
||||
genreId?: number,
|
||||
include?: Prisma.SongInclude,
|
||||
skip?: number,
|
||||
take?: number,
|
||||
@@ -23,6 +24,7 @@ export class SearchService {
|
||||
return await this.prisma.song.findMany({
|
||||
where: {
|
||||
artistId,
|
||||
genreId,
|
||||
},
|
||||
take,
|
||||
skip,
|
||||
@@ -33,7 +35,10 @@ export class SearchService {
|
||||
await this.search.index("songs").search(query, {
|
||||
limit: take,
|
||||
offset: skip,
|
||||
...(artistId ? { filter: `artistId = ${artistId}` } : {}),
|
||||
filter: [
|
||||
...(artistId ? [`artistId = ${artistId}`] : []),
|
||||
...(genreId ? [`genreId = ${genreId}`] : []),
|
||||
].join(' AND '),
|
||||
})
|
||||
).hits.map((x) => x.id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user