From a550fd58f76760229c842f061272597ffadf0f07 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Sun, 14 Apr 2024 20:33:58 +0000 Subject: [PATCH] Update AdventureCard component to include regionId and visited properties, and add country flag support --- migrations/0002_far_mephistopheles.sql | 1 + migrations/meta/0002_snapshot.json | 391 ++++++++++++++++++ migrations/meta/_journal.json | 7 + sql/002_us.sql | 54 ++- src/lib/components/AdventureCard.svelte | 7 + src/lib/db/schema.ts | 1 + src/lib/utils/types.ts | 33 ++ .../worldtravel/[countrycode]/+page.svelte | 1 + .../[regioncode]/+page.server.ts | 34 ++ .../[countrycode]/[regioncode]/+page.svelte | 20 + 10 files changed, 548 insertions(+), 1 deletion(-) create mode 100644 migrations/0002_far_mephistopheles.sql create mode 100644 migrations/meta/0002_snapshot.json create mode 100644 src/routes/worldtravel/[countrycode]/[regioncode]/+page.server.ts create mode 100644 src/routes/worldtravel/[countrycode]/[regioncode]/+page.svelte diff --git a/migrations/0002_far_mephistopheles.sql b/migrations/0002_far_mephistopheles.sql new file mode 100644 index 00000000..5a0139a4 --- /dev/null +++ b/migrations/0002_far_mephistopheles.sql @@ -0,0 +1 @@ +ALTER TABLE "worldTravelCountryRegions" ADD COLUMN "info" json; \ 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 00000000..f84336c7 --- /dev/null +++ b/migrations/meta/0002_snapshot.json @@ -0,0 +1,391 @@ +{ + "id": "91692e84-91ec-4411-ad9d-7b8b14f67dda", + "prevId": "4c095e1a-9f13-4899-aa83-f56864191f51", + "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": { + "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": {} + }, + "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": {} + }, + "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 index 66fa8260..12ecd457 100644 --- a/migrations/meta/_journal.json +++ b/migrations/meta/_journal.json @@ -15,6 +15,13 @@ "when": 1713050481064, "tag": "0001_closed_wendell_vaughn", "breakpoints": true + }, + { + "idx": 2, + "version": "5", + "when": 1713125110816, + "tag": "0002_far_mephistopheles", + "breakpoints": true } ] } \ No newline at end of file diff --git a/sql/002_us.sql b/sql/002_us.sql index aef770c4..1ae55467 100644 --- a/sql/002_us.sql +++ b/sql/002_us.sql @@ -1,6 +1,58 @@ INSERT INTO "worldTravelCountryRegions" (id, name, country_code) VALUES - ('US-AL', 'Alabama', 'us'), + ('US-AL', 'Alabama', 'us', '{ + "name": "Alabama", + "abbreviation": "AL", + "description": "Alabama is a state located in the southeastern region of the United States. Known for its rich history, including its role in the American Civil War and the Civil Rights Movement, Alabama offers a diverse landscape of mountains, plains, and coastal areas. The state boasts a humid subtropical climate and is known for its strong tradition in college sports, particularly football. Alabama's economy is diverse, with major industries including automotive manufacturing, agriculture, and aerospace. Tourists are drawn to Alabama's natural beauty, historical sites, and cultural landmarks.", + "capital": "Montgomery", + "largest_city": "Birmingham", + "area": { + "total": 52420, + "units": "square miles" + }, + "population": { + "estimate": 4903185, + "year": 2020 + }, + "state_flower": "Camellia", + "state_bird": "Yellowhammer", + "state_tree": "Southern Longleaf Pine", + "climate": { + "description": "Humid subtropical", + "summer_highs": "80-90°F", + "winter_lows": "30-50°F", + "precipitation": "Abundant throughout the year" + }, + "economy": { + "industries": [ + "Automotive Manufacturing", + "Agriculture", + "Mining", + "Technology", + "Aerospace" + ], + "agricultural_products": [ + "Poultry", + "Cotton", + "Peanuts", + "Soybeans", + "Corn" + ] + }, + "tourism": { + "attractions": [ + "U.S. Space & Rocket Center", + "Gulf Shores and Orange Beach", + "Rosa Parks Museum", + "Civil Rights Institute", + "Little River Canyon National Preserve" + ] + }, + "major_sports_teams": [ + "Alabama Crimson Tide (NCAA)", + "Auburn Tigers (NCAA)" + ] +}'), ('US-AK', 'Alaska', 'us'), ('US-AZ', 'Arizona', 'us'), ('US-AR', 'Arkansas', 'us'), diff --git a/src/lib/components/AdventureCard.svelte b/src/lib/components/AdventureCard.svelte index c88d2532..5ed4e824 100644 --- a/src/lib/components/AdventureCard.svelte +++ b/src/lib/components/AdventureCard.svelte @@ -2,6 +2,7 @@ import { createEventDispatcher } from "svelte"; import locationDot from "$lib/assets/locationDot.svg"; import calendar from "$lib/assets/calendar.svg"; + import { goto } from "$app/navigation"; const dispatch = createEventDispatcher(); export let type: String; @@ -12,6 +13,7 @@ export let id: Number | undefined = undefined; export let regionId: String | undefined = undefined; export let visited: Boolean | undefined = undefined; + export let countryCode: String | undefined = undefined; function remove() { dispatch("remove", id); @@ -30,6 +32,10 @@ dispatch("removeVisit", regionId); visited = false; } + + function moreInfo() { + goto(`/worldtravel/${countryCode}/${regionId}`); + } {#if type === "mylog"} @@ -122,6 +128,7 @@

{name}

{regionId}

+ {#if !visited} worldTravelCountries.country_code), + info: json("info"), }); export const userVisitedWorldTravel = pgTable("userVisitedWorldTravel", { diff --git a/src/lib/utils/types.ts b/src/lib/utils/types.ts index 39cb486f..645621ce 100644 --- a/src/lib/utils/types.ts +++ b/src/lib/utils/types.ts @@ -4,3 +4,36 @@ export interface Adventure { location: string; created: string; } + +export interface RegionInfo { + name: string; + abbreviation: string; + description: string; + capital: string; + largest_city: string; + area: { + total: number; + units: string; + }; + population: { + estimate: number; + year: number; + }; + state_flower: string; + state_bird: string; + state_tree: string; + climate: { + description: string; + summer_highs: string; + winter_lows: string; + precipitation: string; + }; + economy: { + industries: string[]; + agricultural_products: string[]; + }; + tourism: { + attractions: string[]; + }; + major_sports_teams: string[]; +}; diff --git a/src/routes/worldtravel/[countrycode]/+page.svelte b/src/routes/worldtravel/[countrycode]/+page.svelte index bbafcdcb..9c4ff20f 100644 --- a/src/routes/worldtravel/[countrycode]/+page.svelte +++ b/src/routes/worldtravel/[countrycode]/+page.svelte @@ -89,6 +89,7 @@ {#each data.regions as region (region.id)} { + const { regioncode } = params; + + let info = await db + .select({data: worldTravelCountryRegions}) + .from(worldTravelCountryRegions) + .where(eq(worldTravelCountryRegions.id, regioncode)) + .limit(1) + .execute(); + + let visited = false; + if (locals.user) { + let userVisited = await db + .select({data: userVisitedWorldTravel}) + .from(userVisitedWorldTravel) + .where(and(eq(userVisitedWorldTravel.userId, locals.user.id), eq(userVisitedWorldTravel.region_id, regioncode))) + .limit(1) + .execute(); + if (userVisited.length !== 0) { + visited = true; + } + } + + return { + info : info[0], + visited : visited, + }; +} \ No newline at end of file diff --git a/src/routes/worldtravel/[countrycode]/[regioncode]/+page.svelte b/src/routes/worldtravel/[countrycode]/[regioncode]/+page.svelte new file mode 100644 index 00000000..ead9b7b0 --- /dev/null +++ b/src/routes/worldtravel/[countrycode]/[regioncode]/+page.svelte @@ -0,0 +1,20 @@ + + +

Info About {regionName} in {country}

+{#if visited} +

You have visited this region!

+{/if} + +

Region Info

+{#if info.description} +

{info.description}

+{/if}