refactor sample for using $resource