def _find_feature(id): """ Find a feature by id """ feature = Feature.find(id) if not feature: msg = f"Feature not found." raise exceptions.NotFound({"message": msg}) return feature
def create_feature(featureData: FeatureCreate): """ Create a new feature """ _check_id_format(featureData.id) _check_version_format(featureData.version) if Feature.find(featureData.id): msg = f"The feature id isn't available. Please try another." return http.JSONResponse({"message": msg}, status_code=409) _check_services_exists(featureData.services) feature = Feature.create(**featureData) msg = "Feature created successfully." log.info(f"{msg} - ID: {feature.id}") feature.update_services(featureData.services) headers = {"Content-Location": f"/features/{feature.id}"} return http.JSONResponse({"message": msg}, status_code=201, headers=headers)