From 29ef585410eb8079d66e37851f83b414165e0eac Mon Sep 17 00:00:00 2001 From: GitBluub Date: Wed, 20 Sep 2023 03:41:34 +0200 Subject: [PATCH] doc: genre, lesson and history controller --- back/src/genre/genre.controller.ts | 4 +++- back/src/history/history.controller.ts | 15 ++++++++++----- back/src/lesson/lesson.controller.ts | 4 +++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/back/src/genre/genre.controller.ts b/back/src/genre/genre.controller.ts index b6f4dc8..0ebf2af 100644 --- a/back/src/genre/genre.controller.ts +++ b/back/src/genre/genre.controller.ts @@ -14,7 +14,7 @@ import { Req, StreamableFile, } from '@nestjs/common'; -import { Plage } from 'src/models/plage'; +import { ApiOkResponsePlaginated, Plage } from 'src/models/plage'; import { CreateGenreDto } from './dto/create-genre.dto'; import { Request } from 'express'; import { GenreService } from './genre.service'; @@ -22,6 +22,7 @@ import { Prisma, Genre } from '@prisma/client'; import { ApiTags } from '@nestjs/swagger'; import { createReadStream, existsSync } from 'fs'; import { FilterQuery } from 'src/utils/filter.pipe'; +import { Genre as _Genre } from 'src/_gen/prisma-class/genre'; @Controller('genre') @ApiTags('genre') @@ -65,6 +66,7 @@ export class GenreController { } @Get() + @ApiOkResponsePlaginated(_Genre) async findAll( @Req() req: Request, @FilterQuery(GenreController.filterableFields) diff --git a/back/src/history/history.controller.ts b/back/src/history/history.controller.ts index 53d809f..74f6809 100644 --- a/back/src/history/history.controller.ts +++ b/back/src/history/history.controller.ts @@ -10,12 +10,14 @@ import { Request, UseGuards, } from '@nestjs/common'; -import { ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger'; +import { ApiCreatedResponse, ApiOkResponse, ApiOperation, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger'; import { SearchHistory, SongHistory } from '@prisma/client'; import { JwtAuthGuard } from 'src/auth/jwt-auth.guard'; import { SongHistoryDto } from './dto/SongHistoryDto'; import { HistoryService } from './history.service'; import { SearchHistoryDto } from './dto/SearchHistoryDto'; +import { SongHistory as _SongHistory } from 'src/_gen/prisma-class/song_history'; +import { SearchHistory as _SearchHistory} from 'src/_gen/prisma-class/search_history'; @Controller('history') @ApiTags('history') @@ -23,8 +25,9 @@ export class HistoryController { constructor(private readonly historyService: HistoryService) { } @Get() - @HttpCode(200) + @ApiOperation({ description: "Get song history of connected user"}) @UseGuards(JwtAuthGuard) + @ApiOkResponse({ type: _SongHistory, isArray: true}) @ApiUnauthorizedResponse({ description: 'Invalid token' }) async getHistory( @Request() req: any, @@ -35,8 +38,9 @@ export class HistoryController { } @Get('search') - @HttpCode(200) + @ApiOperation({ description: "Get search history of connected user"}) @UseGuards(JwtAuthGuard) + @ApiOkResponse({ type: _SearchHistory, isArray: true}) @ApiUnauthorizedResponse({ description: 'Invalid token' }) async getSearchHistory( @Request() req: any, @@ -47,13 +51,14 @@ export class HistoryController { } @Post() - @HttpCode(201) + @ApiOperation({ description: "Create a record of a song played by a user"}) + @ApiCreatedResponse({ description: "Succesfully created a record"}) async create(@Body() record: SongHistoryDto): Promise { return this.historyService.createSongHistoryRecord(record); } @Post("search") - @HttpCode(201) + @ApiOperation({ description: "Creates a search record in the users history"}) @UseGuards(JwtAuthGuard) @ApiUnauthorizedResponse({description: "Invalid token"}) async createSearchHistory( diff --git a/back/src/lesson/lesson.controller.ts b/back/src/lesson/lesson.controller.ts index 0e66abc..2f8531b 100644 --- a/back/src/lesson/lesson.controller.ts +++ b/back/src/lesson/lesson.controller.ts @@ -13,11 +13,12 @@ import { Delete, NotFoundException, } from '@nestjs/common'; -import { Plage } from 'src/models/plage'; +import { ApiOkResponsePlaginated, Plage } from 'src/models/plage'; import { LessonService } from './lesson.service'; import { ApiOperation, ApiProperty, ApiTags } from '@nestjs/swagger'; import { Prisma, Skill } from '@prisma/client'; import { FilterQuery } from 'src/utils/filter.pipe'; +import { Lesson as _Lesson} from 'src/_gen/prisma-class/lesson'; export class Lesson { @ApiProperty() @@ -48,6 +49,7 @@ export class LessonController { summary: 'Get all lessons', }) @Get() + @ApiOkResponsePlaginated(_Lesson) async getAll( @Req() request: Request, @FilterQuery(LessonController.filterableFields)