mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-04 12:45:17 +02:00
Add name and date columns to sharedAdventures table and display them in shared adventure page
This commit is contained in:
parent
167080441a
commit
a6c3738c48
7 changed files with 241 additions and 3 deletions
2
migrations/0011_heavy_ben_urich.sql
Normal file
2
migrations/0011_heavy_ben_urich.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE "sharedAdventures" ADD COLUMN "name" text NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "sharedAdventures" ADD COLUMN "date" text NOT NULL;
|
219
migrations/meta/0011_snapshot.json
Normal file
219
migrations/meta/0011_snapshot.json
Normal file
|
@ -0,0 +1,219 @@
|
|||
{
|
||||
"id": "b318f7a7-c4e1-49f3-9bfc-7d68f118bf7d",
|
||||
"prevId": "d6cd08c8-9dc8-42df-aab9-0f5800602864",
|
||||
"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
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"date": {
|
||||
"name": "date",
|
||||
"type": "text",
|
||||
"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
|
||||
},
|
||||
"icon": {
|
||||
"name": "icon",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"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": {}
|
||||
}
|
||||
}
|
|
@ -78,6 +78,13 @@
|
|||
"when": 1712842196443,
|
||||
"tag": "0010_lean_gamma_corps",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 11,
|
||||
"version": "5",
|
||||
"when": 1712873663208,
|
||||
"tag": "0011_heavy_ben_urich",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
|
@ -16,6 +16,8 @@ export const featuredAdventures = pgTable("featuredAdventures", {
|
|||
export const sharedAdventures = pgTable("sharedAdventures", {
|
||||
id: text("id").primaryKey(),
|
||||
data: json("data").notNull(),
|
||||
name: text("name").notNull(),
|
||||
date: text("date").notNull(),
|
||||
});
|
||||
|
||||
export const userTable = pgTable("user", {
|
||||
|
|
|
@ -2,13 +2,15 @@ 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 }) {
|
||||
export async function POST({ request, locals }) {
|
||||
const { key, data } = await request.json();
|
||||
let adventure = data as Adventure;
|
||||
console.log(adventure);
|
||||
let date = new Date().toISOString().split("T")[0];
|
||||
let name = locals.user ? locals.user.username : "Anonymous";
|
||||
await db
|
||||
.insert(sharedAdventures)
|
||||
.values({ id: key, data: adventure })
|
||||
.values({ id: key, data: adventure, name:name, date:date })
|
||||
.execute();
|
||||
return new Response(JSON.stringify({ key: key }));
|
||||
}
|
|
@ -29,9 +29,14 @@ export async function load({ params }) {
|
|||
} as Adventure;
|
||||
});
|
||||
|
||||
let name = rawData.name;
|
||||
let date = rawData.date;
|
||||
|
||||
|
||||
// Return the array of Adventure objects
|
||||
return {
|
||||
adventureArray,
|
||||
name,
|
||||
date,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
</div>
|
||||
{/each} -->
|
||||
<h1 class="text-center font-bold text-4xl">Shared Adventure List</h1>
|
||||
<h2 class="text-center text-2xl">By {data.name} on {data.date}</h2>
|
||||
<div
|
||||
class="grid xl:grid-cols-3 lg:grid-cols-3 md:grid-cols-2 sm:grid-cols-1 gap-4 mt-4 content-center auto-cols-auto ml-6 mr-6"
|
||||
>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue