From f8be2c24626375e9d8f45afc073c9626d09da0b1 Mon Sep 17 00:00:00 2001 From: GitBluub Date: Wed, 20 Sep 2023 03:41:15 +0200 Subject: [PATCH] doc: artist and album controller --- back/src/album/album.controller.ts | 11 +++++++++-- back/src/artist/artist.controller.ts | 13 +++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/back/src/album/album.controller.ts b/back/src/album/album.controller.ts index e1fe65e..3051381 100644 --- a/back/src/album/album.controller.ts +++ b/back/src/album/album.controller.ts @@ -13,13 +13,14 @@ import { Query, Req, } from '@nestjs/common'; -import { Plage } from 'src/models/plage'; +import { ApiOkResponsePlaginated, Plage } from 'src/models/plage'; import { CreateAlbumDto } from './dto/create-album.dto'; import { AlbumService } from './album.service'; import { Request } from 'express'; import { Prisma, Album } from '@prisma/client'; -import { ApiTags } from '@nestjs/swagger'; +import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger'; import { FilterQuery } from 'src/utils/filter.pipe'; +import { Album as _Album } from 'src/_gen/prisma-class/album'; @Controller('album') @ApiTags('album') @@ -29,6 +30,7 @@ export class AlbumController { constructor(private readonly albumService: AlbumService) {} @Post() + @ApiOperation({ description: "Register a new album, should not be used by frontend"}) async create(@Body() createAlbumDto: CreateAlbumDto) { try { return await this.albumService.createAlbum({ @@ -45,6 +47,7 @@ export class AlbumController { } @Delete(':id') + @ApiOperation({ description: "Delete an album by id"}) async remove(@Param('id', ParseIntPipe) id: number) { try { return await this.albumService.deleteAlbum({ id }); @@ -54,6 +57,8 @@ export class AlbumController { } @Get() + @ApiOkResponsePlaginated(_Album) + @ApiOperation({ description: "Get all albums paginated"}) async findAll( @Req() req: Request, @FilterQuery(AlbumController.filterableFields) @@ -70,6 +75,8 @@ export class AlbumController { } @Get(':id') + @ApiOperation({ description: "Get an album by id"}) + @ApiOkResponse({ type: _Album}) async findOne(@Param('id', ParseIntPipe) id: number) { const res = await this.albumService.album({ id }); diff --git a/back/src/artist/artist.controller.ts b/back/src/artist/artist.controller.ts index 7c947f4..9a3ff8a 100644 --- a/back/src/artist/artist.controller.ts +++ b/back/src/artist/artist.controller.ts @@ -15,14 +15,15 @@ import { Req, StreamableFile, } from '@nestjs/common'; -import { Plage } from 'src/models/plage'; +import { ApiOkResponsePlaginated, Plage } from 'src/models/plage'; import { CreateArtistDto } from './dto/create-artist.dto'; import { Request } from 'express'; import { ArtistService } from './artist.service'; import { Prisma, Artist } from '@prisma/client'; -import { ApiTags } from '@nestjs/swagger'; +import { ApiNotFoundResponse, ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger'; import { createReadStream, existsSync } from 'fs'; import { FilterQuery } from 'src/utils/filter.pipe'; +import { Artist as _Artist} from 'src/_gen/prisma-class/artist'; @Controller('artist') @ApiTags('artist') @@ -32,6 +33,7 @@ export class ArtistController { constructor(private readonly service: ArtistService) {} @Post() + @ApiOperation({ description: "Register a new artist, should not be used by frontend"}) async create(@Body() dto: CreateArtistDto) { try { return await this.service.create(dto); @@ -41,6 +43,7 @@ export class ArtistController { } @Delete(':id') + @ApiOperation({ description: "Delete an artist by id"}) async remove(@Param('id', ParseIntPipe) id: number) { try { return await this.service.delete({ id }); @@ -50,6 +53,8 @@ export class ArtistController { } @Get(':id/illustration') + @ApiOperation({ description: "Get an artist's illustration"}) + @ApiNotFoundResponse({ description: "Artist or illustration not found"}) async getIllustration(@Param('id', ParseIntPipe) id: number) { const artist = await this.service.get({ id }); if (!artist) throw new NotFoundException('Artist not found'); @@ -66,6 +71,8 @@ export class ArtistController { } @Get() + @ApiOperation({ description: "Get all artists paginated"}) + @ApiOkResponsePlaginated(_Artist) async findAll( @Req() req: Request, @FilterQuery(ArtistController.filterableFields) @@ -82,6 +89,8 @@ export class ArtistController { } @Get(':id') + @ApiOperation({ description: "Get an artist by id"}) + @ApiOkResponse({ type: _Artist}) async findOne(@Param('id', ParseIntPipe) id: number) { const res = await this.service.get({ id });