In today's exercise, we'll be building out a doctor - patient - appointment domain. The first step will be to build out the models and migrations. Next, we'll create seed data so that our api will have some data to start out with
- Models & migrations
- Seed Data & Test Relationships in Console
- Build out API endpoints to implement CRUD
- A high level description of your tasks is below.
- Each section is test driven with a separate test file.
- You can run
rspec --f-f
to progress through the tests. - Consult test errors as you go
- After completing part 2, you can use
tux
to interact with your models and seeded data - While working through part 3, you can use
binding.pry
within your routes to pause the tests in the middle of a request so you can poke around and see what's going on. - At this point, if you've run your seeds, you should also be able to use these functions to test out your API: Sinatra API Testing
There are 3 classes and tables you'll need to create:
- Doctor
- name
- specialization
- Patient
- name
- Appointment
- time (as a string)
- doctor_id
- patient_id
In the first part of the exercise, you'll also be putting together the relationships between your models.
For this portion, you'll want to create a seeds file that will start by destroying all existing data in the database. You can create additional records if you like, but at the minimum, your seeds file should create:
- 2 Doctors
- 1 named "Dr. Drew" specializing in "Addiction Medicine"
- 1 named "Dr. Fauci" specializing in "Infectious Diseases"
- 2 Patients
- 1 named "Dennis Rodman"
- 1 named "Tom Hanks"
- 2 appointments
- 1 at "2:00 PM" for Dennis Rodman with Dr. Drew
- 1 at "11:30 AM" for Tom Hanks with Dr. Fauci
Once you've built out the seeds, you can run them using rake db:seed
. After that, you can run the tux
command.
Once you're in the console, try out the associations.
Appointment.first.doctor
Appointment.last.patient
Doctor.first.appointments
Doctor.last.patients
Patient.first.appointments
Patient.last.doctors
You'll be implementing CRUD for all 3 models. For testing purposes, all routes must be defined within the app/controllers/application_controller.rb
file.
Doctor
- get '/doctors'
- post '/new_doctor'
- patch '/doctors/:id'
- delete '/doctors/:id'
Patient
- get '/patients'
- post '/new_patient'
- patch '/patients/:id'
- delete '/patients/:id'
Appointment
- get '/appointments'
- post '/new_appointment'
- patch '/appointments/:id'
- delete '/appointments/:id'
- get '/doctors/:id/appointments'
- post '/doctors/:id/appointments'
- get '/patients/:id/appointments'
- post '/patients/:id/appointments'
- get '/doctors_by_specialization/:specialization'