/
product.controller.ts
36 lines (33 loc) · 1.1 KB
/
product.controller.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { CreateProductUseCase } from '@app/application/ecommerce/use-case/create-product';
import { GetProductUseCase } from '@app/application/ecommerce/use-case/get-product';
import { CacheKey } from '@nestjs/cache-manager';
import {
Body,
Controller,
Get,
Post,
UseInterceptors
} from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { HttpCacheInterceptor } from '../persistence/cache/interceptor/http-cache.interceptor';
import { CreateProductDto } from './dto/create-product.dto';
@Controller('/product')
@ApiTags('Product')
export class ProductController {
constructor(
private createProductUseCase: CreateProductUseCase,
private getProductUseCase: GetProductUseCase,
) { }
@Get('')
@CacheKey('products')
@UseInterceptors(HttpCacheInterceptor)
async getAll() {
const response = this.getProductUseCase.execute({});
return response;
}
@Post('')
create(@Body() createProductDto: CreateProductDto) {
const response = this.createProductUseCase.execute(createProductDto);
return response;
}
}