"""Interface to the ows-product-review microservice.""" from oto import response from owsrequest import request from product_digital.constants import services from product_digital.utils.response_handler_util import safe_decode_json def get_rejection(product_id): """Get the rejection for a given product. Args: product_id (int): the product id Returns: response.Response: status of rejections call and a dict that's empty or has a single result """ ows_product_review_response = request.get( services.OWS_PRODUCT_REVIEW, '/reject/{product_id}'.format( product_id=product_id), ) info_body = safe_decode_json( ows_product_review_response, services.OWS_PRODUCT_REVIEW) if ows_product_review_response.status_code != 200: return response.create_error_response( status=ows_product_review_response.status_code, code=info_body.get('code'), message=info_body.get('message')) return response.Response(message=info_body) def get_status(product_id): """Get the Gated DIY AWAL product status. We fetch it from ows-content-review using simplified logic. No corrections as of now. Args: product_id (int): the product id Returns: response.Response: status of rejections call and a dict with data """ ows_product_review_response = request.get( services.OWS_PRODUCT_REVIEW, f'/status/{product_id}', ) info_body = safe_decode_json( ows_product_review_response, services.OWS_PRODUCT_REVIEW) if ows_product_review_response.status_code != 200: return response.create_error_response( status=ows_product_review_response.status_code, code=info_body.get('code'), message=info_body.get('message')) return response.Response(message=info_body)