Started writing API wrapper
parent
9f61d8d48e
commit
66a7cd8def
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
// This starter template is using Vue 3 <script setup> SFCs
|
// This starter template is using Vue 3 <script setup> SFCs
|
||||||
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
|
// 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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -10,7 +10,7 @@ import HelloWorld from './components/HelloWorld.vue'
|
||||||
alt="Vue logo"
|
alt="Vue logo"
|
||||||
src="./assets/logo.png"
|
src="./assets/logo.png"
|
||||||
>
|
>
|
||||||
<HelloWorld msg="Hello Vue 3 + TypeScript + Vite" />
|
<SectionsList />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
@ -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"]
|
||||||
|
}
|
||||||
|
}
|
|
@ -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>
|
|
@ -21,6 +21,7 @@ export function makeServer ({ environment = 'development' } = {}) {
|
||||||
routes () {
|
routes () {
|
||||||
this.namespace = 'api/v1';
|
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) => {
|
this.get('/sections', (schema) => {
|
||||||
return schema.sections.all();
|
return schema.sections.all();
|
||||||
})
|
})
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue