(function () {
    'use strict';

    const API_URL = 'http://csse-studweb3.canterbury.ac.nz/~bjm213/365/polls/index.php/services/'
    /* Controllers */
    var pollControllers = angular.module('pollControllers', []);

    pollControllers.controller('PollListCtrl', ['$scope', '$http',
    function ($scope, $http) {
      $scope.getVotes = function() {
        $http.get(API_URL + 'polls/')
          .success(function(data) {
            $scope.data = data;
          });
        }
      $scope.vote = function(pollId, answerId) {
        $http.post(API_URL + "votes/" + answerId + "/" + pollId);
        $scope.getVotes();
      };
      $scope.clearVotes = function(pollId) {
        $http.delete(API_URL + "votes/" + pollId);
        $scope.getVotes();
      };
      $scope.getVotes();
      }]);
  }())
