/// <summary> /// Gets a page of videos for a particular user. /// </summary> public async Task<UserVideos> GetUserVideos(GetUserVideos getVideos) { // Figure out if we're getting first page or subsequent page PreparedStatement preparedStatement; IStatement boundStatement; if (getVideos.FirstVideoOnPageAddedDate.HasValue && getVideos.FirstVideoOnPageVideoId.HasValue) { preparedStatement = await _statementCache.NoContext.GetOrAddAsync( "SELECT * FROM user_videos WHERE userid = ? AND (added_date, videoid) <= (?, ?) LIMIT ?"); boundStatement = preparedStatement.Bind(getVideos.UserId, getVideos.FirstVideoOnPageAddedDate.Value, getVideos.FirstVideoOnPageVideoId.Value, getVideos.PageSize); } else { preparedStatement = await _statementCache.NoContext.GetOrAddAsync("SELECT * FROM user_videos WHERE userid = ? LIMIT ?"); boundStatement = preparedStatement.Bind(getVideos.UserId, getVideos.PageSize); } RowSet rows = await _session.ExecuteAsync(boundStatement).ConfigureAwait(false); return new UserVideos { UserId = getVideos.UserId, Videos = rows.Select(MapRowToVideoPreview).ToList() }; }
/// <summary> /// Gets a page of videos for a particular user. /// </summary> public async Task<UserVideos> GetUserVideos(GetUserVideos getVideos) { // Figure out if we're getting first page or subsequent page PreparedStatement preparedStatement = await _statementCache.NoContext.GetOrAddAsync("SELECT * FROM user_videos WHERE userid = ?"); IStatement boundStatement = preparedStatement.Bind(getVideos.UserId) .SetAutoPage(false) .SetPageSize(getVideos.PageSize); // The initial query won't have a paging state, but subsequent calls should if there are more pages if (string.IsNullOrEmpty(getVideos.PagingState) == false) boundStatement.SetPagingState(Convert.FromBase64String(getVideos.PagingState)); RowSet rows = await _session.ExecuteAsync(boundStatement).ConfigureAwait(false); return new UserVideos { UserId = getVideos.UserId, Videos = rows.Select(MapRowToVideoPreview).ToList(), PagingState = rows.PagingState != null && rows.PagingState.Length > 0 ? Convert.ToBase64String(rows.PagingState) : null }; }