2
I have some questions regarding the logic of the controller and service search functions.
Follow 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
};
});
Doubts:
1- This approach is "correct"?
2- If I needed to search by company, date and value or only by date, would I add one more function? For example: getProjetosPorEmpresaDataValor
or getProjetoPorData
.
3- No controller I would 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 treats which data to bring according to the parameters received in the request.
As I have never developed a large application, I have several similar doubts, if you can point me some material to help in this direction it would be good.