Merge master into storybook-deploy

This commit is contained in:
github-actions[bot]
2023-10-09 11:24:25 +00:00
committed by GitHub
2 changed files with 41 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
export const baseApi = createApi({
reducerPath: 'baseApi',
tagTypes: ['Decks'],
baseQuery: fetchBaseQuery({
baseUrl: 'https://api.flashcards.andrii.es',
credentials: 'include',

View File

@@ -1,4 +1,11 @@
import { CardsResponse, DeckResponse, DecksResponse, GetDecksArgs } from './decks.types'
import {
CardsResponse,
CreateDeckArgs,
DeckResponse,
DecksResponse,
GetDecksArgs,
UpdateDeckArgs,
} from './decks.types'
import { baseApi } from '@/services'
@@ -11,6 +18,7 @@ const decksService = baseApi.injectEndpoints({
params: args ?? undefined,
}
},
providesTags: ['Decks'],
}),
getDeckById: builder.query<DeckResponse, { id: string }>({
query: ({ id }) => `v1/decks/${id}`,
@@ -18,7 +26,37 @@ const decksService = baseApi.injectEndpoints({
getDeckCards: builder.query<CardsResponse, { id: string }>({
query: ({ id }) => `v1/decks/${id}/cards`,
}),
createDeck: builder.mutation<DeckResponse, CreateDeckArgs>({
query: body => ({
url: `v1/decks`,
method: 'POST',
body,
}),
invalidatesTags: ['Decks'],
}),
deleteDeck: builder.mutation<void, { id: string }>({
query: ({ id }) => ({
url: `v1/decks/${id}`,
method: 'DELETE',
}),
invalidatesTags: ['Decks'],
}),
updateDeck: builder.mutation<DeckResponse, UpdateDeckArgs>({
query: ({ id, ...body }) => ({
url: `v1/decks/${id}`,
method: 'PATCH',
body,
}),
invalidatesTags: ['Decks'],
}),
}),
})
export const { useGetDecksQuery, useGetDeckByIdQuery, useGetDeckCardsQuery } = decksService
export const {
useGetDecksQuery,
useGetDeckByIdQuery,
useGetDeckCardsQuery,
useCreateDeckMutation,
useDeleteDeckMutation,
useUpdateDeckMutation,
} = decksService