add crete/get cards

This commit is contained in:
2023-06-18 12:16:03 +02:00
parent 0794238f0d
commit ca976cfe5d
19 changed files with 358 additions and 7 deletions

View File

@@ -18,12 +18,16 @@ import { CommandBus } from '@nestjs/cqrs'
import {
CreateDeckCommand,
DeleteDeckByIdCommand,
GetAllCardsInDeckCommand,
GetAllDecksCommand,
GetDeckByIdCommand,
UpdateDeckCommand,
} from './use-cases'
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'
import { GetAllDecksDto } from './dto/get-all-decks.dto'
import { GetAllCardsInDeckDto } from '../cards/dto/get-all-cards.dto'
import { CreateCardCommand } from './use-cases/create-card-use-case'
import { CreateCardDto } from '../cards/dto/create-card.dto'
@Controller('decks')
export class DecksController {
@@ -48,6 +52,18 @@ export class DecksController {
return this.commandBus.execute(new GetDeckByIdCommand(id))
}
@UseGuards(JwtAuthGuard)
@Get(':id/cards')
findCardsInDeck(@Param('id') id: string, @Req() req, @Query() query: GetAllCardsInDeckDto) {
return this.commandBus.execute(new GetAllCardsInDeckCommand(req.user.id, id, query))
}
@UseGuards(JwtAuthGuard)
@Post(':id/cards')
createCardInDeck(@Param('id') id: string, @Req() req, @Body() card: CreateCardDto) {
return this.commandBus.execute(new CreateCardCommand(req.user.id, id, card))
}
@UseGuards(JwtAuthGuard)
@Patch(':id')
update(@Param('id') id: string, @Body() updateDeckDto: UpdateDeckDto, @Req() req) {