-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
12 changed files
with
206 additions
and
2 deletions.
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
44 changes: 44 additions & 0 deletions
44
src/FairPlayCombinedSln/FairPlayCombined.DataAccess/Models/FairPlayTube/VideoWatchTime.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,44 @@ | ||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated> | ||
#nullable disable | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using Microsoft.EntityFrameworkCore; | ||
using FairPlayCombined.DataAccess.Models.dboSchema; | ||
using FairPlayCombined.DataAccess.Models.FairPlayBudgetSchema; | ||
using FairPlayCombined.DataAccess.Models.FairPlayDatingSchema; | ||
using FairPlayCombined.DataAccess.Models.FairPlayShopSchema; | ||
using FairPlayCombined.DataAccess.Models.FairPlaySocialSchema; | ||
using FairPlayCombined.DataAccess.Models.FairPlayTubeSchema; | ||
|
||
|
||
namespace FairPlayCombined.DataAccess.Models.FairPlayTubeSchema; | ||
|
||
[Table("VideoWatchTime", Schema = "FairPlayTube")] | ||
[Index("SessionId", Name = "UI_VideoWatchTime_SessionId", IsUnique = true)] | ||
[Index("VideoInfoId", "SessionId", Name = "UI_VideoWatchTime_VideoInfoId_SessionId", IsUnique = true)] | ||
public partial class VideoWatchTime | ||
{ | ||
[Key] | ||
public long VideoWatchTimeId { get; set; } | ||
|
||
public long VideoInfoId { get; set; } | ||
|
||
public Guid SessionId { get; set; } | ||
|
||
public DateTimeOffset SessionStartDatetime { get; set; } | ||
|
||
public int WatchTime { get; set; } | ||
|
||
[StringLength(450)] | ||
public string WatchedByApplicationUserId { get; set; } | ||
|
||
[ForeignKey("VideoInfoId")] | ||
[InverseProperty("VideoWatchTime")] | ||
public virtual VideoInfo VideoInfo { get; set; } | ||
|
||
[ForeignKey("WatchedByApplicationUserId")] | ||
[InverseProperty("VideoWatchTime")] | ||
public virtual AspNetUsers WatchedByApplicationUser { 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
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
25 changes: 25 additions & 0 deletions
25
...layCombinedSln/FairPlayCombined.Models/FairPlayTube/VideoWatchTime/VideoWatchTimeModel.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,25 @@ | ||
using FairPlayCombined.Common.GeneratorsAttributes; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FairPlayCombined.Models.FairPlayTube.VideoWatchTime | ||
{ | ||
public class VideoWatchTimeModel: IListModel | ||
{ | ||
public long? VideoWatchTimeId { get; set; } | ||
[Required] | ||
[DeniedValues(default(long))] | ||
public long VideoInfoId { get; set; } | ||
[Required] | ||
public Guid? SessionId { get; set; }= Guid.Empty; | ||
[Required] | ||
public DateTimeOffset? SessionStartDatetime { get; set; } | ||
public int WatchTime { get; set; } | ||
[StringLength(450)] | ||
public string? WatchedByApplicationUserId { get; set; } | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/FairPlayCombinedSln/FairPlayCombined.Services/FairPlayTube/VideoWatchTimeService.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,51 @@ | ||
using FairPlayCombined.DataAccess.Data; | ||
using FairPlayCombined.DataAccess.Models.FairPlayTubeSchema; | ||
using FairPlayCombined.Models.FairPlayTube.VideoWatchTime; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FairPlayCombined.Services.FairPlayTube | ||
{ | ||
public partial class VideoWatchTimeService( | ||
IDbContextFactory<FairPlayCombinedDbContext> dbContextFactory, | ||
ILogger<VideoWatchTimeService> logger) : BaseService | ||
{ | ||
public async Task CreateVideoWatchTimeAsync(string videoId, | ||
VideoWatchTimeModel videoWatchTimeModel, | ||
CancellationToken cancellationToken) | ||
{ | ||
logger.LogInformation(message: "Start of method: {methodName}", nameof(CreateVideoWatchTimeAsync)); | ||
var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken: cancellationToken); | ||
var videoInfoEntity = await dbContext.VideoInfo.SingleAsync(p => p.VideoId == videoId, | ||
cancellationToken: cancellationToken); | ||
VideoWatchTime? entity = new() | ||
{ | ||
SessionId = videoWatchTimeModel.SessionId!.Value, | ||
SessionStartDatetime = DateTimeOffset.UtcNow, | ||
VideoInfoId = videoInfoEntity.VideoInfoId, | ||
WatchedByApplicationUserId = videoWatchTimeModel.WatchedByApplicationUserId, | ||
WatchTime = videoWatchTimeModel.WatchTime | ||
}; | ||
await dbContext.VideoWatchTime.AddAsync(entity, cancellationToken: cancellationToken); | ||
await dbContext.SaveChangesAsync(cancellationToken: cancellationToken); | ||
} | ||
public async Task UpdateVideoWatchTimeAsync(string videoId, | ||
VideoWatchTimeModel videoWatchTimeModel, | ||
CancellationToken cancellationToken) | ||
{ | ||
logger.LogInformation(message: "Start of method: {methodName}", nameof(UpdateVideoWatchTimeAsync)); | ||
var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken: cancellationToken); | ||
VideoWatchTime? entity = null; | ||
entity = await dbContext.VideoWatchTime | ||
.SingleOrDefaultAsync(p => p.SessionId == videoWatchTimeModel.SessionId, | ||
cancellationToken: cancellationToken); | ||
entity!.WatchTime = videoWatchTimeModel.WatchTime; | ||
await dbContext.SaveChangesAsync(cancellationToken: cancellationToken); | ||
} | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/FairPlayCombinedSln/FairPlayCombinedDb/FairPlayTube/Tables/VideoWatchTime.sql
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,19 @@ | ||
CREATE TABLE [FairPlayTube].[VideoWatchTime] | ||
( | ||
[VideoWatchTimeId] BIGINT NOT NULL CONSTRAINT PK_VideoWatchTime PRIMARY KEY IDENTITY, | ||
[VideoInfoId] BIGINT NOT NULL, | ||
[SessionId] UNIQUEIDENTIFIER NOT NULL, | ||
[SessionStartDatetime] DATETIMEOFFSET NOT NULL, | ||
[WatchTime] INT NOT NULL, | ||
[WatchedByApplicationUserId] NVARCHAR(450) NULL, | ||
CONSTRAINT [FK_VideoWatchTime_VideoInfo] FOREIGN KEY ([VideoInfoId]) REFERENCES [FairPlayTube].[VideoInfo]([VideoInfoId]), | ||
CONSTRAINT [FK_VideoWatchTime_AspNetUsers] FOREIGN KEY ([WatchedByApplicationUserId]) REFERENCES [dbo].[AspNetUsers]([Id]) | ||
) | ||
|
||
GO | ||
|
||
CREATE UNIQUE INDEX [UI_VideoWatchTime_SessionId] ON [FairPlayTube].[VideoWatchTime] ([SessionId]) | ||
|
||
GO | ||
|
||
CREATE UNIQUE INDEX [UI_VideoWatchTime_VideoInfoId_SessionId] ON [FairPlayTube].[VideoWatchTime] ([VideoInfoId],[SessionId]) |
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