poconsole.factory('formDataObject', function() {
    return function(data) {
        var fd = new FormData();
        angular.forEach(data, function(value, key) {
            fd.append(key, value);
        });
        return fd;
    };
});

poconsole.factory('docs',function($q, $http, $log, formDataObject){

    var getAllDocs = function(){
        var deferred = $q.defer();
        $http.get('/doc').success(function(data) {
        	deferred.resolve({
    			docs:data
    		});
        });
        return deferred.promise;
    };

    var getDoc = function(id){
        var deferred = $q.defer();
        $http.get('/doc/' + id).success(function(data) {
        	deferred.resolve({
    			docs:data
    		});
        });
        return deferred.promise;
    };

    var deleteDoc = function(id){
        var deferred = $q.defer();
        $http.delete('/doc/' + id).success(function(data) {
        	deferred.resolve({
    			deleted:data
    		});
        });
        return deferred.promise;
    };


    return {
        getAllDocs:getAllDocs,
        getDoc: getDoc,
        deleteDoc: deleteDoc
    };

});
