Improve, refactor and create basic unit tests for the posts controller