refactor api controller