Files
guides/frontend/src/api.js
2026-05-31 18:04:56 +02:00

117 lines
3.3 KiB
JavaScript

const BASE = '/api'
export async function fetchGuides() {
const res = await fetch(`${BASE}/guides`)
return res.json()
}
export async function fetchGuide(id) {
const res = await fetch(`${BASE}/guides/${id}`)
return res.json()
}
export async function createGuide(topic, format, instructions = '') {
const res = await fetch(`${BASE}/guides`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ topic, format, instructions }),
})
return res.json()
}
export async function reworkGuide(id, instructions) {
const res = await fetch(`${BASE}/guides/${id}/rework`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ instructions }),
})
return res.json()
}
export async function cancelGuide(id) {
await fetch(`${BASE}/guides/${id}/cancel`, { method: 'POST' })
}
export async function deleteGuide(id) {
await fetch(`${BASE}/guides/${id}`, { method: 'DELETE' })
}
export function pdfUrl(id) {
return `${BASE}/guides/${id}/pdf`
}
export function htmlUrl(id) {
return `${BASE}/guides/${id}/html`
}
export async function suggestTopics(problem) {
const res = await fetch(`${BASE}/topic-suggestions`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ problem }),
})
return res.json()
}
export async function fetchBausteine(topic) {
const res = await fetch(`${BASE}/bausteine?topic=${encodeURIComponent(topic)}`)
return res.json()
}
export async function createBaustein(topic, title, instructions = '') {
const res = await fetch(`${BASE}/bausteine`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ topic, title, instructions }),
})
return res.json()
}
export async function deleteBaustein(id) {
await fetch(`${BASE}/bausteine/${id}`, { method: 'DELETE' })
}
export async function reworkBaustein(id, instructions) {
await fetch(`${BASE}/bausteine/${id}/rework`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ instructions }),
})
}
export async function sortBausteine(topic, instructions = '') {
await fetch(`${BASE}/bausteine/sort?topic=${encodeURIComponent(topic)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ instructions }),
})
}
export async function fetchSortStatus(topic) {
const res = await fetch(`${BASE}/bausteine/sort/status?topic=${encodeURIComponent(topic)}`)
return res.json()
}
export async function fetchSuggestions(topic) {
const res = await fetch(`${BASE}/bausteine/suggestions?topic=${encodeURIComponent(topic)}`)
return res.json()
}
export async function generateSuggestions(topic) {
await fetch(`${BASE}/bausteine/suggestions/generate?topic=${encodeURIComponent(topic)}`, { method: 'POST' })
}
export async function fetchSuggestionsStatus(topic) {
const res = await fetch(`${BASE}/bausteine/suggestions/status?topic=${encodeURIComponent(topic)}`)
return res.json()
}
export async function addSuggestion(id) {
const res = await fetch(`${BASE}/bausteine/suggestions/${id}/add`, { method: 'POST' })
return res.json()
}
export async function ignoreSuggestion(id) {
await fetch(`${BASE}/bausteine/suggestions/${id}/ignore`, { method: 'POST' })
}