Fix the user/course api querying invalid id

Tests added as well