From 006fe8cb74c8b7d68c2231e69bf33cfbc6aaa837 Mon Sep 17 00:00:00 2001 From: M1000fr Date: Tue, 10 Dec 2024 14:33:43 +0100 Subject: [PATCH] feat: Add Swagger API documentation to AuthController and ClassController --- src/modules/auth/auth.controller.ts | 5 ++++- src/modules/class/class.controller.ts | 7 +++++++ src/modules/user/user.controller.ts | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/modules/auth/auth.controller.ts b/src/modules/auth/auth.controller.ts index 975ff7c..aa046bc 100644 --- a/src/modules/auth/auth.controller.ts +++ b/src/modules/auth/auth.controller.ts @@ -1,5 +1,5 @@ import { Controller, Get, Req, Res, UseGuards } from "@nestjs/common"; -import { ApiBearerAuth, ApiOkResponse } from "@nestjs/swagger"; +import { ApiBearerAuth, ApiOkResponse, ApiOperation } from "@nestjs/swagger"; import { ConfigService } from "@nestjs/config"; import { AuthService } from "./auth.service"; @@ -14,6 +14,7 @@ export class AuthController { ) {} @Get("login") + @ApiOperation({ summary: "Redirect to login page" }) @ApiOkResponse({ description: "Redirect to login page", example: { @@ -42,6 +43,7 @@ export class AuthController { @Get("callback") @UseGuards(Oauth2AuthGuard) + @ApiOperation({ summary: "Return JWT token" }) @ApiOkResponse({ description: "Return JWT token", example: { @@ -57,6 +59,7 @@ export class AuthController { @Get("refresh") @UseGuards(RefreshJwtAuthGuard) + @ApiOperation({ summary: "Refresh JWT token" }) @ApiBearerAuth() refresh(@Req() req) { return { diff --git a/src/modules/class/class.controller.ts b/src/modules/class/class.controller.ts index 2985c80..1b01ec4 100644 --- a/src/modules/class/class.controller.ts +++ b/src/modules/class/class.controller.ts @@ -26,6 +26,7 @@ import { RolesGuard } from "@/modules/auth/guards/role.guard"; import { ApiBearerAuth, ApiOkResponse, + ApiOperation, ApiQuery, ApiUnauthorizedResponse, } from "@nestjs/swagger"; @@ -42,6 +43,7 @@ export class ClassController { @Post() @ApiOkResponse(ClassResponse) + @ApiOperation({ summary: "Create a new class" }) async create(@Body() createClassDto: CreateClassDto) { return await this.classService.create(createClassDto).then((class_) => { return new ClassEntity(class_); @@ -50,6 +52,7 @@ export class ClassController { @Get() @ApiOkResponse(ClassesResponse) + @ApiOperation({ summary: "Get all classes" }) async findAll() { return await this.classService .findAll({}) @@ -60,6 +63,7 @@ export class ClassController { @Get(":id") @ApiOkResponse(ClassResponse) + @ApiOperation({ summary: "Get a class by id" }) async findOne(@Param("id") id: string) { return await this.classService .findOne(id) @@ -68,6 +72,7 @@ export class ClassController { @Patch(":id") @ApiOkResponse(ClassResponse) + @ApiOperation({ summary: "Update a class by id" }) async update( @Param("id") id: string, @Body() updateClassDto: UpdateClassDto, @@ -79,6 +84,7 @@ export class ClassController { @Delete(":id") @ApiOkResponse(ClassResponse) + @ApiOperation({ summary: "Remove a class by id" }) async remove(@Param("id") id: string) { return await this.classService .remove(id) @@ -87,6 +93,7 @@ export class ClassController { @Delete() @ApiOkResponse(ClassCountResponse) + @ApiOperation({ summary: "Remove multiple classes by ids" }) @ApiQuery({ name: "ids", required: true, type: [String] }) async bulkRemove(@Query("ids") ids: string | string[]) { if (typeof ids === "string") ids = [ids]; diff --git a/src/modules/user/user.controller.ts b/src/modules/user/user.controller.ts index ca8efb0..78f98e0 100644 --- a/src/modules/user/user.controller.ts +++ b/src/modules/user/user.controller.ts @@ -15,6 +15,7 @@ import { import { ApiBearerAuth, ApiOkResponse, + ApiOperation, ApiParam, ApiQuery, ApiUnauthorizedResponse @@ -39,6 +40,7 @@ export class UserController { @Get() @ApiOkResponse(UsersResponse) + @ApiOperation({ summary: "Get all users" }) async findAll(): Promise { return await this.userService .findAll() @@ -47,6 +49,7 @@ export class UserController { @Get(":id") @ApiOkResponse(UserResponse) + @ApiOperation({ summary: "Get user by id" }) async findOne(@Param("id") id: string): Promise { return this.userService .findOne(id) @@ -54,6 +57,8 @@ export class UserController { } @Patch(":id") + @ApiOkResponse(UserResponse) + @ApiOperation({ summary: "Update user by id" }) async update( @Param("id") id: string, @Body() updateUserDto: UpdateUserDTO, @@ -65,6 +70,7 @@ export class UserController { @Delete(":id") @ApiOkResponse(UserResponse) + @ApiOperation({ summary: "Delete user by id" }) @ApiParam({ name: "id", type: String, @@ -77,6 +83,7 @@ export class UserController { @Delete() @ApiOkResponse(UserCountResponse) + @ApiOperation({ summary: "Delete users by ids" }) @ApiQuery({ name: "ids", required: true, type: [String] }) bulkRemove(@Query("ids") ids: string | string[]): Promise<{ count: number;