Skip to content

Mamba240824/rails-api

Repository files navigation

README

Wildlife Tracker Challenge The Forest Service is considering a proposal to place in conservancy a forest of virgin Douglas fir just outside of Portland, Oregon. Before they give the go ahead, they need to do an environmental impact study. They've asked you to build an API the rangers can use to report wildlife sightings.

Story 1: In order to track wildlife sightings, as a user of the API, I need to manage animals.

terminal process

Branch: animal-crud-actions

Acceptance Criteria

  • create a resource for animal with the following information: common name and scientific binomial

  • rails g resource Animal common_name:string scientific_binomial:string"

  • Can see the data response of all the animals

    • disable authenticity token in app/controllers/application_controller.rb:
      • "skip_before_action :verify_authenticity_token"
    • index method in animal_controller.rb:
      • def index animals = Animal.all render json: animals end

process for postman

GET -> localhost:3000/aniamls Click the send button Body -> Pretty -> JSON (upper portion of postman)

postman results

  • Body -> Pretty -> JSON (lower body) [ { "id": 1, "common_name": "Lion", "scientific_binomial": "Panthera leo", "created_at": "2024-02-03T20:57:03.944Z", "updated_at": "2024-02-03T20:57:03.944Z" }, { "id": 2, "common_name": "Zebra", "scientific_binomial": "Equus quagga", "created_at": "2024-02-03T21:21:31.764Z", "updated_at": "2024-02-03T21:21:31.764Z" }, { "id": 3, "common_name": "Giraffe", "scientific_binomial": "Cervus camelopardalis", "created_at": "2024-02-03T21:27:24.793Z", "updated_at": "2024-02-03T21:27:24.793Z" }, { "id": 4, "common_name": "Giraffe", "scientific_binomial": "Cervus camelopardalis", "created_at": "2024-02-03T21:32:12.027Z", "updated_at": "2024-02-03T21:32:12.027Z" } ]

    • show method to show a single instance in animal_controller.rb:

      • def show animal = Animal.find(params[:id]) render json: animal end
  • Can create a new animal in the database

  • Can update an existing animal in the database

  • Can remove an animal entry in the database Story 2: In order to track wildlife sightings, as a user of the API, I need to manage animal sightings.

Branch: sighting-crud-actions

Acceptance Criteria

-Create a resource for animal sightings with the following information: latitude, longitude, date Hint: An animal has_many sightings (rails g resource Sighting animal_id:integer ...) Hint: Date is written in Active Record as yyyy-mm-dd (“2022-07-28") Can create a new animal sighting in the database Can update an existing animal sighting in the database Can remove an animal sighting in the database Story 3: In order to see the wildlife sightings, as a user of the API, I need to run reports on animal sightings.

Branch: animal-sightings-reports

Acceptance Criteria

Can see one animal with all its associated sightings Hint: Checkout this example on how to include associated records Can see all the all sightings during a given time period Hint: Your controller can use a range to look like this: class SightingsController < ApplicationController def index sightings = Sighting.where(date: params[:start_date]..params[:end_date]) render json: sightings end end Hint: Be sure to add the start_date and end_date to what is permitted in your strong parameters method Hint: Utilize the params section in Postman to ease the developer experience Hint: Routes with params Stretch Challenges Story 4: In order to see the wildlife sightings contain valid data, as a user of the API, I need to include proper specs.

Branch: animal-sightings-specs

Acceptance Criteria Validations will require specs in spec/models and the controller methods will require specs in spec/requests.

Can see validation errors if an animal doesn't include a common name and scientific binomial Can see validation errors if a sighting doesn't include latitude, longitude, or a date Can see a validation error if an animal's common name exactly matches the scientific binomial Can see a validation error if the animal's common name and scientific binomial are not unique Can see a status code of 422 when a post request can not be completed because of validation errors Hint: Handling Errors in an API Application the Rails Way Story 5: In order to increase efficiency, as a user of the API, I need to add an animal and a sighting at the same time.

Branch: submit-animal-with-sightings

Acceptance Criteria

Can create new animal along with sighting data in a single API request Hint: Look into accepts_nested_attributes_for

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published