Newer
Older
cortex-hub / frontend / src / services / api / skillService.js
import { fetchWithAuth } from './apiClient';

/**
 * Fetches all skills.
 */
export const getSkills = async () => {
  return await fetchWithAuth('/skills/');
};

/**
 * Creates a new skill.
 */
export const createSkill = async (skillData) => {
  return await fetchWithAuth('/skills/', {
    method: "POST",
    body: skillData
  });
};

/**
 * Updates a skill.
 */
export const updateSkill = async (skillId, skillData) => {
  return await fetchWithAuth(`/skills/${skillId}`, {
    method: "PUT",
    body: skillData
  });
};

/**
 * Deletes a skill.
 */
export const deleteSkill = async (skillId) => {
  return await fetchWithAuth(`/skills/${skillId}`, {
    method: "DELETE"
  });
};

// --- VFS API ---

export const getSkillFiles = async (skillId) => {
  return await fetchWithAuth(`/skills/${skillId}/files`);
};

export const getSkillFileContent = async (skillId, path) => {
  return await fetchWithAuth(`/skills/${skillId}/files/${encodeURIComponent(path)}`);
};

export const saveSkillFile = async (skillId, path, content) => {
  return await fetchWithAuth(`/skills/${skillId}/files/${encodeURIComponent(path)}`, {
    method: "POST",
    body: { content }
  });
};

export const deleteSkillFile = async (skillId, path) => {
  return await fetchWithAuth(`/skills/${skillId}/files/${encodeURIComponent(path)}`, {
    method: "DELETE"
  });
};