From 2008bf74db57d458f1cb9485b4fba372c622cc38 Mon Sep 17 00:00:00 2001 From: pjw5521 Date: Sat, 15 Jul 2023 18:33:20 +0900 Subject: [PATCH] feat: add a function to get the list of cards in the deck --- .../src/modules/card/CardRepository.ts | 6 ++++++ .../src/modules/deck/DeckController.ts | 5 +++++ .../service-backend/src/modules/deck/DeckModule.ts | 3 ++- .../service-backend/src/modules/deck/DeckService.ts | 11 +++++++++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/service-backend/src/modules/card/CardRepository.ts b/packages/service-backend/src/modules/card/CardRepository.ts index 186b2e4..ba32ecb 100644 --- a/packages/service-backend/src/modules/card/CardRepository.ts +++ b/packages/service-backend/src/modules/card/CardRepository.ts @@ -53,4 +53,10 @@ export class CardRepository { return updateCard; } + + async findAll(deckId: string){ + const cards = await this.cardModel.find({ deckId }).exec(); + + return cards; + } } diff --git a/packages/service-backend/src/modules/deck/DeckController.ts b/packages/service-backend/src/modules/deck/DeckController.ts index c6315cc..3767926 100644 --- a/packages/service-backend/src/modules/deck/DeckController.ts +++ b/packages/service-backend/src/modules/deck/DeckController.ts @@ -19,6 +19,11 @@ export class DeckController { return { result: result }; } + @Get(":id/cards") + async findCard(@Param('id') id: string): Promise { + return await this.deckService.findAll(id); + } + @Patch(':id') async updateDeck(@Param('id') id: string, @Body() updateDeckDto: UpdateDeckDto) { return await this.deckService.updateDeck(id, updateDeckDto); diff --git a/packages/service-backend/src/modules/deck/DeckModule.ts b/packages/service-backend/src/modules/deck/DeckModule.ts index 985bc9c..55c5b72 100644 --- a/packages/service-backend/src/modules/deck/DeckModule.ts +++ b/packages/service-backend/src/modules/deck/DeckModule.ts @@ -2,9 +2,10 @@ import { Module } from '@nestjs/common'; import { DeckService } from './DeckService'; import { DeckController } from './DeckController'; import { DeckRepository } from './DeckRepository'; +import { CardRepository } from '../card/CardRepository' @Module({ controllers: [DeckController], - providers: [DeckService, DeckRepository], + providers: [DeckService, DeckRepository, CardRepository], }) export class DeckModule {} diff --git a/packages/service-backend/src/modules/deck/DeckService.ts b/packages/service-backend/src/modules/deck/DeckService.ts index 5763a99..a06a48e 100644 --- a/packages/service-backend/src/modules/deck/DeckService.ts +++ b/packages/service-backend/src/modules/deck/DeckService.ts @@ -1,12 +1,15 @@ import { Injectable } from '@nestjs/common'; -import { CreateDeckDto } from './dto/CreateDeckDto'; import { UpdateDeckDto } from './dto/UpdateDeckDto'; import { DeckRepository } from './DeckRepository'; import { DeckCategory } from './DeckConstant'; +import { CardRepository } from '../card/CardRepository' @Injectable() export class DeckService { - constructor(private readonly deckRepository: DeckRepository) {} + constructor( + private readonly deckRepository: DeckRepository, + private readonly cardRepository: CardRepository + ) {} async create(name: string, userId: string, category: DeckCategory[]): Promise { return await this.deckRepository.create(name, userId, category); @@ -23,4 +26,8 @@ export class DeckService { async removeDeck(id: string) { return await this.deckRepository.remove(id); } + + async findAll(id: string){ + return await this.cardRepository.findAll(id); + } }