Exemple #1
0
async def test_protected_user(
        test: str,
        token_object: JWTBearer = Depends(JWTBearer()),
        db: Session = Depends(get_db)
):
    payload = token_object.get_payload()
    # user = db.query(User).filter(User.email == payload['user_id']).first()
    user = crud_user.get_user_from_payload(db=db, payload=payload)
    return {'AUTORIZED_user': user, 'test_string': test}
Exemple #2
0
async def get_rcm_rating_based_last(token: JWTBearer = Depends(JWTBearer()), db: Session = Depends(get_db)):
    """ Return rcmmnd list based on movie rating for last watched movie by user"""
    user = crud_user.get_user_from_payload(db=db, payload=token.get_payload())
    latest_watched_movie_id = crud_movie.latest_movie_id_watched_by_user(db=db, user_id=user.id)
    recommended_id_list = rcmmnd.based_on_ratings(movie_id=latest_watched_movie_id, no_of_movies=15)

    latest_watched_movie = crud_movie.get_movie(db=db, movie_id=latest_watched_movie_id)
    recommended_movie_list = crud_movie.get_movies_by_list_id(db=db, movie_id_list=recommended_id_list)

    return {
        'latest_movie': latest_watched_movie,
        'recommended_list': recommended_movie_list
    }
Exemple #3
0
async def read_movie_with_rating(
        movie_id: int,
        token: JWTBearer = Depends(JWTBearer()),
        db: Session = Depends(get_db)
):
    """ GET: Return specific movie by id with user rate - authentication required """
    user = crud_user.get_user_from_payload(payload=token.get_payload(), db=db)
    movie_tuple = crud_movie.get_movie_with_rate(db, movie_id, user.id)

    if movie_tuple:
        # convert tuple to movie schema
        i_movie, i_rate = movie_tuple
        db_movie = MovieSchema.from_orm(i_movie)
        db_movie.user_rating = i_rate
        return db_movie
    else:
        return None
Exemple #4
0
async def search_movies_with_rates_attached(
        req_search_str: str,
        token: JWTBearer = Depends(JWTBearer()),
        db: Session = Depends(get_db)
):
    """ Searches for movies by title with user ratings attached """
    user = crud_user.get_user_from_payload(db=db, payload=token.get_payload())
    movies_rate_tuple = await crud_movie.search_movies_by_title_with_rate(db=db, search_string=req_search_str,
                                                                          user_id=user.id)

    # convert list of tuple to list with movie schemas
    movies_with_user_rate = []
    for i_movie, i_rate in movies_rate_tuple:
        movie = MovieSchema.from_orm(i_movie)
        movie.user_rating = i_rate
        movies_with_user_rate.append(movie)

    return movies_with_user_rate
Exemple #5
0
async def get_rcm_collaborative_filtering(token: JWTBearer = Depends(JWTBearer()), db: Session = Depends(get_db)):
    """ Return rcmmnd list based on similarity between users """
    user = crud_user.get_user_from_payload(db=db, payload=token.get_payload())
    recommended_id_list = rcmmnd.collaborative_filtering(user_id=user.id, no_of_movies=15)
    recommended_movie_list = crud_movie.get_movies_by_list_id(db=db, movie_id_list=recommended_id_list)
    return recommended_movie_list