diff --git a/backend/src/app.ts b/backend/src/app.ts
index f3009f4..58b8a46 100644
--- a/backend/src/app.ts
+++ b/backend/src/app.ts
@@ -79,8 +79,17 @@ app.post('/api/character', jsonParser, async (req, res) => {
const orderBy = req.body.orderBy
const count = req.body.count
+ const characterData = await Character.findAll({
+ offset: page * count,
+ limit: count
+ })
+ const pageCount = Math.ceil(await Character.count() / count)
+
+console.log(characterData)
+console.log(pageCount)
+
res.setHeader('Content-Type', 'application/json')
- res.send(await Character.findAll({ offset: page * count, limit: count }))
+ res.json({characterData, pageCount})
})
app.get('/api/game/:characterId', async (req, res) => {
diff --git a/frontend/src/vues/CharacterList.vue b/frontend/src/vues/CharacterList.vue
index fb1534d..e89567e 100644
--- a/frontend/src/vues/CharacterList.vue
+++ b/frontend/src/vues/CharacterList.vue
@@ -11,7 +11,7 @@
-
+
|
{{ character.id }}
|
@@ -26,6 +26,7 @@
+
@@ -39,19 +40,23 @@ import axios from 'axios'
let page = 0
let count = 10
-const characters = ref({
- data: [
- { id: 1, name: 'test', player: 'test player', status: 'active', lastGame: 0 },
- { id: 1, name: 'test', player: 'test player', status: 'active', lastGame: 0 }
- ]
-})
+const characters = ref({})
+const pageCount = ref({})
async function loadData() {
- characters.value = await axios.post('/api/character', {
+ const response = await axios.post('/api/character', {
page: `${page}`,
count: `${count}`,
orderBy: 'id'
})
+
+ console.log(response)
+
+ characters.value = response.data.characterData
+ pageCount.value = response.data.pageCount
+
+ console.log(characters.value)
+ console.log(pageCount.value)
}
function previousPage() {
@@ -64,6 +69,11 @@ function nextPage() {
loadData()
}
+function setPage(targetPage:number) {
+ this.page=targetPage - 1
+ loadData()
+}
+
onMounted(async () => {
loadData()
})