def create_question(): """ :return: """ payload = request.get_json(force=True) if 'asker_id' not in payload: return response.json_failure("Missing asker_id", status=400) if 'title' not in payload: return response.json_failure("Missing title", status=400) result = community_service.ask_question(payload['asker_id'], payload['title']) return response.json_success(result, status=201)
def create_response(question_id: int): """ :param question_id: :return: """ payload = request.get_json(force=True) if 'responder_id' not in payload: return response.json_failure("Missing responder_id", status=400) if 'text' not in payload: return response.json_failure("Missing text", status=400) result = community_service.respond_question(payload['responder_id'], question_id, payload['text']) return response.json_success(result, status=201)
def global_exception_handler(ex): app.logger.error(traceback.format_exc()) status = 500 msg = str(ex) if isinstance(ex, HTTPException): status = ex.code elif isinstance(ex, SQLAlchemyError): msg = 'Unexpected database error.' return response.json_failure(msg, status=status)
def create_bookmark(user_id: int): """ :param user_id: :return: """ payload = request.get_json(force=True) if 'post_type' not in payload: return response.json_failure("Missing post_type", status=400) if 'post_id' not in payload: return response.json_failure("Missing post_id", status=400) post_id = payload['post_id'] post_type = payload['post_type'] try: post_type = PostType(post_type) except ValueError as e: return response.json_failure(f"Invalid post_type '{post_type}'", status=400) result = community_service.create_bookmark(user_id, post_id, post_type) return response.json_success(result, status=201)
def get_bookmarks(user_id: int, post_type: int): """ :param user_id: :return: """ try: post_type = PostType(post_type) except ValueError as e: return response.json_failure(f"Invalid post_type '{post_type}'", status=400) result = community_service.get_bookmarks(user_id, post_type) return response.json_success(result)