Move code outside controller

Refactor code to use proper GET, POST, PUT and Delete protocol and Promise code style