예제 #1
0
    def create_user(username: str, email: str, phone: str,
                    avatar_url: str) -> User:
        """
        Create a new user.

        Args :
            data = {username, email, phone, avatar_url}
        """
        old_user = (db.session.query(User).filter(
            or_(User.email == email, User.phone == phone)).first())
        if old_user:
            json_abort(
                409,
                f"User already exists. We do not allow for duplicate phones, emails, or usernames.",
            )
        user = User(
            username=username,
            email=email,
            phone=phone,
            avatar_url=avatar_url,
            calorie=0,
        )
        db.session.add(user)
        db.session.commit()

        return user
예제 #2
0
파일: user.py 프로젝트: hamza-kadiri/gojap
def remove_user(user_id: int) -> Response:
    """Delete a user.

    Returns :
        {username, email, phone, calorie}
    """
    user = UserService.remove_user(user_id)
    if not user:
        return json_abort(404, f"User not found")

    return jsonify({"user": user})
예제 #3
0
def get_command_by_user_and_table(table_id: int, user_id: int) -> Response:
    """Get commands for a user.

    Returns :
        {command: id, user_id, table_id}
    """
    command = CommandService.get_command_by_user_and_table(table_id, user_id)
    if not command:
        return json_abort(404, f"Command not found")

    return jsonify({"command": command})
예제 #4
0
def get_command(command_id: int) -> Response:
    """Find a given command.

    Returns :
        {command : id, item_id, table_id, users}
    """
    command = CommandService.get_command(command_id)

    if not command:
        return json_abort(404, f"No command with id {command_id}")
    return jsonify({"command": command})
예제 #5
0
파일: user.py 프로젝트: hamza-kadiri/gojap
def get_user(user_id: int) -> Response:
    """
    Find a given user.

    Returns :
        {user : id, username, email, phone, calorie}
    """
    user = UserService.get_user(user_id)

    if not user:
        return json_abort(404, f"No user with id {user_id}")
    return jsonify(user)
예제 #6
0
def get_unique_command_by_table_id_and_item_id(table_id: int,
                                               item_id: int) -> Response:
    """Get a unique command for a table_id and item_id.

    Returns :
        {command: id, item_id, table_id, users}
    """
    command = CommandService.get_unique_command_by_table_id_and_item_id(
        table_id, item_id)
    if not command:
        return json_abort(404, f"Command not found")

    return jsonify(command)
예제 #7
0
파일: user.py 프로젝트: hamza-kadiri/gojap
def create_user() -> Response:
    """Create a new user.

    Args :
        data = {username, email, phone, ?avatar_url}

    Returns :
        {user : id, username, email, phone, calorie}
    """
    data = request.json
    avatar_url = data["avatar_url"] if "avatar_url" in data else ""

    if not data["username"]:
        return json_abort(400, f"Empty string not allowed as a username")

    user = UserService.create_user(
        data["username"], data["email"], data["phone"], avatar_url
    )

    return jsonify({"user": user})
예제 #8
0
def create_jap_event() -> Response:
    """Create a new jap_event.

    Body args :
        {event_name, description, jap_place_id, creator_id, date}

    Returns :
        {serialized jap_event}
    """
    data = request.json
    if not data["event_name"]:
        return json_abort(400, f"Empty string not allowed as a event_name")
    jap_event = JapEventService.create_jap_event(
        data["event_name"],
        data["description"],
        data["jap_place_id"],
        data["creator_id"],
        data["date"],
    )

    return jsonify(jap_event)