diff --git a/server.js b/server.js index 9ea4469..697046e 100644 --- a/server.js +++ b/server.js @@ -5,6 +5,8 @@ const port = 8000; const user = JSON.stringify({ name: "Joe User", + stickers: [], + username: "joe", }); const stickers = { @@ -12,12 +14,20 @@ const stickers = { color: "#000088", layout: "layout1", message1: "I am an activist!", + uuid: "88ae126f-b19a-4287-abe0-a8f5ac763cb7", }, } const requestListener = function (req, res) { res.setHeader("Content-Type", "application/json"); const urlParts = req.url.split("/"); + let body = ''; + req.on('data', chunk => { + body += chunk.toString(); + }); + req.on('end', () => { + console.log('body', body); + }); console.log(urlParts); switch (urlParts[1]) { case "login": diff --git a/src/stores/stickerStore.ts b/src/stores/stickerStore.ts index d96447f..58e8156 100644 --- a/src/stores/stickerStore.ts +++ b/src/stores/stickerStore.ts @@ -6,7 +6,7 @@ export const useStickerStore = defineStore('sticker', { console.log('fetch'); // TODO: Check if we have it already and if it's stale. const response = await fetch( - `/sticker/${uuid}`, + `/api/sticker/${uuid}`, ); const json = await response.json(); console.log(json); diff --git a/src/stores/userStore.ts b/src/stores/userStore.ts index c179471..fb99ee2 100644 --- a/src/stores/userStore.ts +++ b/src/stores/userStore.ts @@ -2,28 +2,44 @@ import { defineStore } from 'pinia' const anonymous = { name: 'Anonymous', + stickers: [], username: null, }; export const useUserStore = defineStore('user', { actions: { + async addSticker(sticker) { + const response = await fetch( + `/api/user/${this.user.username}/stickers`, + { + body: JSON.stringify({uuid: sticker.uuid}), + method: 'POST', + }, + ); + if (response.ok) { + this.user.stickers.push(sticker); + } + }, async login(username: string, password: string) { const response = await fetch( - "/login", + "/api/login", { method: 'POST', }, ); const json = await response.json(); + console.log('login', json); // this.user.name = json.name; this.user = { name: json.name, - username: "username", + stickers: json.stickers, + username: json.username, } return json; }, logout() { - console.log('logout2'); + console.log('logout'); + // TODO: Tell server. // this.user = anonymous; // this.hasChanged = true; // this.user.name = 'Anonymous'; diff --git a/src/views/StickerView.vue b/src/views/StickerView.vue index 6c280b5..cf18673 100644 --- a/src/views/StickerView.vue +++ b/src/views/StickerView.vue @@ -13,7 +13,6 @@ const userStore = useUserStore(); const route = useRoute(); const uuid = ref(route.params.uuid as string); // const uuid = ref(route.params.uuid); -console.log('uuid', uuid.value); onBeforeMount(async () => { await stickerStore.fetch(uuid.value); @@ -28,6 +27,10 @@ const second = computed(() => { return [parts[3], parts[4]].join('-'); }) +function claimSticker() { + userStore.addSticker(stickerStore.sticker); +} +