refactored the user controller to remove duplicacy
added tests