diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 6e74089..50d6e89 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -12,4 +12,9 @@ class ApiController < ApplicationController def tournament @tournament = Tournament.where(:id => params[:tournament]).includes(:schools,:weights,:mats,:matches,:user,:wrestlers).first end + + def newTournament + @tournament = Tournament.new(JSON.parse(params[:tournament])) + @tournament.save + end end diff --git a/config/routes.rb b/config/routes.rb index a4008fb..30007fe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -56,6 +56,7 @@ Wrestling::Application.routes.draw do get "/api/tournaments" => "api#tournaments" get "/api/tournaments/:tournament" => "api#tournament" get "/api/index" => "api#index" + post "/api/tournaments/new" => "newTournament" # Example of regular route: # get 'products/:id' => 'catalog#view' diff --git a/frontend/app/js/homeController.js b/frontend/app/js/homeController.js deleted file mode 100644 index 4e261b4..0000000 --- a/frontend/app/js/homeController.js +++ /dev/null @@ -1,17 +0,0 @@ -app.controller("homeController", function($scope, $http) { - $scope.message = "Test message in scope."; - - - $http({ - method: 'GET', - url: '/api/tournaments/' - }).then(function successCallback(response) { - // this callback will be called asynchronously - // when the response is available - $scope.query = response.data; - }, function errorCallback(response) { - // called asynchronously if an error occurs - // or server returns response with an error status. - $scope.query = "Nothing there"; - }); -}); \ No newline at end of file diff --git a/frontend/app/js/tournaments-controller.js b/frontend/app/js/tournaments-controller.js new file mode 100644 index 0000000..bc79971 --- /dev/null +++ b/frontend/app/js/tournaments-controller.js @@ -0,0 +1,10 @@ +app.controller("tournamentsController", function($scope, tournamentsService) { + $scope.message = "Test message in scope."; + tournamentsService.getAllTournaments().then(function(data) { + //this will execute when the + //AJAX call completes. + console.log(data); + $scope.allTournaments = data; + }); + +}); \ No newline at end of file diff --git a/frontend/app/js/tournaments-service.js b/frontend/app/js/tournaments-service.js new file mode 100644 index 0000000..b301cf6 --- /dev/null +++ b/frontend/app/js/tournaments-service.js @@ -0,0 +1,17 @@ +app.factory('tournamentsService', function($http){ + + + return { + getAllTournaments: function() { + //since $http.get returns a promise, + //and promise.then() also returns a promise + //that resolves to whatever value is returned in it's + //callback argument, we can return that. + return $http.get('/api/tournaments/').then(function(result) { + return result.data; + }); + } + }; + +}); + diff --git a/frontend/app/pages/index.us b/frontend/app/pages/index.us index 5d7d471..3693a53 100644 --- a/frontend/app/pages/index.us +++ b/frontend/app/pages/index.us @@ -35,7 +35,7 @@
| {{ tournament.name }} | {{ tournament.address }} | {{ tournament.director }} | @@ -65,7 +65,6 @@ -