RestApi code refactoring - database