Skip to content

Commit

Permalink
Fixed Swagger GUI page
Browse files Browse the repository at this point in the history
  • Loading branch information
popov654 committed Mar 31, 2024
1 parent 311a4da commit bd57951
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/article/article.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Body, Controller, Delete, Get, Param, Post, Put, Query } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { User } from '../user/user.decorator';
import { IArticleRO, IArticlesRO, ICommentsRO } from './article.interface';
import { ArticleService } from './article.service';
Expand Down Expand Up @@ -38,6 +38,7 @@ export class ArticleController {
}

@ApiOperation({ summary: 'Create article' })
@ApiBody({ type: CreateArticleDto })
@ApiResponse({ status: 201, description: 'The article has been successfully created.' })
@ApiResponse({ status: 403, description: 'Forbidden.' })
@Post()
Expand All @@ -46,6 +47,7 @@ export class ArticleController {
}

@ApiOperation({ summary: 'Update article' })
@ApiBody({ type: CreateArticleDto })
@ApiResponse({ status: 201, description: 'The article has been successfully updated.' })
@ApiResponse({ status: 403, description: 'Forbidden.' })
@Put(':slug')
Expand All @@ -63,6 +65,7 @@ export class ArticleController {
}

@ApiOperation({ summary: 'Create comment' })
@ApiBody({ type: CreateCommentDto })
@ApiResponse({ status: 201, description: 'The comment has been successfully created.' })
@ApiResponse({ status: 403, description: 'Forbidden.' })
@Post(':slug/comments')
Expand Down
6 changes: 6 additions & 0 deletions src/article/dto/create-article.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { ApiProperty } from "@nestjs/swagger";

export class CreateArticleDto {
@ApiProperty()
readonly title!: string;
@ApiProperty()
readonly description!: string;
@ApiProperty()
readonly body!: string;
@ApiProperty()
readonly tagList!: string[];
}
3 changes: 3 additions & 0 deletions src/article/dto/create-comment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { ApiProperty } from "@nestjs/swagger";

export class CreateCommentDto {
@ApiProperty()
readonly body!: string;
}
4 changes: 4 additions & 0 deletions src/user/dto/create-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty } from 'class-validator';

export class CreateUserDto {

@IsNotEmpty()
@ApiProperty()
readonly username!: string;

@IsNotEmpty()
@ApiProperty()
readonly email!: string;

@IsNotEmpty()
@ApiProperty()
readonly password!: string;
}
3 changes: 3 additions & 0 deletions src/user/dto/login-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty } from 'class-validator';

export class LoginUserDto {

@IsNotEmpty()
@ApiProperty()
readonly email!: string;

@IsNotEmpty()
@ApiProperty()
readonly password!: string;
}
6 changes: 6 additions & 0 deletions src/user/dto/update-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { ApiProperty } from "@nestjs/swagger";

export class UpdateUserDto {
@ApiProperty()
readonly bio!: string;
@ApiProperty()
readonly email!: string;
@ApiProperty()
readonly image!: string;
@ApiProperty()
readonly username!: string;
}
5 changes: 4 additions & 1 deletion src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { UserService } from './user.service';

import {
ApiBearerAuth,
ApiBody,
ApiTags,
} from '@nestjs/swagger';

Expand All @@ -28,6 +29,7 @@ export class UserController {
}

@UsePipes(new ValidationPipe())
@ApiBody({ type: CreateUserDto })
@Post('users')
async create(@Body('user') userData: CreateUserDto) {
return this.userService.create(userData);
Expand All @@ -39,8 +41,9 @@ export class UserController {
}

@UsePipes(new ValidationPipe())
@ApiBody({ type: LoginUserDto })
@Post('users/login')
async login(@Body('user') loginUserDto: LoginUserDto): Promise<IUserRO> {
async login(@Body() loginUserDto: LoginUserDto): Promise<IUserRO> {
const foundUser = await this.userService.findOne(loginUserDto);

const errors = { User: ' not found' };
Expand Down

0 comments on commit bd57951

Please sign in to comment.