diff --git a/migrations/0009_spotty_madame_web.sql b/migrations/0009_spotty_madame_web.sql
new file mode 100644
index 0000000..900b8d7
--- /dev/null
+++ b/migrations/0009_spotty_madame_web.sql
@@ -0,0 +1,5 @@
+ALTER TABLE "userVisitedAdventures" RENAME COLUMN "adventure_visited" TO "adventure_id";--> statement-breakpoint
+ALTER TABLE "userVisitedAdventures" ADD PRIMARY KEY ("adventure_id");--> statement-breakpoint
+ALTER TABLE "userVisitedAdventures" ALTER COLUMN "adventure_id" SET DATA TYPE serial;--> statement-breakpoint
+ALTER TABLE "userVisitedAdventures" ALTER COLUMN "adventure_id" SET NOT NULL;--> statement-breakpoint
+ALTER TABLE "userVisitedAdventures" ADD COLUMN "visited_date" text;
\ No newline at end of file
diff --git a/migrations/meta/0009_snapshot.json b/migrations/meta/0009_snapshot.json
new file mode 100644
index 0000000..46e2615
--- /dev/null
+++ b/migrations/meta/0009_snapshot.json
@@ -0,0 +1,201 @@
+{
+ "id": "1d83805d-6ee2-4dae-87a6-5af6f2d5add3",
+ "prevId": "ec5af5e4-8522-4383-af47-412fb43c7cc3",
+ "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": {}
+ },
+ "session": {
+ "name": "session",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "session_user_id_user_id_fk": {
+ "name": "session_user_id_user_id_fk",
+ "tableFrom": "session",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "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": {}
+ },
+ "user": {
+ "name": "user",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "username": {
+ "name": "username",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "first_name": {
+ "name": "first_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "last_name": {
+ "name": "last_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "hashed_password": {
+ "name": "hashed_password",
+ "type": "varchar",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {}
+ },
+ "userVisitedAdventures": {
+ "name": "userVisitedAdventures",
+ "schema": "",
+ "columns": {
+ "adventure_id": {
+ "name": "adventure_id",
+ "type": "serial",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "adventure_name": {
+ "name": "adventure_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "location": {
+ "name": "location",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "visited_date": {
+ "name": "visited_date",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "userVisitedAdventures_user_id_user_id_fk": {
+ "name": "userVisitedAdventures_user_id_user_id_fk",
+ "tableFrom": "userVisitedAdventures",
+ "tableTo": "user",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "no action",
+ "onUpdate": "no action"
+ }
+ },
+ "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 730cbd1..226286d 100644
--- a/migrations/meta/_journal.json
+++ b/migrations/meta/_journal.json
@@ -64,6 +64,13 @@
"when": 1712186591227,
"tag": "0008_romantic_maria_hill",
"breakpoints": true
+ },
+ {
+ "idx": 9,
+ "version": "5",
+ "when": 1712407140727,
+ "tag": "0009_spotty_madame_web",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/src/lib/components/Navbar.svelte b/src/lib/components/Navbar.svelte
index 36ffccd..f05c718 100644
--- a/src/lib/components/Navbar.svelte
+++ b/src/lib/components/Navbar.svelte
@@ -43,10 +43,12 @@
class="btn btn-primary my-2 md:my-0 md:mr-4 md:ml-2"
on:click={goHome}>Home
-
+ {#if user}
+
+ {/if}
diff --git a/src/lib/db/schema.ts b/src/lib/db/schema.ts
index 6e252a2..2800cad 100644
--- a/src/lib/db/schema.ts
+++ b/src/lib/db/schema.ts
@@ -40,10 +40,11 @@ export const sessionTable = pgTable("session", {
});
export const userVisitedAdventures = pgTable("userVisitedAdventures", {
+ adventureID: serial("adventure_id").primaryKey(),
userId: text("user_id")
.notNull()
.references(() => userTable.id),
adventureName: text("adventure_name").notNull(),
location: text("location"),
- adventureVistied: text("adventure_visited"),
+ visitedDate: text("visited_date"),
});
diff --git a/src/routes/api/visits/+server.ts b/src/routes/api/visits/+server.ts
index d6d9aba..3f9c243 100644
--- a/src/routes/api/visits/+server.ts
+++ b/src/routes/api/visits/+server.ts
@@ -3,6 +3,7 @@ import type { RequestEvent } from "@sveltejs/kit";
import { userVisitedAdventures } from "$lib/db/schema";
import { db } from "$lib/db/db.server";
import { eq } from "drizzle-orm";
+import type { Adventure } from "$lib/utils/types";
// Gets all the adventures that the user has visited
export async function GET(event: RequestEvent): Promise {
@@ -14,16 +15,19 @@ export async function GET(event: RequestEvent): Promise {
},
});
}
-
let result = await db
.select()
.from(userVisitedAdventures)
.where(eq(userVisitedAdventures.userId, event.locals.user.id))
.execute();
-
return new Response(
JSON.stringify({
- result: result,
+ adventures: result.map((item) => ({
+ id: item.adventureID,
+ name: item.adventureName,
+ location: item.location,
+ created: item.visitedDate,
+ })),
}),
{
status: 200,
diff --git a/src/routes/log/+page.server.ts b/src/routes/log/+page.server.ts
new file mode 100644
index 0000000..41f111f
--- /dev/null
+++ b/src/routes/log/+page.server.ts
@@ -0,0 +1,13 @@
+import { redirect } from "@sveltejs/kit";
+import type { PageServerLoad } from "./$types";
+
+export const load: PageServerLoad = async (event) => {
+ if (!event.locals.user) {
+ return redirect(302, "/login");
+ }
+ const response = await event.fetch("/api/visits");
+ const result = await response.json();
+ return {
+ result,
+ };
+};
diff --git a/src/routes/log/+page.svelte b/src/routes/log/+page.svelte
index 5af4f81..451f01e 100644
--- a/src/routes/log/+page.svelte
+++ b/src/routes/log/+page.svelte
@@ -1,4 +1,6 @@