import type {Whiteboard} from "@/types"; import {api} from './api' export const whiteboardService = { async getWhiteboardHistory(): Promise { const raw = await api.get('/api/Whiteboard/history') return raw.map(mapWhiteboard) }, async getRecentWhiteboards(): Promise { const raw = await api.get('/api/Whiteboard/recent') return raw.map(mapWhiteboard) }, async createNewWhiteboard(title: string): Promise { return await api.post('/api/Whiteboard', { title: title, maxParticipants: 10, joinPolicy: 0}) }, async getWhiteboardById(id: string): Promise { return await api.get(`/api/Whiteboard/${id}`).then(mapWhiteboard) }, async deleteWhiteboard(id: string): Promise { await api.delete(`/api/Whiteboard/${id}`) } } function mapWhiteboard(raw: any): Whiteboard { return { id: raw.id, ownerId: raw.ownerId, code: raw.code, title: raw.title, createdAt: new Date(raw.createdAt), deletedAt: raw.deletedAt ? new Date(raw.deletedAt) : undefined, maxParticipants: raw.maxParticipants, joinPolicy: raw.joinPolicy, state: raw.state, } }