import { Controller, Get, Post, Body, Patch, Param, Delete, HttpCode, UseGuards, Query, NotFoundException, ParseIntPipe, Req } from '@nestjs/common' import { MoneyUpdatesService } from './money-updates.service' import { CreateMoneyUpdateDto } from './dto/create-money-update.dto' import { UpdateMoneyUpdateDto } from './dto/update-money-update.dto' import { AuthenticatedRequest, JwtAuthGuard } from 'src/auth/jwt-auth.guard' import { ApiBearerAuth, ApiCreatedResponse, ApiNotFoundResponse, ApiOkResponse, ApiUnauthorizedResponse } from '@nestjs/swagger' import { MoneyUpdateEntity } from './entities/money-update.entity' import { ApiOkResponsePaginated, paginateOutput } from 'src/common/utils/pagination.utils' import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto' import { PlayerFilterDto } from 'src/common/dto/player_filter.dto' import { PaginateOutputDto } from 'src/common/dto/pagination-output.dto' @Controller('money-updates') export class MoneyUpdatesController { constructor(private readonly moneyUpdatesService: MoneyUpdatesService) {} @Post() @HttpCode(201) @UseGuards(JwtAuthGuard) @ApiBearerAuth() @ApiCreatedResponse({ type: MoneyUpdateEntity, description: "Objet créé avec succès" }) @ApiUnauthorizedResponse({ description: "Non authentifié⋅e" }) async create(@Req() request: AuthenticatedRequest, @Body() createMoneyUpdateDto: CreateMoneyUpdateDto): Promise { const moneyUpdate = await this.moneyUpdatesService.create(request.user, createMoneyUpdateDto) return new MoneyUpdateEntity(moneyUpdate) } @Get() @UseGuards(JwtAuthGuard) @ApiBearerAuth() @ApiOkResponsePaginated(MoneyUpdateEntity) @ApiUnauthorizedResponse({ description: "Non authentifié⋅e" }) async findAll(@Query() queryPagination: QueryPaginationDto, @Query() playerFilter: PlayerFilterDto): Promise> { const [trains, total] = await this.moneyUpdatesService.findAll(queryPagination, playerFilter) return paginateOutput(trains.map(train => new MoneyUpdateEntity(train)), total, queryPagination) } @Get(':id') @UseGuards(JwtAuthGuard) @ApiBearerAuth() @ApiOkResponse({ type: MoneyUpdateEntity }) @ApiUnauthorizedResponse({ description: "Non authentifié⋅e" }) @ApiNotFoundResponse({ description: "Objet non trouvé" }) async findOne(@Param('id', ParseIntPipe) id: number): Promise { const train = await this.moneyUpdatesService.findOne(id) if (!train) throw new NotFoundException(`Trajet en train inexistant avec l'identifiant ${id}`) return new MoneyUpdateEntity(train) } @Patch(':id') @UseGuards(JwtAuthGuard) @ApiBearerAuth() @ApiOkResponse({ type: MoneyUpdateEntity }) @ApiUnauthorizedResponse({ description: "Non authentifié⋅e" }) @ApiNotFoundResponse({ description: "Objet non trouvé" }) async update(@Param('id', ParseIntPipe) id: number, @Body() updateMoneyUpdateDto: UpdateMoneyUpdateDto) { return await this.moneyUpdatesService.update(id, updateMoneyUpdateDto) } @Delete(':id') @HttpCode(204) @UseGuards(JwtAuthGuard) @ApiBearerAuth() @ApiOkResponse({ type: MoneyUpdateEntity }) @ApiUnauthorizedResponse({ description: "Non authentifié⋅e" }) @ApiNotFoundResponse({ description: "Objet non trouvé" }) async remove(@Param('id', ParseIntPipe) id: number) { await this.moneyUpdatesService.remove(id) } }