-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
162 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/FairPlayCombinedSln/FairPlayCombined.Models/FairPlayTube/VideoViewer/VideoViewerModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FairPlayCombined.Models.FairPlayTube.VideoViewer | ||
{ | ||
public class VideoViewerModel | ||
{ | ||
public string? VideoId { get; set; } | ||
public string? VideoName { get; set; } | ||
public string? Username { get; set; } | ||
public long TotalSessions { get; set; } | ||
public double TotalTimeWatched { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/FairPlayCombinedSln/FairPlayCombined.Services/FairPlayTube/VideoViewerService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using FairPlayCombined.DataAccess.Data; | ||
using FairPlayCombined.Models.FairPlayTube.VideoInfo; | ||
using FairPlayCombined.Models.FairPlayTube.VideoViewer; | ||
using FairPlayCombined.Models.Pagination; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Dynamic.Core; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FairPlayCombined.Services.FairPlayTube | ||
{ | ||
public partial class VideoViewerService( | ||
IDbContextFactory<FairPlayCombinedDbContext> dbContextFactory, | ||
ILogger<VideoViewerService> logger) : BaseService | ||
{ | ||
public async Task<PaginationOfT<VideoViewerModel>> GetPaginatedVideoViewerInfoForUserIdAsync( | ||
PaginationRequest paginationRequest, | ||
string videoId, | ||
string userId, | ||
CancellationToken cancellationToken) | ||
{ | ||
logger.LogInformation(message: "Start of method: {methodName}", nameof(GetPaginatedVideoViewerInfoForUserIdAsync)); | ||
PaginationOfT<VideoViewerModel> result = new(); | ||
var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); | ||
string orderByString = string.Empty; | ||
if (paginationRequest.SortingItems?.Length > 0) | ||
orderByString = | ||
String.Join(",", | ||
paginationRequest.SortingItems.Select(p => $"{p.PropertyName} {GetSortTypeString(p.SortType)}")); | ||
var query = dbContext.VideoWatchTime | ||
.Include(p=>p.VideoInfo) | ||
.Include(p=>p.WatchedByApplicationUser) | ||
.Where(p=>p.VideoInfo.ApplicationUserId == userId && p.VideoInfo.VideoId == videoId) | ||
.GroupBy(p=>new | ||
{ | ||
Username=p.WatchedByApplicationUser.UserName, | ||
VideoId = p.VideoInfo.VideoId, | ||
VideoName = p.VideoInfo.Name | ||
}) | ||
.OrderByDescending(p=>p.Sum(x=>x.WatchTime)) | ||
.Select(p => new VideoViewerModel | ||
{ | ||
TotalSessions = p.Count(), | ||
TotalTimeWatched = p.Sum(p=>p.WatchTime), | ||
Username = p.Key.Username, | ||
VideoId = p.Key.VideoId, | ||
VideoName = p.Key.VideoName | ||
}); | ||
if (!String.IsNullOrEmpty(orderByString)) | ||
query = query.OrderBy(orderByString); | ||
result.TotalItems = await query.CountAsync(cancellationToken); | ||
result.PageSize = paginationRequest.PageSize; | ||
result.TotalPages = (int)Math.Ceiling((decimal)result.TotalItems / result.PageSize); | ||
result.Items = await query | ||
.Skip(paginationRequest.StartIndex) | ||
.Take(paginationRequest.PageSize) | ||
.ToArrayAsync(cancellationToken); | ||
return result; | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/FairPlayCombinedSln/FairPlayTube/Components/Pages/Creator/MyVideoViewers.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
@attribute [Route($"{Constants.Routes.FairPlayTubeRoutes.CreatorRoutes.MyVideoViewers}/{{VideoId}}")] | ||
|
||
@using FairPlayCombined.Common | ||
@using FairPlayCombined.Interfaces | ||
@using FairPlayCombined.Models.FairPlayTube.VideoInfo | ||
@using FairPlayCombined.Models.FairPlayTube.VideoViewer | ||
@using FairPlayCombined.Models.Pagination | ||
@using FairPlayCombined.Services.Common | ||
@using FairPlayCombined.Services.FairPlayTube | ||
@using FairPlayTube.Components.Spinners | ||
|
||
@rendermode RenderMode.InteractiveServer | ||
@inject VideoViewerService videoViewerService | ||
@inject IUserProviderService userProviderService | ||
<PageTitle>My Video Viewers</PageTitle> | ||
|
||
<LoadingIndicator ShowSpinners="this.IsBusy"></LoadingIndicator> | ||
|
||
<div class="@ThemeConfiguration.Grids.GridContainerCss"> | ||
<FluentDataGrid ItemsProvider="ItemsProvider" Pagination="this.paginationState"> | ||
<PropertyColumn Property="@( p=> p.Username)"></PropertyColumn> | ||
<PropertyColumn Property="@( p=> p.VideoName)"></PropertyColumn> | ||
<TemplateColumn Title="@nameof(VideoViewerModel.TotalTimeWatched)"> | ||
@TimeSpan.FromSeconds(context.TotalTimeWatched) | ||
</TemplateColumn> | ||
<PropertyColumn Property="@( p=> p.TotalSessions)"></PropertyColumn> | ||
</FluentDataGrid> | ||
</div> | ||
<FluentPaginator State="this.paginationState"></FluentPaginator> | ||
|
||
@code | ||
{ | ||
[Parameter] | ||
public string? VideoId { get; set; } | ||
private bool IsBusy { get; set; } | ||
private GridItemsProvider<VideoViewerModel>? ItemsProvider; | ||
PaginationState paginationState = new() | ||
{ | ||
ItemsPerPage = Constants.Pagination.PageSize | ||
}; | ||
private CancellationTokenSource cancellationTokenSource = new(); | ||
|
||
protected override void OnInitialized() | ||
{ | ||
this.IsBusy = true; | ||
ItemsProvider = async req => | ||
{ | ||
StateHasChanged(); | ||
PaginationRequest paginationRequest = new() | ||
{ | ||
PageSize = paginationState.ItemsPerPage, | ||
StartIndex = req.StartIndex | ||
}; | ||
var items = await videoViewerService | ||
.GetPaginatedVideoViewerInfoForUserIdAsync(paginationRequest, | ||
videoId:this.VideoId!, | ||
userId: this.userProviderService!.GetCurrentUserId()!, | ||
this.cancellationTokenSource.Token); | ||
StateHasChanged(); | ||
var result = GridItemsProviderResult.From<VideoViewerModel>(items!.Items!, items.TotalItems); | ||
return result; | ||
}; | ||
this.IsBusy = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters