import { Body, Controller, Delete, Get, HttpCode, Param, ParseIntPipe, Patch, Post, Put, Query, } from '@nestjs/common'; import { CreateProductDto } from './dto/create-product.dto'; import { UpdateProductDto } from './dto/update-product.dto'; import { ProductsService } from './products.service'; import { MergeProductsDto } from './dto/merge-products.dto'; import { UpdateCanonicalNameDto } from './dto/update-canonical-name.dto'; import { SetTagsDto } from './dto/set-tags.dto'; import { UpsertNutritionDto } from './dto/upsert-nutrition.dto'; @Controller('products') export class ProductsController { constructor(private readonly productsService: ProductsService) {} @Get() findAll( @Query('tag') tag?: string, @Query('subcategory') subcategory?: string, ) { return this.productsService.findAll({ tag, subcategory }); } @Get('tags') findAllTags() { return this.productsService.findAllTags(); } @Get('duplicates') findDuplicates() { return this.productsService.findDuplicateCandidates(); } @Get('merge-preview') previewMerge( @Query('sourceProductId', ParseIntPipe) sourceProductId: number, @Query('targetProductId', ParseIntPipe) targetProductId: number, ) { return this.productsService.previewMerge(sourceProductId, targetProductId); } @Post('backfill-canonical') backfillCanonical() { return this.productsService.backfillCanonicalNames(); } @Get(':id') findOne(@Param('id', ParseIntPipe) id: number) { return this.productsService.findOne(id); } @Post() create(@Body() body: CreateProductDto) { return this.productsService.create(body); } @Post('merge') merge(@Body() body: MergeProductsDto) { return this.productsService.merge(body.sourceProductId, body.targetProductId); } @Patch(':id/canonical-name') updateCanonicalName( @Param('id', ParseIntPipe) id: number, @Body() body: UpdateCanonicalNameDto, ) { return this.productsService.updateCanonicalName(id, body.canonicalName); } @Put(':id/tags') setTags( @Param('id', ParseIntPipe) id: number, @Body() body: SetTagsDto, ) { return this.productsService.setTags(id, body.tags); } @Put(':id/nutrition') upsertNutrition( @Param('id', ParseIntPipe) id: number, @Body() body: UpsertNutritionDto, ) { return this.productsService.upsertNutrition(id, body); } @Patch(':id') update( @Param('id', ParseIntPipe) id: number, @Body() body: UpdateProductDto, ) { return this.productsService.update(id, body); } @Delete(':id') remove(@Param('id', ParseIntPipe) id: number) { return this.productsService.remove(id); } @Post(':id/restore') restore(@Param('id', ParseIntPipe) id: number) { return this.productsService.restore(id); } @Delete('reset-all') @HttpCode(200) resetAll() { return this.productsService.resetAll(); } }