mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-10 15:50:50 +00:00
Start of api
This commit is contained in:
3
app/assets/javascripts/api.js.coffee
Normal file
3
app/assets/javascripts/api.js.coffee
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
# All this logic will automatically be available in application.js.
|
||||||
|
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||||
4
app/assets/stylesheets/api.css
Normal file
4
app/assets/stylesheets/api.css
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
/*
|
||||||
|
Place all the styles related to the matching controller here.
|
||||||
|
They will automatically be included in application.css.
|
||||||
|
*/
|
||||||
10
app/controllers/api_controller.rb
Normal file
10
app/controllers/api_controller.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class ApiController < ApplicationController
|
||||||
|
|
||||||
|
def tournaments
|
||||||
|
@tournaments = Tournament.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def tournament
|
||||||
|
@tournament = Tournament.where(:id => params[:tournament]).includes(:schools,:weights,:mats,:matches,:user,:wrestlers).first
|
||||||
|
end
|
||||||
|
end
|
||||||
2
app/helpers/api_helper.rb
Normal file
2
app/helpers/api_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
module ApiHelper
|
||||||
|
end
|
||||||
1
app/views/api/tournament.jbuilder
Normal file
1
app/views/api/tournament.jbuilder
Normal file
@@ -0,0 +1 @@
|
|||||||
|
json.(@tournament, :id, :name, :address, :director, :director_email, :schools, :weights, :mats, :matches)
|
||||||
4
app/views/api/tournaments.jbuilder
Normal file
4
app/views/api/tournaments.jbuilder
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
json.array!(@tournaments) do |tournament|
|
||||||
|
json.extract! tournament, :id, :name, :address, :director, :director_email
|
||||||
|
json.url tournament_url(tournament, format: :json)
|
||||||
|
end
|
||||||
@@ -51,6 +51,11 @@ Wrestling::Application.routes.draw do
|
|||||||
get 'tournaments/:id/error' => 'tournaments#error'
|
get 'tournaments/:id/error' => 'tournaments#error'
|
||||||
post "/tournaments/:id/swap" => "tournaments#swap", :as => :swap_wrestlers
|
post "/tournaments/:id/swap" => "tournaments#swap", :as => :swap_wrestlers
|
||||||
|
|
||||||
|
|
||||||
|
#API
|
||||||
|
get "/api/tournaments" => "api#tournaments"
|
||||||
|
get "/api/tournaments/:tournament" => "api#tournament"
|
||||||
|
|
||||||
# Example of regular route:
|
# Example of regular route:
|
||||||
# get 'products/:id' => 'catalog#view'
|
# get 'products/:id' => 'catalog#view'
|
||||||
|
|
||||||
|
|||||||
7
test/controllers/api_controller_test.rb
Normal file
7
test/controllers/api_controller_test.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class ApiControllerTest < ActionController::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user