Moved API route logic to models