In this challenge, you design and build a Data Model and a RESTful API that stores data into a Relational Database.
Read these instructions carefully. Understand exactly what is expected before starting this Sprint Challenge.
This is an individual assessment, please work on it alone. It is an opportunity to demonstrate proficiency in the concepts and objectives introduced and practiced in preceding days.
If the instructions are not clear, please seek support from your TL and Instructor on Slack.
The Minimum Viable Product must be completed in three hours.
Follow these steps to set up and work on your project:
- Create a forked copy of this project.
- Add your Team Lead as collaborator on Github.
- Clone your forked version of the Repository.
- Create a new Branch on the clone: git checkout -b
firstName-lastName
. - Implement the project on this Branch, committing changes regularly.
- Push commits: git push origin
firstName-lastName
.
Follow these steps for completing your project.
- Submit a Pull-Request to merge
firstName-lastName
Branch into master on your fork, don't make Pull Requests against Lambda's repository. - Please don't merge your own pull request.
- Add your Team Lead as a Reviewer on the Pull-request
- Your Team Lead will count the challenge as done by merging the branch into master.
Commit your code regularly and use descriptive messages. This helps both you (in case you ever need to return to old code) and your Team Lead.
Demonstrate your understanding of this week's concepts by answering the following free-form questions. Edit this document to include your answers after each question. Make sure to leave a blank line above and below your answer so it is clear and easy to read by your project manager.
- Explain the difference between
Relational Databases
andSQL
.
Relational Databases are a type of database that uses a system of tables and keys to keep track of information related to each other. The keys are used to keep track of information within related tables to associated information together. SQL is a Structured Query Language used to manage databases and the data within them. It's used for CRUD operations against a relational database.
- Why do tables need a
primary key
?
A primary key is a way to uniquely identify each entry in the database. Otherwise, the data could be un-unique and make it impossible to retrieve.
- What is the name given to a table column that references the primary key on another table.
Foreign key
- What do we need in order to have a many to many relationship between two tables.
A middle reference/look up table that reference the combo of both side.
Take the steps necessary to complete the project from scratch. Start by initializing your project with a package.json
and go from there.
Complete the following tasks:
- Design the data model and use knex migrations to create the database and tables.
- Build an API with endpoints for:
- adding resources.
- retrieving a list of resources.
- adding projects.
- retrieving a list of projects.
- adding tasks.
- retrieving a list of tasks. The list of tasks should include the project name and project description.
- When returning
project
ortask
information, thecompleted
property should betrue
orfalse
.
For example, instead of returning a task
that looks like this:
{
id: 1,
name: 'convert to boolean',
completed: 1 // the database stores a 1 to represent true values on a boolean field
}
The API should return:
{
id: 1,
name: 'convert to boolean',
completed: true // write code to convert the 1 to true and 0 to false
}
- a
project
can have multipletasks
. - a
task
belongs to only oneproject
. - a
project
can use multipleresources
. - the same
resource
can be used in multipleprojects
. - when adding
projects
the client must provide a name, the description is optional. - when adding
resources
the client must provide a name, the description is optional. - when adding a
task
the client must provide a description, the notes are optional. - when adding a
task
the client must provide theid
of an existing project. - for
projects
andtasks
if no value is provided for thecompleted
property, the API should provide a default value offalse
.
A project
is what needs to be done. We want to store the following data about a project
:
- a unique Id.
- a name. This column is required.
- a description.
- a boolean that indicates if the project has been completed. This column cannot be NULL, the default value should be
false
.
A resource
is anything needed to complete a project, some examples are: a person, a tool, a meeting room or a software license. We want to store the following data about a resource
:
- a unique Id.
- a name. This column is required.
- a description.
The database should not allow resources with duplicate names.
An task
one of the steps needed to complete the project. We want to store the following data about an task
.
- a unique id.
- a description of what needs to be done. This column is required.
- a notes column to add additional information.
- a boolean that indicates if the task has been completed. This column cannot be NULL, the default value should be
false
.
This section is optional and not counted towards MVP. Start working on it after you're done with the main assignment.
Add an endpoint for retrieving a project
by its id
that returns an object with the following structure:
{
id: 1,
name: 'project name here',
description: 'the project description',
completed: false, // or true, the database will return 1 for true and 0 for false
tasks: [
{
id: 1,
description: 'task description',
notes: 'the task notes',
completed: false // or true
},
{
id: 7,
description: 'another task description',
notes: 'the task notes',
completed: false // or true
}
],
resources: [
{
id: 1,
name: 'Lambda Student',
description: 'a soon to be hired developer'
},
{
id: 2,
name: 'MacBook Pro #1'
description: 'an overly expensive laptop computer'
}
]
}
Add the remaining CRUD operations for projects and tasks.
Use knex
to add data seeding scripts for projects and tasks.
Add support for the concept of contexts
. A context is something like at home, at work or at computer. The idea is that some tasks require one or more contexts
in order to be worked on. For example, the task of file income taxes may require that you are at home, at computer and online so if you are at work and look at the list of pending tasks you could do in your current context, filing your taxes will not be one of them.
A context
can be applied to more than one task
. An task can be tied to more than one context, like in the example above.
When retrieving an task
by id, add a property that lists all the contexts
related to that task.
Good luck and have fun!