From 270a7cf6fa1c099e715458e953844bdf34935244 Mon Sep 17 00:00:00 2001 From: Jiwon Park <43839859+pjw5521@users.noreply.github.com> Date: Sun, 30 Jul 2023 05:21:03 +0900 Subject: [PATCH] feat: add client api of findDeckListByUserId api (#105) * feat: add client api of getDeckListByUserId api * refactor: update the return type of getDeckListByUserId api --- packages/api/src/index.ts | 12 ++++++++---- .../src/modules/deck/DeckController.ts | 2 +- .../service-backend/src/modules/deck/DeckService.ts | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index ed16d78..0eb887e 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -23,9 +23,10 @@ const card = JSON_APIS({ // Todo : change to session createCard: ({ createCardDto }: { createCardDto: CreateCardDto }) => client.public.post<{ result: boolean }>('cards', createCardDto), - // get card by id + /* get List of Cards in deck: Get card information by deck id */ // Todo : change to session - getCards: ({ id }: { id: string }) => client.public.get<{ result: Card[] | null }>(`decks/id=${id}/cards`), + getCards: ({ deckId }: { deckId: string }) => + client.public.get<{ result: Card[] | null }>(`decks/id=${deckId}/cards`), /* delete card by id */ // Todo : change to session deleteCard: ({ id }: { id: string }) => client.public.delete<{ result: boolean }>(`cards/id=${id}`), @@ -40,9 +41,12 @@ const deck = JSON_APIS({ client.public.post<{ deck_id: string }>('decks', createDeckDto), /* get Deck: Get card information by deck id */ // Todo : change to session - getDeck: ({ id }: { id: string }) => client.public.get<{ result: Deck | null }>(`decks/id=${id}`), - /* get List of Cards in deck: Get card information by deck id */ + getDeck: ({ deckId }: { deckId: string }) => client.public.get<{ result: Deck | null }>(`decks/id=${deckId}`), + /* Get all deck info */ getAllDeck: () => client.public.get<{ result: Deck[] }>(`decks`), + /* Get deck list of user id */ + getDeckListByUserId: ({ userId }: { userId: string }) => + client.session.get<{ result: Deck[] | null }>(`decks/user/${userId}`), }); export const api = { diff --git a/packages/service-backend/src/modules/deck/DeckController.ts b/packages/service-backend/src/modules/deck/DeckController.ts index ae14e0c..ea76fdc 100644 --- a/packages/service-backend/src/modules/deck/DeckController.ts +++ b/packages/service-backend/src/modules/deck/DeckController.ts @@ -71,7 +71,7 @@ export class DeckController { } @Get('/user/:userId') - async findByUserId(@Param('userId') userId: string): Promise<{ result: Deck[] | null }> { + async findByUserId(@Param('userId') userId: string): Promise<{ result: Deck[] | [] }> { const result = await this.deckService.findDeckListByUserId(userId); return { result: result }; } diff --git a/packages/service-backend/src/modules/deck/DeckService.ts b/packages/service-backend/src/modules/deck/DeckService.ts index b6f6441..1d3d780 100644 --- a/packages/service-backend/src/modules/deck/DeckService.ts +++ b/packages/service-backend/src/modules/deck/DeckService.ts @@ -23,7 +23,7 @@ export class DeckService { return await this.deckRepository.findAll(); } - async findDeckListByUserId(userId: string): Promise { + async findDeckListByUserId(userId: string): Promise { return await this.deckRepository.findByUserId(userId); }