Basically I am a little bit unsure how should I create/manage my resource. I am thinking about resource as a model like in (MVC) background. So for example this is my factory:
angular.module('resources.question', ['ngResource'])
.factory('Question', function ($resource) {
return $resource('/:questionId', {questionId: '@id'}, {
postTest: {method: 'POST', url: '/create/:pageId/:questionId', params: {questionId: 0}},
search: {method: 'GET', url: '/search/:query', params: {query: ''}, isArray: true},
edit: {method: 'GET', url: '/edit/:pageQuestionId'},
delete: {method: 'GET', url: '/delete/:pageQuestionId'},
addExisting: {method: 'GET', url: '/addtopage/:pageId/:questionId'}
});
});
I am noticing that I have some repeating tasks, like inserting data. For example:
var newQuestion = Question.addExisting({
pageId: data.pageId,
questionId: data.questionId,
id: $scope.data.search.question.id
});
//update object from database
$rootScope.survey.pages[data.pageIndex].questions.splice(data.questionIndex, 0, newQuestion); //insert the data
So basically I am not sure how to handle similar situations. Does my factory needs to extended somehow to handle this kind of data manipulation, or do I need to create another factory for these kind of tasks. Or it's just me over-thinking this ?