Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Setup structure for simple three-tier architecture #42

Merged
merged 7 commits into from
Aug 16, 2024

Conversation

DafyddLlyr
Copy link
Contributor

What does this PR do?

Lets try to talk this through early in the week, and I'll hand over to you guys to complete the process 👍

Copy link

vercel bot commented Aug 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fairhold-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 16, 2024 9:47am

Comment on lines +11 to +12
const householdData = await calculationService.getHouseholdData(input);
return NextResponse.json(householdData);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This POST() function is now much simpler, we only care about handing HTTP input and output etc.

@@ -0,0 +1,28 @@
import prisma from "./db";

const getItl3ByPostcodeDistrict = async (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this "layer" we're only concerned about fetching data from the DB, and handing the correct value to consumers.


const prisma = new PrismaClient();

export const getHouseholdData = async (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously - a lot still to be done here, but this is where "business logic" can live. We get parsed and validated input handed across, and we can interact with other services to get the data we need.

@@ -0,0 +1,9 @@
import { gdhiRepo } from "../data/gdhiRepo";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these very simple functions, I appreciate that setting up a whole "layer" may seem redundant, but as complexity and requirements grow it's nice to have a single place to fetch all data from.

We'll see this more clearly once we start splitting up the postcode fallthrough logic 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have missed something obvious here, but why do we want separate "layers" for gdhiRepo and itlRepo and not for other tables in the database?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scratch that, I now understand after having seen the relevant Project card.

@DafyddLlyr DafyddLlyr requested review from a team and removed request for a team August 3, 2024 11:29
@gabrielegranello
Copy link
Collaborator

This looks great to me @DafyddLlyr . Also thank you very much for explaining the logic step by step, super appreciated. I think @zz-hh-aa will also find a lot of value in reading this PR, so maybe they can approve it after reading it if that's ok with you

@@ -0,0 +1,15 @@
import { PrismaClient } from "@prisma/client";

const prismaClientSingleton = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was reading about the Singleton pattern 'cause I hadn't encountered it before--to ensure that the client is truly only created once, would we need some sort of if-then check here to only instantiate if there is no PrismaClient currently in existence?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that's exactly correct 🙌

This is happening below on line 11 - when we import prisma we check if one exists, or instantiate a new one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I missed that--still getting used to the reviews GUI 😅 thanks!

@@ -0,0 +1,9 @@
import { gdhiRepo } from "../data/gdhiRepo";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have missed something obvious here, but why do we want separate "layers" for gdhiRepo and itlRepo and not for other tables in the database?

@DafyddLlyr DafyddLlyr force-pushed the dp/remove-prisma-queryRaw branch from 427405c to 398812b Compare August 16, 2024 09:38
Base automatically changed from dp/remove-prisma-queryRaw to main August 16, 2024 09:39
@@ -0,0 +1,15 @@
import { PrismaClient } from "@prisma/client";

const prismaClientSingleton = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I missed that--still getting used to the reviews GUI 😅 thanks!

@DafyddLlyr DafyddLlyr merged commit 526b938 into main Aug 16, 2024
3 checks passed
@DafyddLlyr DafyddLlyr deleted the dp/three-tier branch August 16, 2024 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants