mirror of
https://github.com/ershisan99/flashcards-example-project.git
synced 2025-12-16 20:59:27 +00:00
Merge master into storybook-deploy
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user