From 4806feadebb9358978e39a98016fd34c46fae1d7 Mon Sep 17 00:00:00 2001 From: blat Date: Mon, 29 Aug 2022 15:42:06 +0200 Subject: [PATCH] aggiunto segnapreso senza auth --- TODO.md | 2 +- components/cosetta.vue | 1 + components/toggleTaken.vue | 25 +++++++++++++++++++++++++ pages/c/[cosetta].vue | 3 +++ server/api/cosetta/[uuid]/taken.post.js | 25 +++++++++++++++++++++++++ server/controller.js | 7 ++++++- 6 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 components/toggleTaken.vue create mode 100644 server/api/cosetta/[uuid]/taken.post.js diff --git a/TODO.md b/TODO.md index 1c83e42..3081932 100644 --- a/TODO.md +++ b/TODO.md @@ -10,6 +10,6 @@ - [ ] un loading per next / prev - [ ] immagine del banner da scaricare in locale - [ ] favicon (solo perche' senza ci mette un sacco a fare il load) -- [ ] ci vuole un modo per segnare che un oggetto e' stato preso? forse no se facciamo un'asta live +- [x] ci vuole un modo per segnare che un oggetto e' stato preso? forse no se facciamo un'asta live - [ ] deploy - [ ] mail in lista diff --git a/components/cosetta.vue b/components/cosetta.vue index d6f83fc..3152a16 100644 --- a/components/cosetta.vue +++ b/components/cosetta.vue @@ -20,5 +20,6 @@ const { cosetta } = defineProps({ class="inline-block bg-gray-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2" v-text='tag' /> + diff --git a/components/toggleTaken.vue b/components/toggleTaken.vue new file mode 100644 index 0000000..96e08d4 --- /dev/null +++ b/components/toggleTaken.vue @@ -0,0 +1,25 @@ + + diff --git a/pages/c/[cosetta].vue b/pages/c/[cosetta].vue index 658ad1d..fd03586 100644 --- a/pages/c/[cosetta].vue +++ b/pages/c/[cosetta].vue @@ -39,6 +39,9 @@ onMounted(() => {
+ + +

chiacchiere

diff --git a/server/api/cosetta/[uuid]/taken.post.js b/server/api/cosetta/[uuid]/taken.post.js new file mode 100644 index 0000000..cc73a73 --- /dev/null +++ b/server/api/cosetta/[uuid]/taken.post.js @@ -0,0 +1,25 @@ +import { toggleTaken } from '../../../controller' +import { useBody } from 'h3' + +export default defineEventHandler(async (event) => { + try { + const body = await useBody(event) + const taken = toggleTaken(event.context.params.uuid) + return { success: true, taken } + } catch (e) { + return { success: false, reason: e.message } + } +}) + + +// import { setTaken } from '../../controller' +// +// export default defineEventHandler(async (event) => { +// try { +// const body = await useBody(event) +// const taken = setTaken(event.context.params.uuid) +// return { success: true, taken } +// } catch (e) { +// return { success: false, reason: e.message } +// } +// }) diff --git a/server/controller.js b/server/controller.js index 8bf1df3..07304a8 100644 --- a/server/controller.js +++ b/server/controller.js @@ -6,7 +6,7 @@ const db = new Database('./cosette.db') export function load() { db.pragma('journal_mode = WAL') - db.exec('CREATE TABLE IF NOT EXISTS cosette (uuid TEXT PRIMARY KEY, name TEXT NOT NULL, description TEXT, tags TEXT, images TEXT, updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP)') + db.exec('CREATE TABLE IF NOT EXISTS cosette (uuid TEXT PRIMARY KEY, name TEXT NOT NULL, description TEXT, tags TEXT, images TEXT, taken TINYINT DEFAULT 0, updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP)') db.exec('CREATE INDEX IF NOT EXISTS cosette_updated_at_index ON cosette (updatedAt)') db.exec('CREATE TABLE IF NOT EXISTS chan (uuid TEXT PRIMARY KEY, cosetta_uuid REFERENCES cosette(uuid), message TEXT, updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP)') } @@ -70,3 +70,8 @@ export function getComment(uuid) { const comment = q.get(uuid) return comment } + +export function toggleTaken(uuid) { + const q = db.prepare('UPDATE cosette SET taken = ABS(taken - 1) WHERE uuid = ?') + return q.run(uuid) +}