def validate(content: dict) -> bool: try: jsonschema_validate(instance=content, schema=PreferenceValidator.__json_validator) return True except Exception as exception: Logger.error("PreferenceValidator.validate", str(exception)) return False
def build_error_payback(exception: Exception, status_code: int) -> dict: Logger.error("Exception Error", str(exception)) status: str if status_code == 400: status = str(exception) else: status = "Internal Server Error" return {"error_message": status, "status_code": status_code}
def ranking_by_gender(gender: str): response: dict status_code: int = 200 try: Logger.info(f"ranking_by_gender - gender={gender}") response = ranking_service.ranking_by_gender(gender) except Exception as exception: Logger.error(str(exception)) status_code = 500 response = UtilController.build_error_payback(exception, status_code) return UtilController.build_response(response, status_code)
def post_support(user_id: int): response: dict status_code: int = 204 try: Logger.info(f"post_support") message = request.json response = support_service.call_support(user_id, message) except Exception as exception: Logger.error(str(exception)) status_code = 500 response = UtilController.build_error_payback(exception, status_code) return UtilController.build_response(response, status_code)
def get_reminder(user_id: int): response: dict status_code: int = 200 try: Logger.info(f"get_reminder: user_id={user_id}") response = reminder_service.get_reminder(user_id) except Exception as exception: Logger.error(str(exception)) status_code = 500 response = UtilController.build_error_payback( exception, status_code) return UtilController.build_response(response, status_code)
def list_reminder(): response: dict status_code: int = 200 try: Logger.info(f"list_reminder") response = reminder_service.list_reminder() except Exception as exception: Logger.error(str(exception)) status_code = 500 response = UtilController.build_error_payback( exception, status_code) return UtilController.build_response(response, status_code)
def post_watched(user_id: int, movie_id: int): response: dict = {} status_code: int = 204 try: Logger.info(f"post_watched: user_id:{user_id} movie_id={movie_id}") watched_service.post_watched(user_id, movie_id) except Exception as exception: Logger.error(str(exception)) status_code = 500 response = UtilController.build_error_payback( exception, status_code) return UtilController.build_response(response, status_code)
def add_movie(): response: dict status_code: int = 204 try: movie = request.json Logger.info(f"add_movie: movie={movie['name']}") response = service.add_movie( movie=movie ) except Exception as exception: Logger.error(str(exception)) status_code = 500 response = UtilController.build_error_payback(exception, status_code) return UtilController.build_response(response, status_code)
def get_votes_by(movie_id: int): response: dict status_code: int = 200 try: Logger.info(f"get_votes_by: movie_id={movie_id}") response = vote_service.get_votes_by(movie_id) if not response: status_code = 404 response = {} except Exception as exception: Logger.error(str(exception)) status_code = 500 response = UtilController.build_error_payback( exception, status_code) return UtilController.build_response(response, status_code)