Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding response bodies to the products controller docs #686

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/modules/products/dto/responses/create-product-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';
import { ProductDetailsDto } from './product-details.dto';

export class SuccessfulCreateResponseDto {
@ApiProperty({
description: 'The status of the request',
example: '200',
})
status: number;

@ApiProperty({
description: 'The message of the response',
example: 'Product created successfully',
})
@IsString()
message: string;

@ApiProperty({
description: 'The created product details',
})
data: ProductDetailsDto;
}
17 changes: 17 additions & 0 deletions src/modules/products/dto/responses/delete-product.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';

export class DeleteProductDto {
@ApiProperty({
description: 'The response message',
example: 'Product successfully deleted',
})
@IsString()
message: string;

@ApiProperty({
description: 'The response data',
})
@IsString()
data: {};
}
110 changes: 110 additions & 0 deletions src/modules/products/dto/responses/error-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';

export class BadRequestResponseDto {
@ApiProperty({
description: 'The status of the request',
example: 'Unprocessable entity exception',
})
@IsString()
status: string;

@ApiProperty({
description: 'The response code',
example: '422',
})
@IsString()
status_code: string;

@ApiProperty({
description: 'The message of the response',
example: 'Invalid organisation credentials',
})
@IsString()
message: string;
}

export class NotFoundResponseDto {
@ApiProperty({
description: 'The response code',
example: '404',
})
@IsString()
status_code: string;

@ApiProperty({
description: 'The message of the response',
example: 'Product not found',
})
@IsString()
message: string;
}

export class NoResultsResponseDto {
@ApiProperty({
description: 'The status of the request',
example: 'No Content',
})
@IsString()
status: string;

@ApiProperty({
description: 'The response code',
example: '204',
})
@IsString()
status_code: string;

@ApiProperty({
description: 'The message of the response',
example: 'No products found',
})
@IsString()
message: string;
}

export class ForbiddenErrorResponseDto {
@ApiProperty({
description: 'The status of the request',
example: 'fail',
})
@IsString()
status: string;

@ApiProperty({
description: 'The response code',
example: '403',
})
@IsString()
status_code: string;

@ApiProperty({
description: 'The message of the response',
example: 'Not allowed to perform this action',
})
@IsString()
message: string;
}

export class ServerErrorResponseDto {
@ApiProperty({
description: 'The status of the request',
example: 'Internal server error',
})
@IsString()
status: string;

@ApiProperty({
description: 'The response code',
example: '500',
})
@IsString()
status_code: string;

@ApiProperty({
description: 'The message of the response',
example: 'An unexpected error occurred. Please try again later.',
})
@IsString()
message: string;
}
17 changes: 17 additions & 0 deletions src/modules/products/dto/responses/get-products.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsBoolean } from 'class-validator';
import { ProductDetailsDto } from './product-details.dto';

export class ProductResponseDto {
@ApiProperty({
description: 'The message of the response',
example: 'Product retrieved successfully',
})
@IsString()
message: string;

@ApiProperty({
description: 'The product details',
})
data: ProductDetailsDto;
}
52 changes: 52 additions & 0 deletions src/modules/products/dto/responses/product-comment.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsBoolean } from 'class-validator';

class CommentDto {
@ApiProperty({
description: 'Comment id',
example: 'comment_1',
})
@IsString()
id: string;

@ApiProperty({
description: 'Product id',
example: 'product_1',
})
@IsString()
product_id: string;

@ApiProperty({
description: 'User id',
example: 'user_1',
})
@IsString()
user_id: string;

@ApiProperty({
description: 'Created comment',
example: '15',
})
@IsString()
comment: string;

@ApiProperty({
description: 'Date when the stock was last updated',
example: new Date(),
})
created_at: Date;
}

export class CommentResponseDto {
@ApiProperty({
description: 'The message of the response',
example: 'Comment added successfully',
})
@IsString()
message: string;

@ApiProperty({
description: 'The product details',
})
data: CommentDto;
}
63 changes: 63 additions & 0 deletions src/modules/products/dto/responses/product-details.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsBoolean } from 'class-validator';

export class ProductDetailsDto {
@ApiProperty({
description: 'Product id',
example: 'product_1',
})
@IsString()
id: string;

@ApiProperty({
description: 'Product name',
example: 'Product 1',
})
@IsString()
name: string;

@ApiProperty({
description: 'Product description',
example: 'Product description 1',
})
@IsString()
description: string;

@ApiProperty({
description: 'Product price',
example: '500',
})
price: number;

@ApiProperty({
description: 'Product status',
example: 'Product status',
})
@IsString()
status: string;

@ApiProperty({
description: 'Product deletion status',
example: 'false',
})
@IsBoolean()
is_deleted: boolean;

@ApiProperty({
description: 'Product quantity',
example: 'Product quantity',
})
quantity: number;

@ApiProperty({
description: 'Date when the product was created',
example: new Date(),
})
created_at: Date;

@ApiProperty({
description: 'Date when the product was last updated',
example: new Date(),
})
updated_at: Date;
}
23 changes: 23 additions & 0 deletions src/modules/products/dto/responses/search-products.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsBoolean } from 'class-validator';
import { ProductDetailsDto } from './product-details.dto';

export class SearchResponseDto {
@ApiProperty({
description: 'The status of the request',
example: 'true',
})
@IsBoolean()
success: boolean;

@ApiProperty({
description: 'The status of the request',
example: '200',
})
statusCode: number;

@ApiProperty({
description: 'The search results',
})
data: ProductDetailsDto[];
}
37 changes: 37 additions & 0 deletions src/modules/products/dto/responses/stock-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';

class StockDto {
@ApiProperty({
description: 'Product id',
example: 'product_1',
})
@IsString()
product_id: string;

@ApiProperty({
description: 'Product stock',
example: '15',
})
current_stock: number;

@ApiProperty({
description: 'Date when the stock was last updated',
example: new Date(),
})
last_updated: Date;
}

export class StockResponseDto {
@ApiProperty({
description: 'The response message',
example: 'Product stock retrieved successfully',
})
@IsString()
message: string;

@ApiProperty({
description: 'The response data',
})
data: StockDto;
}
Loading
Loading