diff --git a/migrations/0001_nostalgic_skreet.sql b/migrations/0001_nostalgic_skreet.sql
new file mode 100644
index 0000000..cf21484
--- /dev/null
+++ b/migrations/0001_nostalgic_skreet.sql
@@ -0,0 +1,6 @@
+CREATE TABLE IF NOT EXISTS "sharedAdventures" (
+ "id" serial PRIMARY KEY NOT NULL,
+ "name" text NOT NULL,
+ "location" text,
+ "date" text
+);
diff --git a/migrations/0002_dusty_captain_midlands.sql b/migrations/0002_dusty_captain_midlands.sql
new file mode 100644
index 0000000..5945004
--- /dev/null
+++ b/migrations/0002_dusty_captain_midlands.sql
@@ -0,0 +1 @@
+ALTER TABLE "sharedAdventures" ALTER COLUMN "id" SET DATA TYPE text;
\ No newline at end of file
diff --git a/migrations/0003_clammy_goblin_queen.sql b/migrations/0003_clammy_goblin_queen.sql
new file mode 100644
index 0000000..ada8daf
--- /dev/null
+++ b/migrations/0003_clammy_goblin_queen.sql
@@ -0,0 +1,4 @@
+ALTER TABLE "sharedAdventures" ADD COLUMN "data" json NOT NULL;--> statement-breakpoint
+ALTER TABLE "sharedAdventures" DROP COLUMN IF EXISTS "name";--> statement-breakpoint
+ALTER TABLE "sharedAdventures" DROP COLUMN IF EXISTS "location";--> statement-breakpoint
+ALTER TABLE "sharedAdventures" DROP COLUMN IF EXISTS "date";
\ No newline at end of file
diff --git a/migrations/meta/0001_snapshot.json b/migrations/meta/0001_snapshot.json
new file mode 100644
index 0000000..bbdf8d5
--- /dev/null
+++ b/migrations/meta/0001_snapshot.json
@@ -0,0 +1,77 @@
+{
+ "id": "183ebfda-8d83-4256-8715-169d36867deb",
+ "prevId": "1639b320-88dd-4af5-ae34-092ab26b4b85",
+ "version": "5",
+ "dialect": "pg",
+ "tables": {
+ "featuredAdventures": {
+ "name": "featuredAdventures",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "location": {
+ "name": "location",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "sharedAdventures": {
+ "name": "sharedAdventures",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "location": {
+ "name": "location",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "date": {
+ "name": "date",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ }
+ },
+ "enums": {},
+ "schemas": {},
+ "_meta": {
+ "columns": {},
+ "schemas": {},
+ "tables": {}
+ }
+}
\ No newline at end of file
diff --git a/migrations/meta/0002_snapshot.json b/migrations/meta/0002_snapshot.json
new file mode 100644
index 0000000..7be23f6
--- /dev/null
+++ b/migrations/meta/0002_snapshot.json
@@ -0,0 +1,77 @@
+{
+ "id": "808d6d31-5ef6-4b22-97f0-cfc73193eb5e",
+ "prevId": "183ebfda-8d83-4256-8715-169d36867deb",
+ "version": "5",
+ "dialect": "pg",
+ "tables": {
+ "featuredAdventures": {
+ "name": "featuredAdventures",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "location": {
+ "name": "location",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "sharedAdventures": {
+ "name": "sharedAdventures",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "location": {
+ "name": "location",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "date": {
+ "name": "date",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ }
+ },
+ "enums": {},
+ "schemas": {},
+ "_meta": {
+ "columns": {},
+ "schemas": {},
+ "tables": {}
+ }
+}
\ No newline at end of file
diff --git a/migrations/meta/0003_snapshot.json b/migrations/meta/0003_snapshot.json
new file mode 100644
index 0000000..f8fd8c1
--- /dev/null
+++ b/migrations/meta/0003_snapshot.json
@@ -0,0 +1,65 @@
+{
+ "id": "45d98527-f0a9-44fc-9658-d3c461afed95",
+ "prevId": "808d6d31-5ef6-4b22-97f0-cfc73193eb5e",
+ "version": "5",
+ "dialect": "pg",
+ "tables": {
+ "featuredAdventures": {
+ "name": "featuredAdventures",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "location": {
+ "name": "location",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "sharedAdventures": {
+ "name": "sharedAdventures",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "data": {
+ "name": "data",
+ "type": "json",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ }
+ },
+ "enums": {},
+ "schemas": {},
+ "_meta": {
+ "columns": {},
+ "schemas": {},
+ "tables": {}
+ }
+}
\ No newline at end of file
diff --git a/migrations/meta/_journal.json b/migrations/meta/_journal.json
index 18e2194..5af8112 100644
--- a/migrations/meta/_journal.json
+++ b/migrations/meta/_journal.json
@@ -8,6 +8,27 @@
"when": 1712061709595,
"tag": "0000_fancy_starjammers",
"breakpoints": true
+ },
+ {
+ "idx": 1,
+ "version": "5",
+ "when": 1712083579596,
+ "tag": "0001_nostalgic_skreet",
+ "breakpoints": true
+ },
+ {
+ "idx": 2,
+ "version": "5",
+ "when": 1712083756923,
+ "tag": "0002_dusty_captain_midlands",
+ "breakpoints": true
+ },
+ {
+ "idx": 3,
+ "version": "5",
+ "when": 1712083977580,
+ "tag": "0003_clammy_goblin_queen",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/src/lib/db/schema.ts b/src/lib/db/schema.ts
index f02329b..7ac75d8 100644
--- a/src/lib/db/schema.ts
+++ b/src/lib/db/schema.ts
@@ -1,4 +1,4 @@
-import { pgTable,serial,text } from "drizzle-orm/pg-core";
+import { pgTable,json,text,serial } from "drizzle-orm/pg-core";
export const featuredAdventures = pgTable("featuredAdventures",{
id:serial("id").primaryKey(),
@@ -6,4 +6,7 @@ export const featuredAdventures = pgTable("featuredAdventures",{
location:text("location"),
})
-
+export const sharedAdventures = pgTable("sharedAdventures",{
+ id:text("id").primaryKey(),
+ data:json("data").notNull(),
+})
\ No newline at end of file
diff --git a/src/lib/index.ts b/src/lib/index.ts
index 856f2b6..938c29f 100644
--- a/src/lib/index.ts
+++ b/src/lib/index.ts
@@ -1 +1,11 @@
// place files you want to import through the `$lib` alias in this folder.
+export function generateRandomString() {
+ let randomString = '';
+ const digits = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+
+ for (let i = 0; i < 10; i++) {
+ const randomIndex = Math.floor(Math.random() * digits.length);
+ randomString += digits[randomIndex];
+ }
+ return randomString;
+}
\ No newline at end of file
diff --git a/src/routes/api/share/+server.ts b/src/routes/api/share/+server.ts
new file mode 100644
index 0000000..4a42082
--- /dev/null
+++ b/src/routes/api/share/+server.ts
@@ -0,0 +1,11 @@
+import { db } from "$lib/db/db.server";
+import { sharedAdventures } from "$lib/db/schema";
+import type { Adventure } from "$lib/utils/types";
+
+export async function POST({ request }: { request: Request }) {
+ const { key , data } = await request.json();
+ let adventure = data as Adventure;
+ console.log(adventure);
+ await db.insert(sharedAdventures).values({ id:key,data:adventure }).execute();
+ return new Response(JSON.stringify({key:key}));
+}
\ No newline at end of file
diff --git a/src/routes/log/+page.svelte b/src/routes/log/+page.svelte
index 9d0eb78..bfa6688 100644
--- a/src/routes/log/+page.svelte
+++ b/src/routes/log/+page.svelte
@@ -10,6 +10,7 @@
import SucessToast from "$lib/components/SucessToast.svelte";
import mapDrawing from "$lib/assets/adventure_map.svg"
import EditModal from "$lib/components/EditModal.svelte";
+ import { generateRandomString } from "$lib";
let newName = '';
let newLocation = '';
@@ -79,6 +80,26 @@
}
}
+ function shareLink() {
+ let key = generateRandomString()
+ let data = JSON.stringify(adventures)
+ fetch('/api/share', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({ key, data }),
+ })
+ .then(response => response.json())
+ .then(data => {
+ console.log('Success:', data);
+ })
+ .catch((error) => {
+ console.error('Error:', error);
+ });
+
+ }
+
function handleClose() {
editId = NaN;
editName = '';
@@ -144,5 +165,8 @@
+
{/if}