Implemented article get endpoint

This commit is contained in:
2022-02-02 16:15:01 +01:00
parent a0a6a3b799
commit 026bf1c3bc
3 changed files with 47 additions and 3 deletions

View File

@@ -54,7 +54,7 @@ async function login(username: string, password: string): Promise<void> {
let result = await fetch(`${prefix}/api/login`, {
method: "POST",
body: JSON.stringify({"username": username, "password": password}),
credentials: "include"
credentials: "same-origin"
})
switch (result.status) {
case 200:
@@ -119,6 +119,34 @@ async function search(q: SearchQuery): Promise<ArticleSummary[]> {
}
}
interface ArticleGetPayload {
title: string,
summary: string,
authors: number[],
image: string,
tags: string[],
link: string
content: string
}
async function getArticle(id: number): Promise<ArticleGetPayload> {
let query = [["id", id]]
let result = await fetch(`${prefix}/api/article?${buildQuery(query)}`, {
method: "GET"
})
switch (result.status) {
case 200:
return await result.json()
case 401:
throw new Error("Not authorized")
case 404:
throw new Error("Article not found")
default:
throw await unknownResponse(result)
}
}
interface ArticleUploadPayload {
title: string,
summary: string,