def get_questions(): """ :return: """ result = community_service.get_questions() return response.json_success(result)
def get_responses(question_id: int): """ :param question_id: :return: """ result = community_service.get_responses(question_id) return response.json_success(result)
def get_user(user_id: int): """ :param user_id: :return: """ result = community_service.get_user(user_id) return response.json_success(result)
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 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)
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)