feat: Add Swagger API documentation to AuthController and ClassController
This commit is contained in:
parent
161b01d8cb
commit
006fe8cb74
@ -1,5 +1,5 @@
|
|||||||
import { Controller, Get, Req, Res, UseGuards } from "@nestjs/common";
|
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 { ConfigService } from "@nestjs/config";
|
||||||
import { AuthService } from "./auth.service";
|
import { AuthService } from "./auth.service";
|
||||||
@ -14,6 +14,7 @@ export class AuthController {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Get("login")
|
@Get("login")
|
||||||
|
@ApiOperation({ summary: "Redirect to login page" })
|
||||||
@ApiOkResponse({
|
@ApiOkResponse({
|
||||||
description: "Redirect to login page",
|
description: "Redirect to login page",
|
||||||
example: {
|
example: {
|
||||||
@ -42,6 +43,7 @@ export class AuthController {
|
|||||||
|
|
||||||
@Get("callback")
|
@Get("callback")
|
||||||
@UseGuards(Oauth2AuthGuard)
|
@UseGuards(Oauth2AuthGuard)
|
||||||
|
@ApiOperation({ summary: "Return JWT token" })
|
||||||
@ApiOkResponse({
|
@ApiOkResponse({
|
||||||
description: "Return JWT token",
|
description: "Return JWT token",
|
||||||
example: {
|
example: {
|
||||||
@ -57,6 +59,7 @@ export class AuthController {
|
|||||||
|
|
||||||
@Get("refresh")
|
@Get("refresh")
|
||||||
@UseGuards(RefreshJwtAuthGuard)
|
@UseGuards(RefreshJwtAuthGuard)
|
||||||
|
@ApiOperation({ summary: "Refresh JWT token" })
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
refresh(@Req() req) {
|
refresh(@Req() req) {
|
||||||
return {
|
return {
|
||||||
|
@ -26,6 +26,7 @@ import { RolesGuard } from "@/modules/auth/guards/role.guard";
|
|||||||
import {
|
import {
|
||||||
ApiBearerAuth,
|
ApiBearerAuth,
|
||||||
ApiOkResponse,
|
ApiOkResponse,
|
||||||
|
ApiOperation,
|
||||||
ApiQuery,
|
ApiQuery,
|
||||||
ApiUnauthorizedResponse,
|
ApiUnauthorizedResponse,
|
||||||
} from "@nestjs/swagger";
|
} from "@nestjs/swagger";
|
||||||
@ -42,6 +43,7 @@ export class ClassController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOkResponse(ClassResponse)
|
@ApiOkResponse(ClassResponse)
|
||||||
|
@ApiOperation({ summary: "Create a new class" })
|
||||||
async create(@Body() createClassDto: CreateClassDto) {
|
async create(@Body() createClassDto: CreateClassDto) {
|
||||||
return await this.classService.create(createClassDto).then((class_) => {
|
return await this.classService.create(createClassDto).then((class_) => {
|
||||||
return new ClassEntity(class_);
|
return new ClassEntity(class_);
|
||||||
@ -50,6 +52,7 @@ export class ClassController {
|
|||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ApiOkResponse(ClassesResponse)
|
@ApiOkResponse(ClassesResponse)
|
||||||
|
@ApiOperation({ summary: "Get all classes" })
|
||||||
async findAll() {
|
async findAll() {
|
||||||
return await this.classService
|
return await this.classService
|
||||||
.findAll({})
|
.findAll({})
|
||||||
@ -60,6 +63,7 @@ export class ClassController {
|
|||||||
|
|
||||||
@Get(":id")
|
@Get(":id")
|
||||||
@ApiOkResponse(ClassResponse)
|
@ApiOkResponse(ClassResponse)
|
||||||
|
@ApiOperation({ summary: "Get a class by id" })
|
||||||
async findOne(@Param("id") id: string) {
|
async findOne(@Param("id") id: string) {
|
||||||
return await this.classService
|
return await this.classService
|
||||||
.findOne(id)
|
.findOne(id)
|
||||||
@ -68,6 +72,7 @@ export class ClassController {
|
|||||||
|
|
||||||
@Patch(":id")
|
@Patch(":id")
|
||||||
@ApiOkResponse(ClassResponse)
|
@ApiOkResponse(ClassResponse)
|
||||||
|
@ApiOperation({ summary: "Update a class by id" })
|
||||||
async update(
|
async update(
|
||||||
@Param("id") id: string,
|
@Param("id") id: string,
|
||||||
@Body() updateClassDto: UpdateClassDto,
|
@Body() updateClassDto: UpdateClassDto,
|
||||||
@ -79,6 +84,7 @@ export class ClassController {
|
|||||||
|
|
||||||
@Delete(":id")
|
@Delete(":id")
|
||||||
@ApiOkResponse(ClassResponse)
|
@ApiOkResponse(ClassResponse)
|
||||||
|
@ApiOperation({ summary: "Remove a class by id" })
|
||||||
async remove(@Param("id") id: string) {
|
async remove(@Param("id") id: string) {
|
||||||
return await this.classService
|
return await this.classService
|
||||||
.remove(id)
|
.remove(id)
|
||||||
@ -87,6 +93,7 @@ export class ClassController {
|
|||||||
|
|
||||||
@Delete()
|
@Delete()
|
||||||
@ApiOkResponse(ClassCountResponse)
|
@ApiOkResponse(ClassCountResponse)
|
||||||
|
@ApiOperation({ summary: "Remove multiple classes by ids" })
|
||||||
@ApiQuery({ name: "ids", required: true, type: [String] })
|
@ApiQuery({ name: "ids", required: true, type: [String] })
|
||||||
async bulkRemove(@Query("ids") ids: string | string[]) {
|
async bulkRemove(@Query("ids") ids: string | string[]) {
|
||||||
if (typeof ids === "string") ids = [ids];
|
if (typeof ids === "string") ids = [ids];
|
||||||
|
@ -15,6 +15,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
ApiBearerAuth,
|
ApiBearerAuth,
|
||||||
ApiOkResponse,
|
ApiOkResponse,
|
||||||
|
ApiOperation,
|
||||||
ApiParam,
|
ApiParam,
|
||||||
ApiQuery,
|
ApiQuery,
|
||||||
ApiUnauthorizedResponse
|
ApiUnauthorizedResponse
|
||||||
@ -39,6 +40,7 @@ export class UserController {
|
|||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ApiOkResponse(UsersResponse)
|
@ApiOkResponse(UsersResponse)
|
||||||
|
@ApiOperation({ summary: "Get all users" })
|
||||||
async findAll(): Promise<UserEntity[]> {
|
async findAll(): Promise<UserEntity[]> {
|
||||||
return await this.userService
|
return await this.userService
|
||||||
.findAll()
|
.findAll()
|
||||||
@ -47,6 +49,7 @@ export class UserController {
|
|||||||
|
|
||||||
@Get(":id")
|
@Get(":id")
|
||||||
@ApiOkResponse(UserResponse)
|
@ApiOkResponse(UserResponse)
|
||||||
|
@ApiOperation({ summary: "Get user by id" })
|
||||||
async findOne(@Param("id") id: string): Promise<UserEntity> {
|
async findOne(@Param("id") id: string): Promise<UserEntity> {
|
||||||
return this.userService
|
return this.userService
|
||||||
.findOne(id)
|
.findOne(id)
|
||||||
@ -54,6 +57,8 @@ export class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Patch(":id")
|
@Patch(":id")
|
||||||
|
@ApiOkResponse(UserResponse)
|
||||||
|
@ApiOperation({ summary: "Update user by id" })
|
||||||
async update(
|
async update(
|
||||||
@Param("id") id: string,
|
@Param("id") id: string,
|
||||||
@Body() updateUserDto: UpdateUserDTO,
|
@Body() updateUserDto: UpdateUserDTO,
|
||||||
@ -65,6 +70,7 @@ export class UserController {
|
|||||||
|
|
||||||
@Delete(":id")
|
@Delete(":id")
|
||||||
@ApiOkResponse(UserResponse)
|
@ApiOkResponse(UserResponse)
|
||||||
|
@ApiOperation({ summary: "Delete user by id" })
|
||||||
@ApiParam({
|
@ApiParam({
|
||||||
name: "id",
|
name: "id",
|
||||||
type: String,
|
type: String,
|
||||||
@ -77,6 +83,7 @@ export class UserController {
|
|||||||
|
|
||||||
@Delete()
|
@Delete()
|
||||||
@ApiOkResponse(UserCountResponse)
|
@ApiOkResponse(UserCountResponse)
|
||||||
|
@ApiOperation({ summary: "Delete users by ids" })
|
||||||
@ApiQuery({ name: "ids", required: true, type: [String] })
|
@ApiQuery({ name: "ids", required: true, type: [String] })
|
||||||
bulkRemove(@Query("ids") ids: string | string[]): Promise<{
|
bulkRemove(@Query("ids") ids: string | string[]): Promise<{
|
||||||
count: number;
|
count: number;
|
||||||
|
Loading…
Reference in New Issue
Block a user