create route + added to swagger
This commit is contained in:
@@ -12,9 +12,12 @@ import { ArtistService } from './artist/artist.service';
|
||||
import { GenreModule } from './genre/genre.module';
|
||||
import { ArtistModule } from './artist/artist.module';
|
||||
import { AlbumModule } from './album/album.module';
|
||||
import { SearchController } from './search/search.controller';
|
||||
import { SearchService } from './search/search.service';
|
||||
import { SearchModule } from './search/search.module';
|
||||
|
||||
@Module({
|
||||
imports: [UsersModule, PrismaModule, AuthModule, SongModule, LessonModule, GenreModule, ArtistModule, AlbumModule],
|
||||
imports: [UsersModule, PrismaModule, AuthModule, SongModule, LessonModule, GenreModule, ArtistModule, AlbumModule, SearchModule],
|
||||
controllers: [AppController],
|
||||
providers: [AppService, PrismaService, ArtistService],
|
||||
})
|
||||
|
||||
13
back/src/search/dto/search-song.dto.ts
Normal file
13
back/src/search/dto/search-song.dto.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
|
||||
|
||||
export class SearchSongDto {
|
||||
@ApiProperty()
|
||||
artist?: number;
|
||||
|
||||
@ApiProperty()
|
||||
album?: number;
|
||||
|
||||
@ApiProperty()
|
||||
genre?: number;
|
||||
}
|
||||
59
back/src/search/search.controller.ts
Normal file
59
back/src/search/search.controller.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { BadRequestException, Body, Controller, DefaultValuePipe, Get, NotFoundException, Param, ParseIntPipe, Query, Req } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { Prisma, Song } from '@prisma/client';
|
||||
import { Plage } from 'src/models/plage';
|
||||
import { SongService } from 'src/song/song.service';
|
||||
import { SearchSongDto } from './dto/search-song.dto';
|
||||
import { SearchService } from './search.service';
|
||||
import { Request } from 'express';
|
||||
|
||||
@ApiTags('search')
|
||||
@Controller('search')
|
||||
export class SearchController {
|
||||
constructor(private readonly searchService: SearchService, private readonly songService: SongService) {}
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return this.searchService.getHello();
|
||||
}
|
||||
|
||||
// @Get('/all')
|
||||
// findall(): Promise<Song[] | null> {
|
||||
// return this.songService.songs();
|
||||
// }
|
||||
|
||||
@Get()
|
||||
async findAll(
|
||||
@Req() req: Request,
|
||||
@Query() filter: Prisma.SongWhereInput,
|
||||
@Query('skip', new DefaultValuePipe(0), ParseIntPipe) skip: number,
|
||||
@Query('take', new DefaultValuePipe(20), ParseIntPipe) take: number,
|
||||
): Promise<Plage<Song>> {
|
||||
try {
|
||||
const ret = await this.songService.songs({
|
||||
skip,
|
||||
take,
|
||||
where: {
|
||||
...filter,
|
||||
id: filter.id ? +filter.id : undefined,
|
||||
},
|
||||
});
|
||||
return new Plage(ret, req);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
throw new BadRequestException(null, e?.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Get('/title/:name')
|
||||
async findByName(@Param('name') name: string): Promise<Song> {
|
||||
// const ret = await this.searchService.songByTitle({ name })
|
||||
// if (!ret) throw new NotFoundException();
|
||||
throw new NotFoundException();
|
||||
// return ret;
|
||||
}
|
||||
|
||||
@Get('/advanced')
|
||||
async findAdvanced(@Body() searchSongDto: SearchSongDto): Promise<Song[] | null> {
|
||||
throw new NotFoundException;
|
||||
}
|
||||
}
|
||||
13
back/src/search/search.module.ts
Normal file
13
back/src/search/search.module.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { SearchService } from './search.service';
|
||||
import { SearchController } from './search.controller';
|
||||
import { PrismaModule } from 'src/prisma/prisma.module';
|
||||
import { SongService } from 'src/song/song.service';
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [SearchController],
|
||||
providers: [SearchService, SongService],
|
||||
exports: [SearchService],
|
||||
})
|
||||
export class SearchModule {}
|
||||
31
back/src/search/search.service.ts
Normal file
31
back/src/search/search.service.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { DefaultValuePipe, Injectable, ParseIntPipe, Query, Req } from '@nestjs/common';
|
||||
import { Prisma, Song } from '@prisma/client';
|
||||
import { PrismaService } from 'src/prisma/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class SearchService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
// async songByTitle(songWhereUniqueInput: Prisma.SongWhereUniqueInput): Promise<Song | null> {
|
||||
// // return this.prisma.song.findUnique({
|
||||
// // where: songWhereUniqueInput,
|
||||
// // });
|
||||
// return this.prisma.song.findMany({
|
||||
// where:
|
||||
// })
|
||||
// }
|
||||
|
||||
// async all(): Promise<Song[] | null> {
|
||||
// return this.prisma.song.findMany
|
||||
// }
|
||||
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
|
||||
// async songAdvanced(
|
||||
// SongWhereInput: Prisma.SongWhereInput): Promise<Song[] | null> {
|
||||
// return this.prisma.song.findMany({
|
||||
// where: SongWhereInput,
|
||||
// });
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user