diff --git a/src/frontend/apps/drive/src/features/drivers/Driver.ts b/src/frontend/apps/drive/src/features/drivers/Driver.ts index fb43e431..4543c945 100644 --- a/src/frontend/apps/drive/src/features/drivers/Driver.ts +++ b/src/frontend/apps/drive/src/features/drivers/Driver.ts @@ -1,5 +1,7 @@ -import { Item } from "./types"; +import { Item, ItemType } from "./types"; export abstract class Driver { - abstract getItems(path: string): Promise; + abstract getItems(filters?: { type?: ItemType }): Promise; + abstract getItem(id: string): Promise; + abstract createFolder(data: { title: string }): Promise; } diff --git a/src/frontend/apps/drive/src/features/drivers/implementations/DummyDriver.ts b/src/frontend/apps/drive/src/features/drivers/implementations/DummyDriver.ts index 213232f9..12dc00cd 100644 --- a/src/frontend/apps/drive/src/features/drivers/implementations/DummyDriver.ts +++ b/src/frontend/apps/drive/src/features/drivers/implementations/DummyDriver.ts @@ -6,9 +6,28 @@ export class DummyDriver extends Driver { return [ { id: "1", - name: "Mon Espace", + title: "Mon Espace", type: ItemType.FOLDER, + lastUpdate: new Date().toISOString(), }, ]; } + + async getItem(id: string): Promise { + return { + id: "1", + title: "Mon Espace", + type: ItemType.FOLDER, + lastUpdate: new Date().toISOString(), + }; + } + + async createFolder(data: { title: string }): Promise { + return { + id: "1", + title: data.title, + type: ItemType.FOLDER, + lastUpdate: new Date().toISOString(), + }; + } } diff --git a/src/frontend/apps/drive/src/features/drivers/implementations/StandardDriver.ts b/src/frontend/apps/drive/src/features/drivers/implementations/StandardDriver.ts index 293902b2..c269f328 100644 --- a/src/frontend/apps/drive/src/features/drivers/implementations/StandardDriver.ts +++ b/src/frontend/apps/drive/src/features/drivers/implementations/StandardDriver.ts @@ -1,11 +1,35 @@ import { fetchAPI } from "@/features/api/fetchApi"; import { Driver } from "../Driver"; -import { Item } from "../types"; +import { Item, ItemType } from "../types"; export class StandardDriver extends Driver { - async getItems(): Promise { - const response = await fetchAPI(`items/`); + async getItems(filters = {}): Promise { + const response = await fetchAPI(`items/`, { + params: filters, + }); const data = await response.json(); return data.results; } + + async getItem(id: string): Promise { + const response = await fetchAPI(`items/${id}/`); + const data = await response.json(); + return data; + } + + async createFolder(data: { + title: string; + parentId?: string; + }): Promise { + const { parentId, ...rest } = data; + const response = await fetchAPI(`items/${parentId}/children/`, { + method: "POST", + body: JSON.stringify({ + ...rest, + type: ItemType.FOLDER, + }), + }); + const item = await response.json(); + return item; + } } diff --git a/src/frontend/apps/drive/src/features/drivers/types.ts b/src/frontend/apps/drive/src/features/drivers/types.ts index 71eaaefd..e5ab1d7f 100644 --- a/src/frontend/apps/drive/src/features/drivers/types.ts +++ b/src/frontend/apps/drive/src/features/drivers/types.ts @@ -5,7 +5,7 @@ export enum ItemType { export type Item = { id: string; - name: string; + title: string; type: ItemType; lastUpdate: string; };