Started writing API wrapper

pull/11/head
Jef Roosens 2021-12-28 20:40:47 +01:00
parent 9f61d8d48e
commit 66a7cd8def
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
5 changed files with 67 additions and 2 deletions

View File

@ -1,7 +1,7 @@
<script setup lang="ts">
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
import HelloWorld from './components/HelloWorld.vue'
import SectionsList from './components/SectionsList.vue'
</script>
<template>
@ -10,7 +10,7 @@ import HelloWorld from './components/HelloWorld.vue'
alt="Vue logo"
src="./assets/logo.png"
>
<HelloWorld msg="Hello Vue 3 + TypeScript + Vite" />
<SectionsList />
</div>
</template>

15
src/api/v1.ts 100644
View File

@ -0,0 +1,15 @@
const API_PREFIX = "/api/v1"
export class RbApi {
async get_json(path) {
const url = `${API_PREFIX}${path}`
let res = await fetch(url)
return await res.json()
}
async sections() {
let res = await this.get_json("/sections")
return res["sections"]
}
}

View File

@ -0,0 +1,24 @@
<script setup lang="ts">
import { ref } from 'vue'
import { RbApi } from '../api/v1'
import { Section } from '../models'
let sections = ref([])
let api = new RbApi()
await api.sections().then(res => {
sections.value = res
})
</script>
<template>
<div>
<p>yeet</p>
<ul>
<li v-for='section in sections'>
{{ section }}
</li>
</ul>
</div>
</template>

View File

@ -21,6 +21,7 @@ export function makeServer ({ environment = 'development' } = {}) {
routes () {
this.namespace = 'api/v1';
// Offsets & limits don't need to be implemented here, as the data set isn't large enough to require this yet
this.get('/sections', (schema) => {
return schema.sections.all();
})

25
src/models.ts 100644
View File

@ -0,0 +1,25 @@
export interface Section {
id: str,
shortname: str,
description: str,
is_default: bool,
has_titles: bool,
is_private: bool,
is_archived: bool
}
export interface Post {
id: str,
section_id: str,
is_private: bool,
is_archived: bool
}
export interface Version {
id: str,
post_id: str,
title: str,
publish_date: Date,
content: str,
is_draft: bool
}