added product controller

This commit is contained in:
hannathkadher
2024-11-20 09:11:11 +04:00
parent a1f74938fc
commit 891129e7e3
6 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1 @@
export * from './product.controller';

View File

@ -0,0 +1,27 @@
import { Controller, Get, UseGuards } from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
import { ControllerRoute } from '@app/common/constants/controller-route';
import { ProductService } from '../services';
@ApiTags('Product Module')
@Controller({
version: EnableDisableStatusEnum.ENABLED,
path: ControllerRoute.PRODUCT.ROUTE,
})
export class ProductController {
constructor(private readonly productService: ProductService) {}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get()
@ApiOperation({
summary: ControllerRoute.PRODUCT.ACTIONS.LIST_PRODUCT_SUMMARY,
description: ControllerRoute.PRODUCT.ACTIONS.LIST_PRODUCT_DESCRIPTION,
})
async getProducts(): Promise<BaseResponseDto> {
return await this.productService.list();
}
}

1
src/product/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './product.module';

View File

@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { ProductService } from './services';
import { ProductRepository } from '@app/common/modules/product/repositories';
import { ProductController } from './controllers';
@Module({
controllers: [ProductController],
providers: [ProductService, ProductRepository],
})
export class ProductModule {}

View File

@ -0,0 +1 @@
export * from './product.service';

View File

@ -0,0 +1,24 @@
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
import { ProductRepository } from '@app/common/modules/product/repositories';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
@Injectable()
export class ProductService {
constructor(private readonly productRepository: ProductRepository) {}
async list(): Promise<BaseResponseDto> {
const products = await this.productRepository.find();
if (!products) {
throw new HttpException(
`No products found in the system`,
HttpStatus.NOT_FOUND,
);
}
return new SuccessResponseDto({
data: products,
message: 'List of products retrieved successfully',
});
}
}