1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Start of api

This commit is contained in:
2016-02-10 15:16:58 +00:00
parent 731131073f
commit e215717914
8 changed files with 36 additions and 0 deletions

View 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/

View File

@@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

View 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

View File

@@ -0,0 +1,2 @@
module ApiHelper
end

View File

@@ -0,0 +1 @@
json.(@tournament, :id, :name, :address, :director, :director_email, :schools, :weights, :mats, :matches)

View 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

View File

@@ -51,6 +51,11 @@ Wrestling::Application.routes.draw do
get 'tournaments/:id/error' => 'tournaments#error'
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:
# get 'products/:id' => 'catalog#view'

View File

@@ -0,0 +1,7 @@
require 'test_helper'
class ApiControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end