0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 10
click for more info
No active XP Potion
Accept a Quest
Login to submit answers
Our API needs to support standard CRUD operations for "chirps". A "chirp" is just a short message that a user can post to the API, like a tweet.
{
"body": "Hello, world!",
"user_id": "123e4567-e89b-12d3-a456-426614174000"
}
Delete the /api/validate_chirp
endpoint that we created before, but port all that logic into this one. Users should not be allowed to create invalid chirps!
id
: A UUIDcreated_at
: A non-null timestampupdated_at
: A non null timestampbody
: A non-null stringuser_id
: This should reference the id
of the user who created the chirp, and ON DELETE CASCADE
, which will cause a user's chirps to be deleted if the user is deleted.You'll need a new up/down migration for this table.
As a general rule it's always a good idea to use created_at
and updated_at
timestamps for all your resources. It gives you a nice audit trail and makes it easier to debug issues.
{
"id": "94b7e44c-3604-42e3-bef7-ebfcc3efff8f",
"created_at": "2021-01-01T00:00:00Z",
"updated_at": "2021-01-01T00:00:00Z",
"body": "Hello, world!",
"user_id": "123e4567-e89b-12d3-a456-426614174000"
}
Yes, this isn't secure because it means any user can create a chirp on behalf of any other user. We'll fix that in a future assignment.
Run and submit the CLI tests.
The Boot.dev CLI requires you to be signed in to submit your solution!
Copy/paste one of the following commands into your terminal:
Run
bootdev run acf357f0-ec20-429f-99ec-265963c2fedf
Submit
bootdev run acf357f0-ec20-429f-99ec-265963c2fedf -s
To run and submit the tests for this lesson, you must have an active Boot.dev membership
Become a member to view solution
Using the Bootdev CLI
The Bootdev CLI is the only way to submit your solution for this type of lesson. We need to be able to run commands in your environment to verify your solution.
You can install it here. It's a Go program hosted on GitHub, so you'll need Go installed as well. Instructions are on the GitHub page.