Implemented the new react version of the frontend
This commit is contained in:
1 parent
236e6e06fb
commit
ffe7e52527
65 files changed
+5228
-177
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import { api } from '@/lib/api';
|
||||
import { normalizeCollection } from '@/lib/normalizers';
|
||||
import type { Collection } from '@/types';
|
||||
|
||||
export const collectionsApi = {
|
||||
getAll: () =>
|
||||
api
|
||||
.get<Collection[]>('/collections')
|
||||
.then((r) => r.data.map(normalizeCollection)),
|
||||
|
||||
getById: (id: number) =>
|
||||
api
|
||||
.get<Collection>(`/collections/${id}`)
|
||||
.then((r) => normalizeCollection(r.data)),
|
||||
|
||||
create: (data: Partial<Collection>) =>
|
||||
api.post<Collection>('/collections', data).then((r) => r.data),
|
||||
|
||||
update: (id: number, data: Partial<Collection>) =>
|
||||
api.put<Collection>(`/collections/${id}`, data).then((r) => normalizeCollection(r.data)),
|
||||
|
||||
updateWithMedia: (id: number, formData: FormData) =>
|
||||
api
|
||||
.put<Collection>(`/collections/${id}`, formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
})
|
||||
.then((r) => normalizeCollection(r.data)),
|
||||
|
||||
delete: (id: number) =>
|
||||
api.delete(`/collections/${id}`).then((r) => r.data),
|
||||
|
||||
addEntry: (collectionId: number, entryId: number) =>
|
||||
api
|
||||
.post(`/collections/${collectionId}/entries`, { entry_id: entryId })
|
||||
.then((r) => r.data),
|
||||
|
||||
removeEntry: (collectionId: number, entryId: number) =>
|
||||
api
|
||||
.delete(`/collections/${collectionId}/entries/${entryId}`)
|
||||
.then((r) => r.data),
|
||||
};
|
||||
Reference in new issue
Block a user