refactoring controller rest calls to factory