diff options
author | 2021-11-24 13:10:09 +0000 | |
---|---|---|
committer | 2021-11-29 12:39:30 +0000 | |
commit | 7e3042157d736e1f81618b92afc3bab501755a31 (patch) | |
tree | 4301aece78d3c486e3b144e736dbf66fc5bd901a /components/pm-subscription-handler/pmsh_service/mod/api/controller.py | |
parent | d7715808aaf9a4f891d2bd571af1a5acc86b4c7b (diff) |
[PMSH] Read all subscriptions API
Issue-ID: DCAEGEN2-2847
Signed-off-by: raviteja.karumuri <raviteja.karumuri@est.tech>
Change-Id: I6a2cbc127e12f2f6b051ed5f58fd2fa584a71908
Diffstat (limited to 'components/pm-subscription-handler/pmsh_service/mod/api/controller.py')
-rwxr-xr-x | components/pm-subscription-handler/pmsh_service/mod/api/controller.py | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/components/pm-subscription-handler/pmsh_service/mod/api/controller.py b/components/pm-subscription-handler/pmsh_service/mod/api/controller.py index 80d86362..e852324d 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/api/controller.py +++ b/components/pm-subscription-handler/pmsh_service/mod/api/controller.py @@ -75,24 +75,40 @@ def get_subscription_by_name(subscription_name): subscription_name (String): Name of the subscription. Returns: - success: dict of single Subscription, 200 - None: subscription not defined, 404 - Exception: Details about exception, 500 + dict, HTTPStatus: single Sub in PMSH, 200 + dict, HTTPStatus: subscription not defined, 404 + dict, HTTPStatus: Exception details of failure, 500 """ logger.info('API call received to fetch subscription by name') try: - subscription = subscription_service.get_subscription_by_name(subscription_name) + subscription = subscription_service.query_subscription_by_name(subscription_name) if subscription is not None: - logger.info(f'subscription object with the name "{subscription_name}" ' - 'was fetched successfully from database') - return subscription.serialize(), HTTPStatus.OK + logger.info(f'queried subscription was successful with the name: {subscription_name}') + return subscription.serialize(), HTTPStatus.OK.value else: - logger.error(f'subscription object with the name "{subscription_name}" ' - 'was un successful to fetch from database') + logger.error('queried subscription was un successful with the name: ' + f'{subscription_name}') return {'error': 'Subscription was not defined with the name : ' - f'{subscription_name}'}, HTTPStatus.NOT_FOUND + f'{subscription_name}'}, HTTPStatus.NOT_FOUND.value except Exception as exception: - logger.error(f'The following exception occurred "{exception}" while fetching subscription ' - f'with the name "{subscription_name}"') + logger.error(f'While querying the subscription with name: {subscription_name}, ' + f'it occurred the following exception "{exception}"') return {'error': 'Request was not processed due to Exception : ' - f'{exception}'}, HTTPStatus.INTERNAL_SERVER_ERROR + f'{exception}'}, HTTPStatus.INTERNAL_SERVER_ERROR.value + + +def get_subscriptions(): + """ Retrieves all the subscriptions that are defined in PMSH. + + Returns: + list (dict), HTTPStatus: All subs in PMSH, 200 + dict, HTTPStatus: Exception details of failure, 500 + """ + logger.info('API call received to fetch all subscriptions') + try: + subscriptions = subscription_service.get_subscriptions_list() + return subscriptions, HTTPStatus.OK.value + except Exception as exception: + logger.error(f'The following exception occurred while fetching subscriptions: {exception}') + return {'error': 'Request was not processed due to Exception : ' + f'{exception}'}, HTTPStatus.INTERNAL_SERVER_ERROR.value |