• Jump To … +
    auth.js comments.js glint.js ideas.js votes.js services.js commentController.js commentModel.js commentRoutes.js helpers.js middleware.js ideaController.js ideaModel.js ideaRoutes.js serverSetup.js serverSpec.js usersController.js usersModel.js usersRoutes.js voteController.js voteRoutes.js
  • services.js

  • ¶
    var glintServices = angular.module('glint.services', []);
    
    glintServices.factory('Ideas', function ($http){
    
      var getIdeas = function (){
        return $http({
          method: 'GET',
          url: '/api/ideas'
        }).then(function (response){
          return response.data;
        }).catch(function (error) {
          console.error('getIdeas error', error);
        });
      };
    
      var createIdea = function (idea){
        return $http({
          method: 'POST',
          url: '/api/ideas',
          data: idea
        }).then(function (response){
          return response.data;
        }).catch(function (error) {
          console.error('createIdeas error', error);
        });
      };
    
      return {
        getIdeas: getIdeas,
        createIdea: createIdea
      };
    });
    
    glintServices.factory('Votes', function($http){
    
      var upvote = function (idea){
        return $http({
          method: 'POST',
          url: '/api/vote/upvote',
          data: idea
        })
        .then(function (response){
          return response.data;
        })
        .catch(function (error) {
          console.error('upvote error', error);
        });
      };
    
      var downvote = function (idea){
        return $http({
          method: 'POST',
          url: '/api/vote/downvote',
          data: idea
        })
        .then(function (response){
          return response.data;
        })
        .catch(function (error) {
          console.error('downvote error', error);
        });
      };
    
      return {
        upvote: upvote,
        downvote: downvote
      };
    });
    
    glintServices.factory('Auth', function($http){
    
      var login = function (user){
        return $http({
          method: 'POST',
          url: '/api/signin',
          data: user
        })
        .then(function (response){
          return response.data;
        })
        .catch(function (error) {
          console.error('login error', error);
        });  };
    
      var signup = function (user){
        return $http({
          method: 'POST',
          url: '/api/signup',
          data: user
        })
        .then(function (response){
          return response.data;
        })
        .catch(function (error) {
          console.error('signup error', error);
        });
      };
    
      return {
        login: login,
        signup: signup
      };
    });
    
    glintServices.factory('Comments', function ($http){
      
      var createComment = function (comment){
        return $http({
          method: 'POST',
          url: '/api/comments',
          data: comment
        }).then(function (response){
          return response.data;
        }).catch(function (error) {
          console.error('createComments error', error);
        });
    
      };
    
      var getComments = function (idea_id){
        return $http({
          method: 'GET',
          url: '/api/comments',
          data: idea_id
        }).then(function (response){
          return response.data;
        }).catch(function (error) {
          console.error('getComments error', error);
        });
      };
    
      return {
        createComment: createComment,
        getComments: getComments
      };
    });