예제 #1
0
async def add_movie(movieIn: MovieIn):
    newId = [
        x["id"]
        for i, x in enumerate(fake_movie_db) if i == len(fake_movie_db) - 1
    ][0] + 1
    fake_movie_db.append({**movieIn.dict(), "id": id})
    return newId
예제 #2
0
async def add_movie(payload: MovieIn):
    for cast_id in payload.casts_id:
        if not is_cast_present(cast_id):
            raise HTTPException(status_code=404,
                                detail=f'Cast with id:{cast_id} not found')
    movie_id = await db_manager.add_movie(payload)
    response = {'id': movie_id, **payload.dict()}
    return response
예제 #3
0
async def update_movie(id: int, payload: MovieIn):
    query = (
        movies
        .update()
        .where(movies.c.id == id)
        .values(**payload.dict())
    )
    return await database.execute(query=query)
예제 #4
0
async def update_movie(id: int, payload: MovieIn):
    movie = await db_manager.get_movie(id)
    if not movie:
        raise HTTPException(status_code=404, detail="Movie not found")
    update_data = payload.dict(exclude_unset=True)
    movie_in_db = MovieIn(**movie)
    updated_movie = movie_in_db.copy(update=update_data)
    return await db_manager.update_movie(id, updated_movie)
예제 #5
0
async def update_movie(id: int, payload: MovieIn):
    movie = await db_manager.get_movie(id)
    if not movie:
        raise HTTPException(status_code=404, detail="Movie not found")

    update_data = payload.dict(exclude_unset=True)

    if 'casts_id' in update_data:
        for cast_id in payload.casts_id:
            if not is_cast_present(cast_id):
                raise HTTPException(
                    status_code=404,
                    detail=f"Cast with given id:{cast_id} not found")

    movie_in_db = MovieIn(**movie)

    updated_movie = movie_in_db.copy(update=update_data)
    return await db_manager.update_movie(id, updated_movie)
async def update_movie(id: int, payload: MovieIn):
    movie = payload.dict()
    fake_movie_db[id] = movie
    return None
async def add_movie(payload: MovieIn):
    movie_id = await db_manager.add_movie(payload)
    response = {'id': movie_id, **payload.dict()}

    return response
예제 #8
0
async def add_movie(payload: MovieIn):
    query = movies.insert().values(**payload.dict())

    return await database.execute(query=query)
예제 #9
0
async def update_movie(id: int, payload: MovieIn):
    query = (movies.update().where(movies.c.id == id).values(**payload.dict()))
    await database.execute(query=query)
    modified_movie = movies.select(movies.c.id == id)
    return await database.fetch_one(query=modified_movie)
예제 #10
0
async def add_movie(payload: MovieIn):
    newId = await db_manager.add_movie(payload)
    return {**payload.dict(), "id":newId}
예제 #11
0
async def update_movie(id: int, movieIn: MovieIn):
    index = [i for i, x in enumerate(fake_movie_db) if x["id"] == id][0]
    response = {**movieIn.dict(), "id": id}
    fake_movie_db[index] = response
    return response