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..9a1e614 --- /dev/null +++ b/server/api/cosetta/[uuid]/taken.post.js @@ -0,0 +1,10 @@ +import { toggleTaken } from '../../../controller' + +export default defineEventHandler(async (event) => { + try { + toggleTaken(event.context.params.uuid) + return { success: true } + } 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) +}