Allow search query to be empty

This commit is contained in:
2024-01-12 14:54:08 +01:00
committed by Clément Le Bihan
parent 358841abd5
commit ec17aa741f

View File

@@ -2,9 +2,6 @@ import {
Controller, Controller,
DefaultValuePipe, DefaultValuePipe,
Get, Get,
InternalServerErrorException,
NotFoundException,
Param,
ParseIntPipe, ParseIntPipe,
Query, Query,
Request, Request,
@@ -16,15 +13,13 @@ import {
ApiTags, ApiTags,
ApiUnauthorizedResponse, ApiUnauthorizedResponse,
} from "@nestjs/swagger"; } from "@nestjs/swagger";
import { Artist, Genre, Song } from "@prisma/client"; import { Artist, Song } from "@prisma/client";
import { JwtAuthGuard } from "src/auth/jwt-auth.guard"; import { JwtAuthGuard } from "src/auth/jwt-auth.guard";
import { SearchService } from "./search.service"; import { SearchService } from "./search.service";
import { Song as _Song } from "src/_gen/prisma-class/song"; import { Song as _Song } from "src/_gen/prisma-class/song";
import { Genre as _Genre } from "src/_gen/prisma-class/genre";
import { Artist as _Artist } from "src/_gen/prisma-class/artist"; import { Artist as _Artist } from "src/_gen/prisma-class/artist";
import { mapInclude } from "src/utils/include"; import { mapInclude } from "src/utils/include";
import { SongController } from "src/song/song.controller"; import { SongController } from "src/song/song.controller";
import { GenreController } from "src/genre/genre.controller";
import { ArtistController } from "src/artist/artist.controller"; import { ArtistController } from "src/artist/artist.controller";
@ApiTags("search") @ApiTags("search")
@@ -39,15 +34,15 @@ export class SearchController {
@ApiUnauthorizedResponse({ description: "Invalid token" }) @ApiUnauthorizedResponse({ description: "Invalid token" })
async searchSong( async searchSong(
@Request() req: any, @Request() req: any,
@Param("query") query: string, @Query("q") query: string | null,
@Query("artistId") artistId: number, @Query("artistId") artistId: number,
@Query("genreId") genreId: number, @Query("genreId") genreId: number,
@Query("include") include: string, @Query("include") include: string,
@Query("skip", new DefaultValuePipe(0), ParseIntPipe) skip: number, @Query("skip", new DefaultValuePipe(0), ParseIntPipe) skip: number,
@Query("take", new DefaultValuePipe(20), ParseIntPipe) take: number, @Query("take", new DefaultValuePipe(20), ParseIntPipe) take: number,
): Promise<Song[] | null> { ): Promise<Song[]> {
return await this.searchService.searchSong( return await this.searchService.searchSong(
query, query ?? "",
artistId, artistId,
genreId, genreId,
mapInclude(include, req, SongController.includableFields), mapInclude(include, req, SongController.includableFields),
@@ -64,12 +59,12 @@ export class SearchController {
async searchArtists( async searchArtists(
@Request() req: any, @Request() req: any,
@Query("include") include: string, @Query("include") include: string,
@Param("query") query: string, @Query("q") query: string | null,
@Query("skip", new DefaultValuePipe(0), ParseIntPipe) skip: number, @Query("skip", new DefaultValuePipe(0), ParseIntPipe) skip: number,
@Query("take", new DefaultValuePipe(20), ParseIntPipe) take: number, @Query("take", new DefaultValuePipe(20), ParseIntPipe) take: number,
): Promise<Artist[] | null> { ): Promise<Artist[]> {
return await this.searchService.searchArtists( return await this.searchService.searchArtists(
query, query ?? "",
mapInclude(include, req, ArtistController.includableFields), mapInclude(include, req, ArtistController.includableFields),
skip, skip,
take, take,