add get_service_with_docs_by_service_type() #35

Merged
zuul merged 2 commits from service_by_service_type into main 2023-02-21 10:44:52 +00:00

View File

@ -209,3 +209,22 @@ class Services(object):
doc_struct[srv["service_category"]].append(srv_res) doc_struct[srv["service_category"]].append(srv_res)
return dict(categories=doc_struct) return dict(categories=doc_struct)
def get_service_with_docs_by_service_type(self, service_type):
"""Retrieve service and service docs by service_type
:param str service_type: Filter by service_type
"""
res = dict()
res['service'] = {}
docs = []
services = self._service_data
for doc in services['documents']:
if doc['service_type'] == service_type:
docs.append(doc)
res['documents'] = docs
for service in services['services']:
if service['service_type'] == service_type:
res['service'] = service
break
tischrei marked this conversation as resolved
Review

why break is required here? There’s only unique service_type in services so after the if condition for the matching service_type you should get exactly one matching res[‘service’] even after completing the loop.

why break is required here? There's only unique service_type in services so after the if condition for the matching service_type you should get exactly one matching res['service'] even after completing the loop.
Review

You are right, that the break is not necessary. The reason I use it here is to shorten the runtime a bit. The loop breaks because 1 result is expected, otherwise the loop would run further which is not necessary and results in larger runtime of this loop.

You are right, that the break is not necessary. The reason I use it here is to shorten the runtime a bit. The loop breaks because 1 result is expected, otherwise the loop would run further which is not necessary and results in larger runtime of this loop.
return res