create optimized course tree query API endpoint