Add beer post, brewery post GET service and page

Add prettier, eslint config
This commit is contained in:
Aaron William Po
2023-01-22 20:56:33 -05:00
parent a434e1bb98
commit 0065525f5c
29 changed files with 8696 additions and 6977 deletions

26
pages/breweries/[id].tsx Normal file
View File

@@ -0,0 +1,26 @@
import { GetServerSideProps, NextPage } from 'next';
import BeerPostQueryResult from '@/services/BeerPost/types/BeerPostQueryResult';
import getBreweryPostById from '@/services/BreweryPost/getBreweryPostById';
interface BreweryPageProps {
breweryPost: BeerPostQueryResult;
}
const BreweryByIdPage: NextPage<BreweryPageProps> = ({ breweryPost }) => {
return (
<>
<h1 className="text-3xl font-bold underline">{breweryPost.name}</h1>
</>
);
};
export const getServerSideProps: GetServerSideProps<BreweryPageProps> = async (
context,
) => {
const breweryPost = await getBreweryPostById(context.params!.id! as string);
return !breweryPost
? { notFound: true }
: { props: { breweryPost: JSON.parse(JSON.stringify(breweryPost)) } };
};
export default BreweryByIdPage;

35
pages/breweries/index.tsx Normal file
View File

@@ -0,0 +1,35 @@
import { GetServerSideProps, NextPage } from 'next';
import Link from 'next/link';
import getAllBreweryPosts from '@/services/BreweryPost/getAllBreweryPosts';
import GetAllBreweryPostsQueryResult from '@/services/BreweryPost/types/BreweryPostQueryResult';
interface BreweryPageProps {
breweryPosts: GetAllBreweryPostsQueryResult[];
}
const BreweryPage: NextPage<BreweryPageProps> = ({ breweryPosts }) => {
return (
<>
<h1 className="text-3xl font-bold underline">Brewery Posts</h1>
{breweryPosts.map((post) => {
return (
<div key={post.id}>
<h2>
<Link href={`/breweries/${post.id}`}>{post.name}</Link>
</h2>
</div>
);
})}
</>
);
};
export const getServerSideProps: GetServerSideProps<BreweryPageProps> = async () => {
const breweryPosts = await getAllBreweryPosts();
return {
props: { breweryPosts: JSON.parse(JSON.stringify(breweryPosts)) },
};
};
export default BreweryPage;