async def add_channel(
    channel: Channel,
    response: Response,
    collection: AsyncIOMotorCollection = Depends(get_channel_collection)):
    """
    /channels handler for adding a new Channel
    """

    result = await collection.insert_one(channel.dict())
    response.status_code = status.HTTP_201_CREATED
    return response
Beispiel #2
0
def register():
    name = request.form.get('name')
    icon = request.form.get('icon')

    if not name:
        return to_error_json("name is required")
    elif Channel.query.filter(Channel.name == name).first() is not None:
        return to_error_json("name {} is already in use".format(name))

    channel = Channel(name=name, icon=icon)
    db.session.add(channel)
    db.session.commit()
    return jsonify(channel.dict(True))