moved code from products controller into api controller