diff --git a/README.md b/README.md index 0ccd2dd..add1ca2 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Up and Running: 2. Run the command `bundle install` 3. Create the database with `rails db:create` 4. Run the migrations `rails db:migrate` -5. Seed the dabase `brake import:import_pokemon` +5. Seed the dabase `rake import:import_pokemon` # API Docs diff --git a/app/controllers/api/v1/pokemons_controller.rb b/app/controllers/api/v1/pokemons_controller.rb index 8249ef6..8859bfb 100644 --- a/app/controllers/api/v1/pokemons_controller.rb +++ b/app/controllers/api/v1/pokemons_controller.rb @@ -1,5 +1,7 @@ class Api::V1::PokemonsController < ApplicationController before_action :set_pokemon, only: [:show, :update, :destroy] + + #CRUD POKEMON def index @pokemons = Pokemon.all.includes(:types) diff --git a/app/controllers/api/v1/types_controller.rb b/app/controllers/api/v1/types_controller.rb index 0f16984..9f7fc71 100644 --- a/app/controllers/api/v1/types_controller.rb +++ b/app/controllers/api/v1/types_controller.rb @@ -1,6 +1,7 @@ class Api::V1::TypesController < ApplicationController before_action :set_type, only: [:show, :update, :destroy] + #CRUD TYPES def index @types = Type.all diff --git a/app/models/pokemon.rb b/app/models/pokemon.rb index 45af6e4..532c683 100644 --- a/app/models/pokemon.rb +++ b/app/models/pokemon.rb @@ -1,4 +1,5 @@ class Pokemon < ApplicationRecord + #MODEL POKEMON, ASSOCIATED WITH TYPES AND VALIDATIONS validates :name, presence: true, uniqueness: true validates :order, presence: true, uniqueness: true diff --git a/app/models/pokemon_type.rb b/app/models/pokemon_type.rb index 9e8ae3b..0f69234 100644 --- a/app/models/pokemon_type.rb +++ b/app/models/pokemon_type.rb @@ -1,4 +1,5 @@ class PokemonType < ApplicationRecord + #INTERMEDIATE MODEL FOR RELATIONS BETWEEN POKEMON AND TYPE belongs_to :pokemon belongs_to :type diff --git a/app/models/type.rb b/app/models/type.rb index b2af279..362f2b7 100644 --- a/app/models/type.rb +++ b/app/models/type.rb @@ -1,4 +1,5 @@ class Type < ApplicationRecord + #MODEL TYPE WITH VALIDATIONS has_many :pokemon_types has_many :pokemons, through: :pokemon_types diff --git a/config/routes.rb b/config/routes.rb index b5722cc..24281a4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,8 @@ # Can be used by load balancers and uptime monitors to verify that the app is live. get "up" => "rails/health#show", as: :rails_health_check + #ROUTES TO POKEMON AND TYPE + namespace :api do namespace :v1 do resources :pokemons diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index ff167c5..9f87bd4 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -2,6 +2,8 @@ require 'json' require 'net/http' require 'uri' +#RAKE TASK TO IMPORT DATA FROM POKEAPI + namespace :import do desc "Import data from PokeApi" task import_pokemon: :environment do diff --git a/test/controllers/api/v1/pokemons_controller_test.rb b/test/controllers/api/v1/pokemons_controller_test.rb index 023b0bd..27f91eb 100644 --- a/test/controllers/api/v1/pokemons_controller_test.rb +++ b/test/controllers/api/v1/pokemons_controller_test.rb @@ -2,6 +2,8 @@ class Api::V1::PokemonsControllerTest < ActionDispatch::IntegrationTest + + #TEST FOR POKEMON CRUD test 'valid_pokemon' do type = Type.create(name: 'grass')