This video is available to students only

School Lunch Data Model

School Lunch Data Model

Data Model#

It's time to go deeper into our application's data model. The purpose of our application is to allow registered users to create and publish a weekly school lunch menu. We will use a lunchWeek entity that will have a list of lunchDay child entities for each school day of the week.

In the lunchWeek entity, we have the following properties:

  • (int) lunchWeekId: The primary key of the lunch week entity (more on this later)

  • (date) weekOf: The start date of the school week, e.g. 2020-01-01

  • (bool) isPublished: Whether or not the week is published for public users to see

  • (array) lunchDays: A list of child lunchDay objects

Then for the lunchDay entity, we have these properties:

  • (int) lunchDayId: The primary key of the lunch day entity

  • (int) lunchWeekId: Foreign key to the parent lunch week entity

  • (date) day: The date of the given lunch day

  • (string) menuDetails: The details of the daily lunch menu

Here's a representative JavaScript object example putting it all together:

Our menuDetails property is just a single string. We may discover later on that we need more properties to subdivide or organize the menuDetails such as keeping the entree and side items in separate properties. For now, we'll keep things simple and defer that decision until later.

The Lunch-Week Route#

The next thing we will tackle is creating the lunch-week route in Express so that we can create-read-update-delete (CRUD) data about lunch weeks.

Start off by creating a new file called lunch-week.js in the routes directory. Go ahead and stub out a GET endpoint.

Then, we need to import the route into app.js and apply it to the Express middleware. Update app.js with the router code:

After updating app.js, make sure the local Express environment is running and test the http://localhost:3000/lunch-week/ route in your browser. You should see the message "lunch week data".


We are going to hard-code a JSON response, just for now. Hard-coding the data obviously won't work for production, but it will help us learn the overall concepts faster. The GET /lunch-week endpoint will return a list of lunchWeek objects.

Add a lunchWeekList object to the lunch-week file and update the get endpoint to return the object. We've defined the object list separately from the endpoint so that we can access it from multiple routes:


This page is a preview of Fullstack Svelte

Start a new discussion. All notification go to the author.