mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-18 00:54:43 -04:00
Feature/history api (#84)
added /api/v2.0/ to the backend url Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
e2155e735d
commit
02f1b2abcc
8 changed files with 76 additions and 37 deletions
46
src/api/history.ts
Normal file
46
src/api/history.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import { HistoryEntry } from '../components/landing/pages/history/history'
|
||||
import { expectResponseCode, getBackendUrl } from '../utils/apiUtils'
|
||||
import { defaultFetchConfig } from './default'
|
||||
|
||||
export const getHistory = async (): Promise<HistoryEntry[]> => {
|
||||
const response = await fetch(getBackendUrl() + '/history')
|
||||
expectResponseCode(response)
|
||||
return await response.json() as Promise<HistoryEntry[]>
|
||||
}
|
||||
|
||||
export const setHistory = async (entries: HistoryEntry[]): Promise<void> => {
|
||||
const response = await fetch(getBackendUrl() + '/history', {
|
||||
...defaultFetchConfig,
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
history: entries
|
||||
})
|
||||
})
|
||||
expectResponseCode(response)
|
||||
}
|
||||
|
||||
export const deleteHistory = async (): Promise<void> => {
|
||||
const response = await fetch(getBackendUrl() + '/history', {
|
||||
...defaultFetchConfig,
|
||||
method: 'DELETE'
|
||||
})
|
||||
expectResponseCode(response)
|
||||
}
|
||||
|
||||
export const updateHistoryEntry = async (noteId: string, entry: HistoryEntry): Promise<HistoryEntry> => {
|
||||
const response = await fetch(getBackendUrl() + '/history/' + noteId, {
|
||||
...defaultFetchConfig,
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(entry)
|
||||
})
|
||||
expectResponseCode(response)
|
||||
return await response.json() as Promise<HistoryEntry>
|
||||
}
|
||||
|
||||
export const deleteHistoryEntry = async (noteId: string): Promise<void> => {
|
||||
const response = await fetch(getBackendUrl() + '/history/' + noteId, {
|
||||
...defaultFetchConfig,
|
||||
method: 'DELETE'
|
||||
})
|
||||
expectResponseCode(response)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue