import { multerImageOptions } from '@/multer.config' import { Body, Controller, Get, Param, Patch, Post, UploadedFile, UseInterceptors, } from '@nestjs/common' import { FileInterceptor } from '@nestjs/platform-express' import { ApiBody, ApiConsumes } from '@nestjs/swagger' import { CreateGuildGoodDto, UpdateGuildGoodDto } from './dto/create-good.dto' import { GoodsService } from './goods.service' @Controller('admin/guilds/:guildId/goods') export class GoodsController { constructor(private readonly goodsService: GoodsService) {} @Get() findAll(@Param('guildId') guildId: string) { return this.goodsService.findAll(guildId) } @Get(':id') findOne(@Param('guildId') guildId: string, @Param('id') goodId: string) { return this.goodsService.findOne(guildId, goodId) } @Post() @UseInterceptors(FileInterceptor('image', multerImageOptions)) @ApiConsumes('multipart/form-data') @ApiBody({ schema: { type: 'object', properties: { image: { type: 'string', format: 'binary' }, }, }, }) create( @Param('guildId') guildId: string, @Body() data: CreateGuildGoodDto, @UploadedFile() file: Express.Multer.File, ) { return this.goodsService.create(guildId, data, file) } @Patch(':id') @UseInterceptors(FileInterceptor('image', multerImageOptions)) @ApiConsumes('multipart/form-data') @ApiBody({ schema: { type: 'object', properties: { image: { type: 'string', format: 'binary' }, }, }, }) update( @Param('guildId') guildId: string, @Param('id') id: string, @Body() data: UpdateGuildGoodDto, @UploadedFile() file: Express.Multer.File, ) { return this.goodsService.update(guildId, id, data, file) } }