From 01865951ac29cc8d64ef1aad1f589715761901aa Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Mon, 6 May 2024 23:13:32 +0000 Subject: [PATCH 1/5] Added new trip plan creator and removed visit count stores --- Dockerfile | 2 - migrations/0000_grey_iron_monger.sql | 119 +++++ migrations/meta/0000_snapshot.json | 511 ++++++++++++++++++++ migrations/meta/_journal.json | 13 + src/lib/components/CreateNewTripPlan.svelte | 105 ++++ src/lib/components/Navbar copy.svelte | 169 ------- src/lib/components/Navbar.svelte | 15 - src/lib/db/schema.ts | 8 +- src/lib/utils/stores/visitCountStore.ts | 5 - src/lib/utils/types.ts | 9 + src/routes/+page.svelte | 177 +------ src/routes/api/trips/+server.ts | 94 ++++ src/routes/api/userinfo/+server.ts | 39 -- src/routes/api/visitcount/+server.ts | 34 -- src/routes/featured/+page.svelte | 8 - src/routes/log/+page.svelte | 7 - src/routes/planner/+page.svelte | 138 ++++-- src/services/adventureService.ts | 11 - startup.sh | 25 - 19 files changed, 967 insertions(+), 522 deletions(-) create mode 100644 migrations/0000_grey_iron_monger.sql create mode 100644 migrations/meta/0000_snapshot.json create mode 100644 migrations/meta/_journal.json create mode 100644 src/lib/components/CreateNewTripPlan.svelte delete mode 100644 src/lib/components/Navbar copy.svelte delete mode 100644 src/lib/utils/stores/visitCountStore.ts create mode 100644 src/routes/api/trips/+server.ts delete mode 100644 src/routes/api/userinfo/+server.ts delete mode 100644 src/routes/api/visitcount/+server.ts diff --git a/Dockerfile b/Dockerfile index a9d97fa..97eb7d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,6 @@ FROM node:18-alpine AS external-website # A small line inside the image to show who made it LABEL Developers="Sean Morley" -RUN apk update && apk add postgresql-client - # The WORKDIR instruction sets the working directory for everything that will happen next WORKDIR /app diff --git a/migrations/0000_grey_iron_monger.sql b/migrations/0000_grey_iron_monger.sql new file mode 100644 index 0000000..3b22ce0 --- /dev/null +++ b/migrations/0000_grey_iron_monger.sql @@ -0,0 +1,119 @@ +CREATE TABLE IF NOT EXISTS "adventures" ( + "id" serial PRIMARY KEY NOT NULL, + "type" text NOT NULL, + "userId" text, + "name" text NOT NULL, + "location" text, + "activityTypes" json, + "description" text, + "rating" integer, + "link" text, + "imageUrl" text, + "date" text +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "featuredAdventures" ( + "id" serial PRIMARY KEY NOT NULL, + "name" text NOT NULL, + "location" text, + CONSTRAINT "featuredAdventures_name_unique" UNIQUE("name") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "session" ( + "id" text PRIMARY KEY NOT NULL, + "user_id" text NOT NULL, + "expires_at" timestamp with time zone NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "sharedAdventures" ( + "id" text PRIMARY KEY NOT NULL, + "data" json NOT NULL, + "name" text NOT NULL, + "date" text NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "userPlannedTrips" ( + "id" serial PRIMARY KEY NOT NULL, + "userId" text NOT NULL, + "adventureName" text NOT NULL, + "description" text, + "startDate" text, + "endDate" text, + "adventures" json +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "user" ( + "id" text PRIMARY KEY NOT NULL, + "username" text NOT NULL, + "first_name" text NOT NULL, + "last_name" text NOT NULL, + "icon" text, + "hashed_password" varchar NOT NULL, + "signup_date" timestamp with time zone NOT NULL, + "last_login" timestamp with time zone, + "role" text NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "userVisitedWorldTravel" ( + "id" serial PRIMARY KEY NOT NULL, + "country_code" text NOT NULL, + "user_id" text NOT NULL, + "region_id" varchar NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "worldTravelCountries" ( + "id" serial PRIMARY KEY NOT NULL, + "name" text NOT NULL, + "country_code" text NOT NULL, + "continent" text NOT NULL, + CONSTRAINT "worldTravelCountries_country_code_unique" UNIQUE("country_code") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "worldTravelCountryRegions" ( + "id" varchar PRIMARY KEY NOT NULL, + "name" text NOT NULL, + "country_code" text NOT NULL, + "info" json +); +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "adventures" ADD CONSTRAINT "adventures_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "session" ADD CONSTRAINT "session_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "userPlannedTrips" ADD CONSTRAINT "userPlannedTrips_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "userVisitedWorldTravel" ADD CONSTRAINT "userVisitedWorldTravel_country_code_worldTravelCountries_country_code_fk" FOREIGN KEY ("country_code") REFERENCES "worldTravelCountries"("country_code") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "userVisitedWorldTravel" ADD CONSTRAINT "userVisitedWorldTravel_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "userVisitedWorldTravel" ADD CONSTRAINT "userVisitedWorldTravel_region_id_worldTravelCountryRegions_id_fk" FOREIGN KEY ("region_id") REFERENCES "worldTravelCountryRegions"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "worldTravelCountryRegions" ADD CONSTRAINT "worldTravelCountryRegions_country_code_worldTravelCountries_country_code_fk" FOREIGN KEY ("country_code") REFERENCES "worldTravelCountries"("country_code") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; diff --git a/migrations/meta/0000_snapshot.json b/migrations/meta/0000_snapshot.json new file mode 100644 index 0000000..c5f36b4 --- /dev/null +++ b/migrations/meta/0000_snapshot.json @@ -0,0 +1,511 @@ +{ + "id": "7cce94bb-5a17-42ff-850f-e0a41834b739", + "prevId": "00000000-0000-0000-0000-000000000000", + "version": "5", + "dialect": "pg", + "tables": { + "adventures": { + "name": "adventures", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "location": { + "name": "location", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "activityTypes": { + "name": "activityTypes", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rating": { + "name": "rating", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "link": { + "name": "link", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "imageUrl": { + "name": "imageUrl", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "adventures_userId_user_id_fk": { + "name": "adventures_userId_user_id_fk", + "tableFrom": "adventures", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "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": { + "featuredAdventures_name_unique": { + "name": "featuredAdventures_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + } + }, + "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": {} + }, + "userPlannedTrips": { + "name": "userPlannedTrips", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "adventureName": { + "name": "adventureName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "startDate": { + "name": "startDate", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "endDate": { + "name": "endDate", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "adventures": { + "name": "adventures", + "type": "json", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "userPlannedTrips_userId_user_id_fk": { + "name": "userPlannedTrips_userId_user_id_fk", + "tableFrom": "userPlannedTrips", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "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 + }, + "signup_date": { + "name": "signup_date", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "last_login": { + "name": "last_login", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "userVisitedWorldTravel": { + "name": "userVisitedWorldTravel", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "country_code": { + "name": "country_code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "region_id": { + "name": "region_id", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "userVisitedWorldTravel_country_code_worldTravelCountries_country_code_fk": { + "name": "userVisitedWorldTravel_country_code_worldTravelCountries_country_code_fk", + "tableFrom": "userVisitedWorldTravel", + "tableTo": "worldTravelCountries", + "columnsFrom": [ + "country_code" + ], + "columnsTo": [ + "country_code" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "userVisitedWorldTravel_user_id_user_id_fk": { + "name": "userVisitedWorldTravel_user_id_user_id_fk", + "tableFrom": "userVisitedWorldTravel", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "userVisitedWorldTravel_region_id_worldTravelCountryRegions_id_fk": { + "name": "userVisitedWorldTravel_region_id_worldTravelCountryRegions_id_fk", + "tableFrom": "userVisitedWorldTravel", + "tableTo": "worldTravelCountryRegions", + "columnsFrom": [ + "region_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "worldTravelCountries": { + "name": "worldTravelCountries", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "country_code": { + "name": "country_code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "continent": { + "name": "continent", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "worldTravelCountries_country_code_unique": { + "name": "worldTravelCountries_country_code_unique", + "nullsNotDistinct": false, + "columns": [ + "country_code" + ] + } + } + }, + "worldTravelCountryRegions": { + "name": "worldTravelCountryRegions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "country_code": { + "name": "country_code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "info": { + "name": "info", + "type": "json", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "worldTravelCountryRegions_country_code_worldTravelCountries_country_code_fk": { + "name": "worldTravelCountryRegions_country_code_worldTravelCountries_country_code_fk", + "tableFrom": "worldTravelCountryRegions", + "tableTo": "worldTravelCountries", + "columnsFrom": [ + "country_code" + ], + "columnsTo": [ + "country_code" + ], + "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 new file mode 100644 index 0000000..99c9da5 --- /dev/null +++ b/migrations/meta/_journal.json @@ -0,0 +1,13 @@ +{ + "version": "5", + "dialect": "pg", + "entries": [ + { + "idx": 0, + "version": "5", + "when": 1715035790035, + "tag": "0000_grey_iron_monger", + "breakpoints": true + } + ] +} \ No newline at end of file diff --git a/src/lib/components/CreateNewTripPlan.svelte b/src/lib/components/CreateNewTripPlan.svelte new file mode 100644 index 0000000..b40dc3b --- /dev/null +++ b/src/lib/components/CreateNewTripPlan.svelte @@ -0,0 +1,105 @@ + + + + + + + diff --git a/src/lib/components/Navbar copy.svelte b/src/lib/components/Navbar copy.svelte deleted file mode 100644 index 7efe33f..0000000 --- a/src/lib/components/Navbar copy.svelte +++ /dev/null @@ -1,169 +0,0 @@ - - - diff --git a/src/lib/components/Navbar.svelte b/src/lib/components/Navbar.svelte index 3bdea98..dd419a1 100644 --- a/src/lib/components/Navbar.svelte +++ b/src/lib/components/Navbar.svelte @@ -1,6 +1,5 @@ diff --git a/src/routes/log/+page.svelte b/src/routes/log/+page.svelte index 1326ead..a33eb3a 100644 --- a/src/routes/log/+page.svelte +++ b/src/routes/log/+page.svelte @@ -13,7 +13,6 @@ import mapDrawing from "$lib/assets/adventure_map.svg"; import EditModal from "$lib/components/EditModal.svelte"; import { generateRandomString } from "$lib"; - import { visitCount } from "$lib/utils/stores/visitCountStore"; import MoreFieldsInput from "$lib/components/CreateNewAdventure.svelte"; import { addAdventure, @@ -36,11 +35,6 @@ isLoading = false; }); - let count = 0; - visitCount.subscribe((value) => { - count = value; - }); - function showToast(action: string) { toastAction = action; isShowingToast = true; @@ -141,7 +135,6 @@ // remove adventure from array where id matches adventures = []; showToast("Adventure removed successfully!"); - visitCount.set(0); }) .catch((error) => { console.error("Error:", error); diff --git a/src/routes/planner/+page.svelte b/src/routes/planner/+page.svelte index 409f3d1..2c7b37d 100644 --- a/src/routes/planner/+page.svelte +++ b/src/routes/planner/+page.svelte @@ -1,5 +1,5 @@ {#if isShowingToast} {/if} -
-
-

Add new Plan

-
+
+
+ +
-
- -
-{#if plans.length != 0} +{#if adventuresPlans.length != 0}
-

My Adventure Plans

+

My Adventure Ideas

{/if} @@ -138,7 +181,7 @@
- {#each plans as adventure (adventure.id)} + {#each adventuresPlans as adventure (adventure.id)} -{#if plans.length == 0 && !isLoading} +{#if adventuresPlans.length == 0 && !isLoading}

Add some plans!

Logo @@ -168,6 +211,35 @@ /> {/if} +{#if isShowingNewTrip} + (isShowingNewTrip = false)} + on:create={createNewTrip} + /> +{/if} + +{#if tripPlans.length !== 0} +
+
+

My Trip Plans

+
+
+{/if} + +{#each tripPlans as trip (trip.id)} +
+
+

{trip.name}

+

{trip.description}

+

+ Start Date: + {trip.startDate} End Date: + {trip.endDate} +

+
+
+{/each} + - - - My Plans | AdventureLog Date: Sat, 11 May 2024 01:06:43 +0000 Subject: [PATCH 4/5] Move add button location for log page --- src/routes/log/+page.svelte | 38 +++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/routes/log/+page.svelte b/src/routes/log/+page.svelte index a33eb3a..b5a1cdd 100644 --- a/src/routes/log/+page.svelte +++ b/src/routes/log/+page.svelte @@ -158,20 +158,30 @@ } -
-
-

Add new Location

-
-
- -
- +
+
+ +
{#if adventures.length != 0}
From 1ccf582b85b57c53373b49d14acea57392c0aed4 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Mon, 13 May 2024 21:29:23 +0000 Subject: [PATCH 5/5] chore: Update login and signup pages with background images --- src/routes/login/+page.svelte | 77 ++++++++++++++++------------- src/routes/signup/+page.svelte | 90 +++++++++++++++++++--------------- 2 files changed, 93 insertions(+), 74 deletions(-) diff --git a/src/routes/login/+page.svelte b/src/routes/login/+page.svelte index d44c956..04e851e 100644 --- a/src/routes/login/+page.svelte +++ b/src/routes/login/+page.svelte @@ -1,4 +1,3 @@ - -
-

Sign in

-
+
+
+
+

Sign in

+
-
-
- -
- -
- -
-
+
+
+ +
+ +
+ +
+
-{#if errors.message} -
- {errors.message} -
-{/if} - -
-
- {#if quote != ""} - {quote} + {#if errors.message} +
+ {errors.message} +
{/if} - -
+ +
+
+ {#if quote != ""} + {quote} + {/if} + +
+
+
diff --git a/src/routes/signup/+page.svelte b/src/routes/signup/+page.svelte index c3cfdc0..f650350 100644 --- a/src/routes/signup/+page.svelte +++ b/src/routes/signup/+page.svelte @@ -3,54 +3,64 @@ import { enhance } from "$app/forms"; import { getRandomQuote } from "$lib"; import { onMount } from "svelte"; + + let backgroundImageUrl = "https://source.unsplash.com/random/?mountains"; + let quote: string = ""; onMount(async () => { quote = getRandomQuote(); }); -
-

Signup

-
+
+
+
+

Signup

+
-
-
- -
- -
- -
- -
- -
-
+
+
+ +
+ +
+ +
+ +
+ +
+
-
-
- {#if quote != ""} - {quote} - {/if} - -
+
+
+ {#if quote != ""} + {quote} + {/if} + +
+
+