in microservices/learning_object_service/src/routes/curriculum_pathway.py [0:0]
def get_curriculum_pathways(
alias: str = None,
fetch_archive: bool = None,
learning_opportunity: str = None,
learning_experience: str = None,
parent_curriculum_pathway: str = None,
child_curriculum_pathway: str = None,
is_active: bool = None,
author: str = None,
version: int = None,
skip: int = Query(0, ge=0, le=2000),
limit: int = Query(10, ge=1, le=100)):
"""The get curriculum pathways endpoint will return an array learning
experiences from firestore
### Args:
parent_curriculum_pathway: `str`
UUID of the curriculum pathway that is a parent node <br/>
child_curriculum_pathway: `str`
UUID of the curriculum pathway that is a child node <br/>
learning_opportunity: `str`
UUID of the learning opportunity <br/>
learning_experience: `str`
UUID of the learning experience <br/>
is_active: `bool`
Flag to determine whether to fetch active pathway or not
version: `int`
Version of the data object <br/>
author: `str`
Name of the Author of the data object <br/>
skip: `int`
Number of experiences to be skipped <br/>
limit: `int`
Size of curriculum pathway array to be returned <br/>
### Raises:
ValueError:
Raised when input angles are outside range. <br/>
Exception 500
Internal Server Error Raised. Raised if something went wrong
### Returns:
Array of Curriculum Pathway: `AllCurriculumPathwaysResponseModel`
"""
try:
array_flag = 0
if alias:
collection_manager = CurriculumPathway.collection.filter(
"alias", "==", alias).filter("is_deleted", "==", False)
else:
collection_manager = CurriculumPathway.collection.filter(
"is_deleted", "==", False)
if learning_opportunity:
collection_manager = collection_manager.filter(
"parent_nodes.learning_opportunities", "array_contains",
learning_opportunity)
array_flag += 1
if parent_curriculum_pathway:
collection_manager = collection_manager.filter(
"parent_nodes.curriculum_pathways", "array_contains",
parent_curriculum_pathway)
array_flag += 1
if child_curriculum_pathway:
collection_manager = collection_manager.filter(
"child_nodes.curriculum_pathways", "array_contains",
child_curriculum_pathway)
array_flag += 1
if learning_experience:
collection_manager = collection_manager.filter(
"child_nodes.learning_experiences", "array_contains",
learning_experience)
array_flag += 1
if version:
collection_manager = collection_manager.filter("version", "==", version)
if author:
collection_manager = collection_manager.filter("author", "==", author)
if is_active is not None:
collection_manager = collection_manager.filter(
"is_active", "==", is_active)
if array_flag > 1:
raise ValidationError(
"Please use only one of the following fields for filter at a "
"time - author, learning_experience, learning_opportunity, version"
)
if fetch_archive:
collection_manager = collection_manager.filter("is_archived", "==", True)
elif fetch_archive is False:
collection_manager = collection_manager.filter("is_archived", "==", False)
curriculum_pathways = collection_manager.order("-created_time").offset(
skip).fetch(limit)
curriculum_pathways = [
i.get_fields(reformat_datetime=True) for i in curriculum_pathways
]
count = 10000
response = {"records": curriculum_pathways, "total_count": count}
return {
"success": True,
"message": "Data fetched successfully",
"data": response
}
except ValidationError as e:
Logger.error(e)
Logger.error(traceback.print_exc())
raise BadRequest(str(e)) from e
except ResourceNotFoundException as e:
Logger.error(e)
Logger.error(traceback.print_exc())
raise ResourceNotFound(str(e)) from e
except Exception as e:
Logger.error(e)
Logger.error(traceback.print_exc())
raise InternalServerError(str(e)) from e