oversci/app/lib/services/document.ts
2025-01-31 19:32:50 +08:00

34 lines
744 B
TypeScript

// app/lib/services/document.ts
import axios from "axios";
interface SaveDocumentParams {
id: string;
content: string;
title?: string;
}
export const DocumentService = {
async saveDocument({ id, content, title }: SaveDocumentParams) {
try {
const response = await axios.put(`/api/documents/${id}`, {
content,
title,
});
return response.data;
} catch (error) {
console.error("Error saving document:", error);
throw error;
}
},
async getDocument(id: string) {
try {
const response = await axios.get(`/api/documents/${id}`);
return response.data;
} catch (error) {
console.error("Error fetching document:", error);
throw error;
}
},
};