#71 - swagger documentation completed

This commit is contained in:
danis
2023-01-19 11:06:46 +03:00
parent 470934a1cb
commit 1b5d966ddc
+31 -7
View File
@@ -1,5 +1,5 @@
import { BadRequestException, Body, Controller, DefaultValuePipe, Get, HttpCode, HttpStatus, NotFoundException, Param, ParseIntPipe, Post, Query, Req } from '@nestjs/common';
import { ApiParam, ApiTags } from '@nestjs/swagger';
import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
import { Prisma, Song } from '@prisma/client';
import { Plage } from 'src/models/plage';
import { SongService } from 'src/song/song.service';
@@ -13,14 +13,22 @@ import { type } from 'os';
export class SearchController {
constructor(private readonly searchService: SearchService, private readonly songService: SongService) {}
@Get('/title/:name')
@ApiOperation({
summary: 'Get a song details by song name',
description: 'Get a song details by song name',
})
@Get('song/:name')
async findByName(@Param('name') name: string): Promise<Song | null> {
const ret = await this.searchService.songByTitle({ name })
if (!ret) throw new NotFoundException;
return ret;
}
@Post('/advanced/song')
@ApiOperation({
summary: 'Get songs details by advanced filter',
description: 'Get songs details by advanced filter',
})
@Post('song/advanced')
@HttpCode(200) // change from '201 created' to '200 OK' http default response code
async findAdvanced(@Body() searchSongDto: SearchSongDto): Promise<Song[] | null> {
const ret = await this.searchService.findAdvanced({
@@ -32,27 +40,43 @@ export class SearchController {
else return ret;
}
@Get('/artist/:artistId')
@ApiOperation({
summary: 'Get songs details by artist',
description: 'Get songs details by artist',
})
@Get('song/artist/:artistId')
async findByArtist(@Param('artistId', ParseIntPipe) artistId: number): Promise<Song[] | null> {
const ret = await this.searchService.songsByArtist(artistId);
if (!ret) throw new NotFoundException;
if (!ret || !ret.length) throw new NotFoundException;
else return ret;
}
@Get('genre/:genreId')
@ApiOperation({
summary: 'Get songs details by genre',
description: 'Get songs details by genre',
})
@Get('song/genre/:genreId')
async findByGenre(@Param('genreId', ParseIntPipe) genreId: number): Promise<Song[] | null> {
const ret = await this.searchService.songsByGenre(genreId);
if (!ret) throw new NotFoundException;
else return ret;
}
@Get('album/:albumId')
@ApiOperation({
summary: 'Get songs details by album',
description: 'Get songs details by album',
})
@Get('song/album/:albumId')
async findByAlbum(@Param('albumId', ParseIntPipe) albumId: number): Promise<Song[] | null> {
const ret = await this.searchService.songsByAlbum(albumId);
if (!ret) throw new NotFoundException;
else return ret;
}
@ApiOperation({
summary: 'Guess elements details by keyword',
description: 'Guess elements details by keyword',
})
@Get('guess/:type/:word')
@ApiParam({name: 'word', type: 'string', required: true, example: 'Yoko Shimomura'})
@ApiParam({name: 'type', type: 'string', required: true, example: 'artist'})