Refactor the code to reduce repeated switch block and added some func comments.
Added user endpoints call.