"""Interface to the ows-notifications microservice.""" from owsrequest import request from owsresponse import response, status from product_review.constants import error, services def send_approval_email(product_id): """Send email notifications for approved product.""" body = { "product_id": product_id, } ows_notifications_response = request.post( services.OWS_NOTIFICATIONS, "/activity/product_approval", json=body ) if ows_notifications_response.status_code not in [status.OK, status.CREATED]: return response.create_error_response( status=ows_notifications_response.status_code, code=error.OWS_NOTIFICATIONS_ERROR_CODE, message=ows_notifications_response.json(), ) return response.Response( status=status.CREATED, message={ "notification_type": "approval", "profiles": ows_notifications_response.json(), }, ) def send_rejection_email(product_id, note): """Send email notifications for rejected product.""" body = { "product_id": product_id, "rejection_reasons": [{"title": "General Comments", "comments": note}], } ows_notifications_response = request.post( services.OWS_NOTIFICATIONS, "/activity/product_rejection", json=body ) if ows_notifications_response.status_code not in [status.OK, status.CREATED]: return response.create_error_response( status=ows_notifications_response.status_code, code=error.OWS_NOTIFICATIONS_ERROR_CODE, message=ows_notifications_response.json(), ) return response.Response( status=status.CREATED, message={ "notification_type": "rejection", "profiles": ows_notifications_response.json(), }, )