mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-08 18:54:22 -04:00
Fix watch status upsert
This commit is contained in:
parent
7bf3ba2443
commit
0ac4a1daa0
@ -91,6 +91,9 @@ resharper_wrap_before_arrow_with_expressions = true
|
|||||||
resharper_xmldoc_attribute_indent = align_by_first_attribute
|
resharper_xmldoc_attribute_indent = align_by_first_attribute
|
||||||
resharper_xmldoc_indent_child_elements = RemoveIndent
|
resharper_xmldoc_indent_child_elements = RemoveIndent
|
||||||
resharper_xmldoc_indent_text = RemoveIndent
|
resharper_xmldoc_indent_text = RemoveIndent
|
||||||
|
# Switch on enum
|
||||||
|
dotnet_diagnostic.CS8509.severity=error # missing switch case for named enum value
|
||||||
|
dotnet_diagnostic.CS8524.severity=none # missing switch case for unnamed enum value
|
||||||
|
|
||||||
# Waiting for https://github.com/dotnet/roslyn/issues/44596 to get fixed.
|
# Waiting for https://github.com/dotnet/roslyn/issues/44596 to get fixed.
|
||||||
# file_header_template = Kyoo - A portable and vast media library solution.\nCopyright (c) Kyoo.\n\nSee AUTHORS.md and LICENSE file in the project root for full license information.\n\nKyoo is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\nany later version.\n\nKyoo is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
# file_header_template = Kyoo - A portable and vast media library solution.\nCopyright (c) Kyoo.\n\nSee AUTHORS.md and LICENSE file in the project root for full license information.\n\nKyoo is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\nany later version.\n\nKyoo is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
@ -37,10 +37,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="$(CheckCodingStyle) == true">
|
<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" />
|
<None Include="$(MSBuildThisFileDirectory)../.editorconfig" Link=".editorconfig" Visible="false" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -24,7 +24,9 @@ namespace Kyoo.Abstractions.Models.Exceptions
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class UnauthorizedException : Exception
|
public class UnauthorizedException : Exception
|
||||||
{
|
{
|
||||||
public UnauthorizedException() { }
|
public UnauthorizedException()
|
||||||
|
: base("User not authenticated or token invalid.")
|
||||||
|
{ }
|
||||||
|
|
||||||
public UnauthorizedException(string message)
|
public UnauthorizedException(string message)
|
||||||
: base(message)
|
: base(message)
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Abstractions.Controllers;
|
using Kyoo.Abstractions.Controllers;
|
||||||
using Kyoo.Abstractions.Models;
|
using Kyoo.Abstractions.Models;
|
||||||
@ -44,6 +43,12 @@ public class WatchStatusRepository : IWatchStatusRepository
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
public const int MaxWatchPercent = 90;
|
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 DatabaseContext _database;
|
||||||
private readonly IRepository<Episode> _episodes;
|
private readonly IRepository<Episode> _episodes;
|
||||||
private readonly IRepository<Movie> _movies;
|
private readonly IRepository<Movie> _movies;
|
||||||
@ -96,7 +101,7 @@ public class WatchStatusRepository : IWatchStatusRepository
|
|||||||
PlayedDate = DateTime.UtcNow
|
PlayedDate = DateTime.UtcNow
|
||||||
};
|
};
|
||||||
await _database.MovieWatchStatus.Upsert(ret)
|
await _database.MovieWatchStatus.Upsert(ret)
|
||||||
.UpdateIf(x => !(status == WatchStatus.Watching && x.Status == WatchStatus.Completed))
|
.UpdateIf(x => status != Watching || x.Status != Completed)
|
||||||
.RunAsync();
|
.RunAsync();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -149,7 +154,7 @@ public class WatchStatusRepository : IWatchStatusRepository
|
|||||||
PlayedDate = DateTime.UtcNow
|
PlayedDate = DateTime.UtcNow
|
||||||
};
|
};
|
||||||
await _database.ShowWatchStatus.Upsert(ret)
|
await _database.ShowWatchStatus.Upsert(ret)
|
||||||
.UpdateIf(x => !(status == WatchStatus.Watching && x.Status == WatchStatus.Completed))
|
.UpdateIf(x => status != Watching || x.Status != Completed)
|
||||||
.RunAsync();
|
.RunAsync();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -207,7 +212,7 @@ public class WatchStatusRepository : IWatchStatusRepository
|
|||||||
PlayedDate = DateTime.UtcNow
|
PlayedDate = DateTime.UtcNow
|
||||||
};
|
};
|
||||||
await _database.EpisodeWatchStatus.Upsert(ret)
|
await _database.EpisodeWatchStatus.Upsert(ret)
|
||||||
.UpdateIf(x => !(status == WatchStatus.Watching && x.Status == WatchStatus.Completed))
|
.UpdateIf(x => status != Watching || x.Status != Completed)
|
||||||
.RunAsync();
|
.RunAsync();
|
||||||
await SetShowStatus(episode.ShowId, userId, WatchStatus.Watching);
|
await SetShowStatus(episode.ShowId, userId, WatchStatus.Watching);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -62,7 +62,7 @@ namespace Kyoo.Core
|
|||||||
context.Result = new ConflictObjectResult(new RequestError("Duplicated item"));
|
context.Result = new ConflictObjectResult(new RequestError("Duplicated item"));
|
||||||
break;
|
break;
|
||||||
case UnauthorizedException ex:
|
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;
|
break;
|
||||||
case Exception ex:
|
case Exception ex:
|
||||||
_logger.LogError(ex, "Unhandled error");
|
_logger.LogError(ex, "Unhandled error");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user