|
@@ -1,9 +1,22 @@
|
|
|
-import { Body, Controller, Post } from '@nestjs/common';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ Body,
|
|
|
|
|
+ Controller,
|
|
|
|
|
+ Delete,
|
|
|
|
|
+ Get,
|
|
|
|
|
+ Param,
|
|
|
|
|
+ Post,
|
|
|
|
|
+ Put,
|
|
|
|
|
+ Query,
|
|
|
|
|
+} from '@nestjs/common';
|
|
|
import { CreateProductRequest } from '@/pet-feeder/dto/create-product.request';
|
|
import { CreateProductRequest } from '@/pet-feeder/dto/create-product.request';
|
|
|
import { ProductService } from '@/pet-feeder/service/product.service';
|
|
import { ProductService } from '@/pet-feeder/service/product.service';
|
|
|
import { ProductVo } from '@/pet-feeder/vo/product.vo';
|
|
import { ProductVo } from '@/pet-feeder/vo/product.vo';
|
|
|
import { ProductMapper } from '@/pet-feeder/mapper/product.mapper';
|
|
import { ProductMapper } from '@/pet-feeder/mapper/product.mapper';
|
|
|
-import { ApiBearerAuth, ApiOkResponse } from '@nestjs/swagger';
|
|
|
|
|
|
|
+import { ApiBearerAuth, ApiOkResponse, getSchemaPath } from '@nestjs/swagger';
|
|
|
|
|
+import { UpdateProductRequest } from '@/pet-feeder/dto/update-product.request';
|
|
|
|
|
+import { PageResultMapper } from '@/core/mapper/page-result.mapper';
|
|
|
|
|
+import { SearchProductFilter } from '@/pet-feeder/dto/search-product.filter';
|
|
|
|
|
+import { PageResult } from '@/core/vo/page-result';
|
|
|
|
|
|
|
|
@Controller('products')
|
|
@Controller('products')
|
|
|
export class ProductController {
|
|
export class ProductController {
|
|
@@ -24,4 +37,56 @@ export class ProductController {
|
|
|
await this.productService.create(createProductRequest),
|
|
await this.productService.create(createProductRequest),
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Put(':id')
|
|
|
|
|
+ @ApiOkResponse({
|
|
|
|
|
+ type: ProductVo,
|
|
|
|
|
+ })
|
|
|
|
|
+ @ApiBearerAuth()
|
|
|
|
|
+ async update(
|
|
|
|
|
+ @Param('id') id: string,
|
|
|
|
|
+ @Body() updateProductRequest: UpdateProductRequest,
|
|
|
|
|
+ ): Promise<ProductVo> {
|
|
|
|
|
+ return this.productMapper.toVo(
|
|
|
|
|
+ await this.productService.update(id, updateProductRequest),
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ @Get(':id')
|
|
|
|
|
+ async get(@Param('id') id: string): Promise<ProductVo> {
|
|
|
|
|
+ return this.productMapper.toVo(await this.productService.get(id));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Get()
|
|
|
|
|
+ @ApiOkResponse({
|
|
|
|
|
+ description: '产品分页列表',
|
|
|
|
|
+ schema: {
|
|
|
|
|
+ allOf: [
|
|
|
|
|
+ { $ref: getSchemaPath(PageResult) }, // 引用 PageResult 模型
|
|
|
|
|
+ {
|
|
|
|
|
+ properties: {
|
|
|
|
|
+ data: {
|
|
|
|
|
+ type: 'array',
|
|
|
|
|
+ items: { $ref: getSchemaPath(ProductVo) }, // 泛型内容具体化
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ },
|
|
|
|
|
+ })
|
|
|
|
|
+ @ApiBearerAuth()
|
|
|
|
|
+ async search(@Query() searchProductFilter: SearchProductFilter) {
|
|
|
|
|
+ const [data, total] = await this.productService.search(searchProductFilter);
|
|
|
|
|
+ return PageResultMapper.toPageResult<ProductVo>(
|
|
|
|
|
+ this.productMapper.toVos(data),
|
|
|
|
|
+ searchProductFilter.getPage(),
|
|
|
|
|
+ searchProductFilter.getSize(),
|
|
|
|
|
+ total,
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Delete(':id')
|
|
|
|
|
+ @ApiBearerAuth()
|
|
|
|
|
+ async delete(@Param('id') id: string): Promise<void> {
|
|
|
|
|
+ await this.productService.delete(id);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|