feat: Add Swagger API documentation to AuthController and ClassController

This commit is contained in:
M1000fr 2024-12-10 14:33:43 +01:00
parent 161b01d8cb
commit 006fe8cb74
3 changed files with 18 additions and 1 deletions

View File

@ -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 {

View File

@ -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];

View File

@ -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<UserEntity[]> {
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<UserEntity> {
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;