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('Doc',function($q, $http, $log, formDataObject){
    var service = {};

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

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

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


    return service;

});
