I have some doubts about the logic of the search functions of the controller and the service.
Here is an example of service :
angular.module("myApp").factory("ProjetosAPI", function ($http, config) {
var _getProjetos = function (pagina, total) {
return $http.get(config.baseUrl + "/projetos?pagina=" + pagina + "&total=" + total);
};
var _getProjetosPorEmpresa = function (pagina, total, empresa) {
return $http.get(config.baseUrl + "/projetos?pagina=" + pagina + "&total=" + total + "&empresa=" + empresa);
};
var _getProjetosPorEmpresaData = function (pagina, total, empresa, data) {
return $http.get(config.baseUrl + "/projetos?pagina=" + pagina + "&total=" + total + "&empresa=" + empresa + "&data=" + data);
};
return {
getProjetos: _getProjetos,
getProjetosPorEmpresa: _getProjetosPoEmpresa,
getProjetosPorEmpresaData: _getProjetosPoEmpresaData
};
});
Questions:
1- Is this approach "right"?
2- If I needed to search by company, date and value or just by date, would I add another function? For example: getProjetosPorEmpresaDataValor
or getProjetoPorData
.
In the controller , would I need to have a function for each function of the service , with the appropriate parameters?
I'm using it this way so far. In the REST API (node.js + express.js) I have a single function for GET /projetos
which handles which data to bring according to the parameters received in the request.
As I have never developed a great application, I have many similar doubts, if you can tell me some material that would help in that sense, it would be good.