From a604a24fd18e73b6472c9afd8f78b1e8f16addd2 Mon Sep 17 00:00:00 2001 From: Aaron William Po Date: Fri, 22 Sep 2023 22:52:51 -0400 Subject: [PATCH] Update: more work on beer styles, add erd to readme --- README.md | 4 + schema.svg | 2086 +++++++++++++++++ src/components/BeerStyle/BeerStyleCard.tsx | 35 +- src/components/ui/SmLoadingCard.tsx | 23 + src/pages/beers/styles/index.tsx | 15 +- src/services/BeerStyles/getAllBeerStyles.ts | 2 + .../BeerStyles/schema/BeerStyleQueryResult.ts | 13 +- 7 files changed, 2152 insertions(+), 26 deletions(-) create mode 100644 schema.svg create mode 100644 src/components/ui/SmLoadingCard.tsx diff --git a/README.md b/README.md index 949c5ee..ace2c15 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,10 @@ scale, or IBU, is used to approximately quantify the bitterness of beer. This sc measured on the perceived bitterness of the beer, but rather the amount of a component of beer known as iso-alpha acids. +## Database Schema + +![Schema](./schema.svg) + ## Technologies ### General diff --git a/schema.svg b/schema.svg new file mode 100644 index 0000000..d32df12 --- /dev/null +++ b/schema.svg @@ -0,0 +1,2086 @@ + + + + + + 1 + + * + + + + + 1 + + * + + + + + * + + 1 + + + + + 1 + + * + + + + + 1 + + * + + + + + 1 + + * + + + + + 1 + + * + + + + + * + + 1 + + + + + * + + 1 + + + + + 1 + + * + + + + + * + + 1 + + + + + 1 + + * + + + + + 1 + + * + + + + + 1 + + 1 + + + + + * + + 1 + + + + + 1 + + * + + + + + 1 + + * + + + + + 1 + + * + + + + + 1 + + * + + + + + 1 + + * + + + + + 1 + + * + + + + + User + + + + + id + + + String + + + + + username + + + + String + + + + + firstName + + + + String + + + + + lastName + + + + String + + + + hash + + + + String + + + + email + + + + String + + + + + createdAt + + + + + DateTime + + + + + updatedAt + + DateTime + + + + + accountIsVerified + + + + Boolean + + + + + dateOfBirth + + + + + DateTime + + + + + beerPosts + + + + + BeerPost + + + + + beerStyles + + + + + BeerStyle + + + + + breweryPosts + + + + + BreweryPost + + + + + beerComments + + + + + BeerComment + + + + + breweryComments + + + + + BreweryComment + + + + + BeerPostLikes + + + + + BeerPostLike + + + + + BeerImage + + + + + BeerImage + + + + + BreweryImage + + + + + BreweryImage + + + + + BreweryPostLike + + + + + BreweryPostLike + + + + + Location + + + + + Location + + + + + Glassware + + + + + Glassware + + + + + BeerPost + + + + + id + + + String + + + + name + + + + String + + + + ibu + + + + Float + + + + abv + + + + Float + + + + + description + + + + String + + + + + postedBy + + + + User + + + + + postedById + + + + String + + + + brewery + + + + + BreweryPost + + + + + breweryId + + + + String + + + + style + + + + + BeerStyle + + + + styleId + + + + String + + + + + createdAt + + + + + DateTime + + + + + updatedAt + + DateTime + + + + + beerComments + + + + + BeerComment + + + + + beerImages + + + + + BeerImage + + + + + BeerPostLikes + + + + + BeerPostLike + + + + + BeerPostLike + + + + + id + + + String + + + + + beerPost + + + + + BeerPost + + + + + beerPostId + + + + String + + + + likedBy + + + + User + + + + + likedById + + + + String + + + + + createdAt + + + + + DateTime + + + + + updatedAt + + DateTime + + + + + BreweryPostLike + + + + + id + + + String + + + + + breweryPost + + + + + BreweryPost + + + + + breweryPostId + + + + String + + + + likedBy + + + + User + + + + + likedById + + + + String + + + + + createdAt + + + + + DateTime + + + + + updatedAt + + DateTime + + + + + BeerComment + + + + + id + + + String + + + + rating + + + + Int + + + + + beerPost + + + + + BeerPost + + + + + beerPostId + + + + String + + + + + postedBy + + + + User + + + + + postedById + + + + String + + + + content + + + + String + + + + + createdAt + + + + + DateTime + + + + + updatedAt + + DateTime + + + + + BeerStyle + + + + + id + + + String + + + + name + + + + String + + + + + description + + + + String + + + + + createdAt + + + + + DateTime + + + + + updatedAt + + DateTime + + + + + postedBy + + + + User + + + + + glassware + + + + + Glassware + + + + + glasswareId + + + + String + + + + + postedById + + + + String + + + + + abvRange + + + + Float[] + + + + + ibuRange + + + + Float[] + + + + + beerPosts + + + + + BeerPost + + + + + Glassware + + + + + id + + + String + + + + name + + + + String + + + + + description + + + + String + + + + + createdAt + + + + + DateTime + + + + + updatedAt + + DateTime + + + + + postedBy + + + + User + + + + + postedById + + + + String + + + + + BeerStyle + + + + + BeerStyle + + + + + Location + + + + + id + + + String + + + + city + + + + String + + + + + stateOrProvince + String + + + + country + String + + + + + coordinates + + + + Float[] + + + + address + + + + String + + + + + postedBy + + + + User + + + + + postedById + + + + String + + + + + BreweryPost + + BreweryPost + + + + + createdAt + + + + + DateTime + + + + + updatedAt + + DateTime + + + + + BreweryPost + + + + + id + + + String + + + + name + + + + String + + + + + location + + + + + Location + + + + + locationId + + + + String + + + + beers + + + + + BeerPost + + + + + description + + + + String + + + + + createdAt + + + + + DateTime + + + + + updatedAt + + DateTime + + + + + postedBy + + + + User + + + + + postedById + + + + String + + + + + breweryComments + + + + + BreweryComment + + + + + breweryImages + + + + + BreweryImage + + + + + breweryPostLike + + + + + BreweryPostLike + + + + + dateEstablished + + + + + DateTime + + + + + BreweryComment + + + + + id + + + String + + + + rating + + + + Int + + + + + breweryPost + + + + + BreweryPost + + + + + breweryPostId + + + + String + + + + + postedBy + + + + User + + + + + postedById + + + + String + + + + content + + + + String + + + + + createdAt + + + + + DateTime + + + + + updatedAt + + DateTime + + + + + BeerImage + + + + + id + + + String + + + + + beerPost + + + + + BeerPost + + + + + beerPostId + + + + String + + + + path + + + + String + + + + alt + + + + String + + + + caption + + + + String + + + + + createdAt + + + + + DateTime + + + + + updatedAt + + DateTime + + + + + postedBy + + + + User + + + + + postedById + + + + String + + + + + BreweryImage + + + + + id + + + String + + + + + breweryPost + + + + + BreweryPost + + + + + breweryPostId + + + + String + + + + path + + + + String + + + + + createdAt + + + + + DateTime + + + + + updatedAt + + DateTime + + + + caption + + + + String + + + + alt + + + + String + + + + + postedBy + + + + User + + + + + postedById + + + + String + + \ No newline at end of file diff --git a/src/components/BeerStyle/BeerStyleCard.tsx b/src/components/BeerStyle/BeerStyleCard.tsx index 2091648..4c265fb 100644 --- a/src/components/BeerStyle/BeerStyleCard.tsx +++ b/src/components/BeerStyle/BeerStyleCard.tsx @@ -8,24 +8,37 @@ const BeerStyleCard: FC<{ beerStyle: z.infer }> = ( beerStyle, }) => { return ( -
+

{beerStyle.name}

-
- ABV Range: {beerStyle.abvRange[0].toFixed(1)}% - - - {beerStyle.abvRange[1].toFixed(1)}% -
-
- IBU Range: {beerStyle.ibuRange[0].toFixed(1)} - - - {beerStyle.ibuRange[1].toFixed(1)} -
+
+
+ ABV Range:{' '} + + {beerStyle.abvRange[0].toFixed(1)}% - {beerStyle.abvRange[1].toFixed(1)}% + +
+
+ IBU Range:{' '} + + {beerStyle.ibuRange[0].toFixed(1)} - {beerStyle.ibuRange[1].toFixed(1)} + +
+
+ +
+

{beerStyle.description}

+
+ +
+ Recommended Glassware:{' '} + {beerStyle.glassware.name} +
diff --git a/src/components/ui/SmLoadingCard.tsx b/src/components/ui/SmLoadingCard.tsx new file mode 100644 index 0000000..6d42aa3 --- /dev/null +++ b/src/components/ui/SmLoadingCard.tsx @@ -0,0 +1,23 @@ +import { FC } from 'react'; + +const SMLoadingCard: FC = () => { + return ( +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ); +}; + +export default SMLoadingCard; diff --git a/src/pages/beers/styles/index.tsx b/src/pages/beers/styles/index.tsx index 9365bb3..a4bf4da 100644 --- a/src/pages/beers/styles/index.tsx +++ b/src/pages/beers/styles/index.tsx @@ -1,14 +1,14 @@ -import BeerStyleCard from '@/components/BeerStyle/BeerStyleCard'; -import LoadingCard from '@/components/ui/LoadingCard'; -import Spinner from '@/components/ui/Spinner'; -import useBeerStyles from '@/hooks/data-fetching/beer-styles/useBeerStyles'; - import { NextPage } from 'next'; import Head from 'next/head'; import { MutableRefObject, useRef } from 'react'; import { FaArrowUp } from 'react-icons/fa'; import { useInView } from 'react-intersection-observer'; +import BeerStyleCard from '@/components/BeerStyle/BeerStyleCard'; +import SmLoadingCard from '@/components/ui/SmLoadingCard'; +import Spinner from '@/components/ui/Spinner'; +import useBeerStyles from '@/hooks/data-fetching/beer-styles/useBeerStyles'; + const BeerStylePage: NextPage = () => { const PAGE_SIZE = 20; const pageRef: MutableRefObject = useRef(null); @@ -17,7 +17,6 @@ const BeerStylePage: NextPage = () => { pageSize: PAGE_SIZE, }); - // eslint-disable-next-line @typescript-eslint/no-unused-vars const { ref: lastBeerStyleRef } = useInView({ onChange: (visible) => { if (!visible || isAtEnd) return; @@ -28,7 +27,7 @@ const BeerStylePage: NextPage = () => { return ( <> - Beer Types | The Biergarten App + Beer Styles | The Biergarten App { {(isLoading || isLoadingMore) && ( <> {Array.from({ length: PAGE_SIZE }, (_, i) => ( - + ))} )} diff --git a/src/services/BeerStyles/getAllBeerStyles.ts b/src/services/BeerStyles/getAllBeerStyles.ts index 63dbd84..20d04f5 100644 --- a/src/services/BeerStyles/getAllBeerStyles.ts +++ b/src/services/BeerStyles/getAllBeerStyles.ts @@ -17,6 +17,8 @@ const getAllBeerStyles = async ( updatedAt: true, abvRange: true, ibuRange: true, + description: true, + glassware: { select: { id: true, name: true } }, }, })) as z.infer[]; diff --git a/src/services/BeerStyles/schema/BeerStyleQueryResult.ts b/src/services/BeerStyles/schema/BeerStyleQueryResult.ts index 924beb4..766f1ee 100644 --- a/src/services/BeerStyles/schema/BeerStyleQueryResult.ts +++ b/src/services/BeerStyles/schema/BeerStyleQueryResult.ts @@ -1,16 +1,15 @@ import { z } from 'zod'; const BeerStyleQueryResult = z.object({ + abvRange: z.tuple([z.number(), z.number()]), + createdAt: z.coerce.date(), + description: z.string(), + glassware: z.object({ id: z.string().cuid(), name: z.string() }), + ibuRange: z.tuple([z.number(), z.number()]), id: z.string().cuid(), name: z.string(), - postedBy: z.object({ - id: z.string().cuid(), - username: z.string(), - }), - createdAt: z.coerce.date(), + postedBy: z.object({ id: z.string().cuid(), username: z.string() }), updatedAt: z.coerce.date().nullable(), - abvRange: z.tuple([z.number(), z.number()]), - ibuRange: z.tuple([z.number(), z.number()]), }); export default BeerStyleQueryResult;