____. .__ __________ __
| |__ ______________ ______ _____|__| ____ \______ \_____ _______| | __
| | | \_ __ \__ \ / ___// ___/ |/ ___\ | ___/\__ \\_ __ \ |/ /
/\__| | | /| | \// __ \_\___ \ \___ \| \ \___ | | / __ \| | \/ <
\________|____/ |__| (____ /____ >____ >__|\___ > |____| (____ /__| |__|_ \
\/ \/ \/ \/ \/ \/
Jurassic Park Setup
Versions & Requirements
- Ruby 3.1.2
- Rails 7.0.7
- PostgreSQL
Setup and Server Start
- Run
bundle install
to install all gems - Run
rails db:create
to create the database - Run
rails db:migrate
to run migrations - Run
rails db:seed
to seed the database - Run
rails s
to start the server - Navigate to
localhost:3000
in your browser - Enjoy, but warning dinosaurs are dangerous and may eat you. Good luck.
Notes
- The seed file will create 5 users. Please see 'db/seeds.rb' for login and API credentials.
- To connect to the API, use the following headers:
Accept: application/json
X-User-Email
X-User-Token
API Request Example
curl --location --request GET 'localhost:3000/cages' \
--header 'X-User-Email: grant@jp-park.net' \
--header 'X-User-Token: A4BpSG' \
--header 'Accept: application/json'
User Roles
- All Users: Can create, update, and delete dinosaurs, along with update cages.
- Builders: Can create, cages.
Testing
- Run
rails test
to run all tests
API Endpoints
Dinosaurs
GET /dinosaurs
- Returns all dinosaurs- Filter by species:
GET /dinosaurs?species=0
- Filter by diet:
GET /dinosaurs?diet=0
- Filter by species:
Species Values
Species | Value |
---|---|
Tyrannosaurus | 0 |
Velociraptor | 1 |
Spinosaurus | 2 |
Megalosaurus | 3 |
Brachiosaurus | 4 |
Stegosaurus | 5 |
Ankylosaurus | 6 |
Triceratops | 7 |
Diet Values
Diet | Value |
---|---|
Herbivore | 0 |
Carnivore | 1 |
GET /dinosaurs/:id
- Returns a single dinosaurPOST /dinosaurs
- Creates a new dinosaur Required Params:name
,species
,cage_id
- species:
Tyrannosaurus
,Velociraptor
,Spinosaurus
,Megalosaurus
,Brachiosaurus
,Stegosaurus
,Ankylosaurus
,Triceratops
- species:
PUT /dinosaurs/:id
- Updates a dinosaurDELETE /dinosaurs/:id
- Deletes a dinosaur
Cages
GET /cages
- Returns all cages- Filter by cage type:
GET /cages?cage_type=0
- Filter by max capacity:
GET /cages?max_capacity=0
- Filter by power status:
GET /cages?power=false
- Filter by cage type:
Cage Type Values
Cage Type | Value |
---|---|
Herbivore | 0 |
Carnivore | 1 |
Power Values
Power Status | Value |
---|---|
Active | true |
Down | false |
GET /cages/:id
- Returns a single cagePOST /cages
- Creates a new cage Required Params:name
,max_capacity
,cage_type
- cage_types:
herbivore
,carnivore
- cage_types:
PUT /cages/:id
- Updates a cageDELETE /cages/:id
- Deletes a cage
API Examples
Access Error
{
"error": "Ah, ah, ah! You didn't say the magic word!"
}
Cage Example
// Create a new cage
curl --location 'localhost:3000/cages' \
--header 'X-User-Email: nedry@jp-park.net' \
--header 'X-User-Token: IALVOP' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"cage": {
"name": "My cage that is very safe",
"max_capacity": 8,
"power": true,
"cage_type": 1
}
}'
Dinosaur Example
// Create a new dinosaur
curl --location 'localhost:3000/dinosaurs' \
--header 'X-User-Email: nedry@jp-park.net' \
--header 'X-User-Token: IALVOP' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"dinosaur": {
"name": "Dino Mite",
"species": 0,
"cage_id": 5
}
}'