import { Body, Controller, Delete, Get, Param, Patch, Post, Query, } from '@nestjs/common'; import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; import { RequirePermission } from '../auth/decorators/require-permission.decorator'; import { CurrentUser } from '../auth/decorators/current-user.decorator'; import type { AuthenticatedUser } from '../auth/types/authenticated-user'; import { CreateBottlingBatchDto } from './dto/create-bottling-batch.dto'; import { UpdateBottlingBatchDto } from './dto/update-bottling-batch.dto'; import { BottlingService } from './bottling.service'; import { Idempotent } from '../common/idempotency/idempotent.decorator'; @ApiTags('bottling') @ApiBearerAuth() @Controller('bottling-batches') export class BottlingController { constructor(private readonly bottlingService: BottlingService) {} @RequirePermission('bottling:read') @Get() findAll(@Query('honeyBatchId') honeyBatchId?: string) { return this.bottlingService.findAll({ honeyBatchId }); } @RequirePermission('bottling:read') @Get(':id') findOne(@Param('id') id: string) { return this.bottlingService.findById(id); } @RequirePermission('bottling:create') @Idempotent() @Post() create( @Body() dto: CreateBottlingBatchDto, @CurrentUser() actor: AuthenticatedUser, ) { return this.bottlingService.create(dto, actor.id); } @RequirePermission('bottling:update') @Patch(':id') update( @Param('id') id: string, @Body() dto: UpdateBottlingBatchDto, @CurrentUser() actor: AuthenticatedUser, ) { return this.bottlingService.update(id, dto, actor.id); } @RequirePermission('bottling:delete') @Delete(':id') remove(@Param('id') id: string, @CurrentUser() actor: AuthenticatedUser) { return this.bottlingService.remove(id, actor.id); } }