feat: create block service for API operations
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import api from './api';
|
||||
|
||||
// Get all blocks for the current project
|
||||
export const getBlocks = async () => {
|
||||
try {
|
||||
const response = await api.get('/blocks');
|
||||
return response.data || [];
|
||||
} catch (error) {
|
||||
console.error('Error fetching blocks:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new block definition
|
||||
export const createBlock = async (blockData) => {
|
||||
try {
|
||||
const response = await api.post('/blocks', blockData);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error creating block:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Update an existing block definition
|
||||
export const updateBlock = async (blockId, blockData) => {
|
||||
try {
|
||||
const response = await api.put(`/blocks/${blockId}`, blockData);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error updating block:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Delete a block definition
|
||||
export const deleteBlock = async (blockId) => {
|
||||
try {
|
||||
await api.delete(`/blocks/${blockId}`);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error deleting block:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// Insert a block instance on the canvas
|
||||
export const insertBlockInstance = async (blockId, position) => {
|
||||
try {
|
||||
const response = await api.post(`/blocks/${blockId}/insert`, position);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error inserting block instance:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user