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:
Philip Molares 2020-05-30 10:12:01 +02:00 committed by GitHub
parent e2155e735d
commit 02f1b2abcc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 76 additions and 37 deletions

46
src/api/history.ts Normal file
View 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)
}