import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { Paginate, PaginateQuery } from 'nestjs-paginate';
import { Product } from 'src/entities/product.entity';
import { ProductsService } from './products.service';

@Controller('products')
export class ProductsController {
  constructor(private readonly productsService: ProductsService) {}

  @Get()
  async index(@Paginate() query: PaginateQuery) {
    return this.productsService.index(query);
  }

  @Get(':id')
  async show(@Param('id') id: Product['id']) {
    return this.productsService.show(id);
  }

  @Post('publish/:id')
  async publish(@Param('id') id: Product['id'], @Body() data: any) {
    return this.productsService.publish(id, data);
  }

  @Post('unlist/:id')
  async unlist(@Param('id') id: Product['id'], @Body() data: any) {
    return this.productsService.unlist(id, data);
  }
}
