mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-05-22 07:02:27 -04:00
Fix watch status upsert
This commit is contained in:
@@ -37,10 +37,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="$(CheckCodingStyle) == true">
|
||||
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.354" PrivateAssets="All" />
|
||||
|
||||
<AdditionalFiles Include="$(MSBuildThisFileDirectory)../stylecop.json" Link="stylecop.json" Visible="false" />
|
||||
<None Include="$(MSBuildThisFileDirectory)../.editorconfig" Link=".editorconfig" Visible="false" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -24,7 +24,9 @@ namespace Kyoo.Abstractions.Models.Exceptions
|
||||
[Serializable]
|
||||
public class UnauthorizedException : Exception
|
||||
{
|
||||
public UnauthorizedException() { }
|
||||
public UnauthorizedException()
|
||||
: base("User not authenticated or token invalid.")
|
||||
{ }
|
||||
|
||||
public UnauthorizedException(string message)
|
||||
: base(message)
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
using Kyoo.Abstractions.Models;
|
||||
@@ -44,6 +43,12 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
/// </remarks>
|
||||
public const int MaxWatchPercent = 90;
|
||||
|
||||
// Those two are defined here because x => WatchingStatus.Watching complies to x => 1
|
||||
// but x => Watching compiles to x => Convert.ToInt(WatchingStatus.Watching)
|
||||
// The second one can be converted to sql wherase the first can't (tries to compare WatchStatus with int).
|
||||
private WatchStatus Watching = WatchStatus.Watching;
|
||||
private WatchStatus Completed = WatchStatus.Completed;
|
||||
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly IRepository<Episode> _episodes;
|
||||
private readonly IRepository<Movie> _movies;
|
||||
@@ -96,7 +101,7 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
PlayedDate = DateTime.UtcNow
|
||||
};
|
||||
await _database.MovieWatchStatus.Upsert(ret)
|
||||
.UpdateIf(x => !(status == WatchStatus.Watching && x.Status == WatchStatus.Completed))
|
||||
.UpdateIf(x => status != Watching || x.Status != Completed)
|
||||
.RunAsync();
|
||||
return ret;
|
||||
}
|
||||
@@ -149,7 +154,7 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
PlayedDate = DateTime.UtcNow
|
||||
};
|
||||
await _database.ShowWatchStatus.Upsert(ret)
|
||||
.UpdateIf(x => !(status == WatchStatus.Watching && x.Status == WatchStatus.Completed))
|
||||
.UpdateIf(x => status != Watching || x.Status != Completed)
|
||||
.RunAsync();
|
||||
return ret;
|
||||
}
|
||||
@@ -207,7 +212,7 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
PlayedDate = DateTime.UtcNow
|
||||
};
|
||||
await _database.EpisodeWatchStatus.Upsert(ret)
|
||||
.UpdateIf(x => !(status == WatchStatus.Watching && x.Status == WatchStatus.Completed))
|
||||
.UpdateIf(x => status != Watching || x.Status != Completed)
|
||||
.RunAsync();
|
||||
await SetShowStatus(episode.ShowId, userId, WatchStatus.Watching);
|
||||
return ret;
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Kyoo.Core
|
||||
context.Result = new ConflictObjectResult(new RequestError("Duplicated item"));
|
||||
break;
|
||||
case UnauthorizedException ex:
|
||||
context.Result = new UnauthorizedObjectResult(new RequestError(ex.Message ?? "User not authenticated or token invalid."));
|
||||
context.Result = new UnauthorizedObjectResult(new RequestError(ex.Message));
|
||||
break;
|
||||
case Exception ex:
|
||||
_logger.LogError(ex, "Unhandled error");
|
||||
|
||||
Reference in New Issue
Block a user