mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-17 12:33:22 +00:00
add crete/get cards
This commit is contained in:
29
src/modules/cards/cards.controller.ts
Normal file
29
src/modules/cards/cards.controller.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Req, UseGuards } from '@nestjs/common'
|
||||
import { CardsService } from './cards.service'
|
||||
import { UpdateCardDto } from './dto/update-card.dto'
|
||||
import { CommandBus } from '@nestjs/cqrs'
|
||||
import { DeleteDeckByIdCommand, GetDeckByIdCommand, UpdateDeckCommand } from './use-cases'
|
||||
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'
|
||||
|
||||
@Controller('cards')
|
||||
export class CardsController {
|
||||
constructor(private readonly decksService: CardsService, private commandBus: CommandBus) {}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.commandBus.execute(new GetDeckByIdCommand(id))
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateDeckDto: UpdateCardDto, @Req() req) {
|
||||
return this.commandBus.execute(new UpdateDeckCommand(id, updateDeckDto, req.user.id))
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string, @Req() req) {
|
||||
return this.commandBus.execute(new DeleteDeckByIdCommand(id, req.user.id))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user