Remove old watched episode and comment out usless people implementation

This commit is contained in:
Zoe Roux 2023-11-28 18:15:30 +01:00
parent 070a94d87d
commit 8ea8d3ff57
9 changed files with 86 additions and 153 deletions

View File

@ -125,10 +125,10 @@ namespace Kyoo.Abstractions.Models
/// </summary> /// </summary>
[LoadableRelation(nameof(StudioId))] public Studio? Studio { get; set; } [LoadableRelation(nameof(StudioId))] public Studio? Studio { get; set; }
/// <summary> // /// <summary>
/// The list of people that made this show. // /// The list of people that made this show.
/// </summary> // /// </summary>
[SerializeIgnore] public ICollection<PeopleRole>? People { get; set; } // [SerializeIgnore] public ICollection<PeopleRole>? People { get; set; }
/// <summary> /// <summary>
/// The list of collections that contains this show. /// The list of collections that contains this show.
@ -147,11 +147,11 @@ namespace Kyoo.Abstractions.Models
/// <inheritdoc /> /// <inheritdoc />
public void OnMerge(object merged) public void OnMerge(object merged)
{ {
if (People != null) // if (People != null)
{ // {
foreach (PeopleRole link in People) // foreach (PeopleRole link in People)
link.Movie = this; // link.Movie = this;
} // }
} }
public Movie() { } public Movie() { }

View File

@ -128,10 +128,10 @@ namespace Kyoo.Abstractions.Models
/// </summary> /// </summary>
[LoadableRelation(nameof(StudioId))] public Studio? Studio { get; set; } [LoadableRelation(nameof(StudioId))] public Studio? Studio { get; set; }
/// <summary> // /// <summary>
/// The list of people that made this show. // /// The list of people that made this show.
/// </summary> // /// </summary>
[SerializeIgnore] public ICollection<PeopleRole>? People { get; set; } // [SerializeIgnore] public ICollection<PeopleRole>? People { get; set; }
/// <summary> /// <summary>
/// The different seasons in this show. If this is a movie, this list is always null or empty. /// The different seasons in this show. If this is a movie, this list is always null or empty.
@ -181,11 +181,11 @@ namespace Kyoo.Abstractions.Models
/// <inheritdoc /> /// <inheritdoc />
public void OnMerge(object merged) public void OnMerge(object merged)
{ {
if (People != null) // if (People != null)
{ // {
foreach (PeopleRole link in People) // foreach (PeopleRole link in People)
link.Show = this; // link.Show = this;
} // }
if (Seasons != null) if (Seasons != null)
{ {

View File

@ -69,18 +69,6 @@ namespace Kyoo.Abstractions.Models
/// </summary> /// </summary>
public Image? Logo { get; set; } public Image? Logo { get; set; }
/// <summary>
/// The list of shows the user has finished.
/// </summary>
[SerializeIgnore]
public ICollection<Show>? Watched { get; set; }
/// <summary>
/// The list of episodes the user is watching (stopped in progress or the next episode of the show)
/// </summary>
[SerializeIgnore]
public ICollection<WatchedEpisode>? CurrentlyWatching { get; set; }
public User() { } public User() { }
[JsonConstructor] [JsonConstructor]

View File

@ -1,46 +0,0 @@
// Kyoo - A portable and vast media library solution.
// Copyright (c) Kyoo.
//
// See AUTHORS.md and LICENSE file in the project root for full license information.
//
// Kyoo is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// Kyoo is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
namespace Kyoo.Abstractions.Models
{
/// <summary>
/// Metadata of episode currently watching by an user
/// </summary>
public class WatchedEpisode
{
/// <summary>
/// The ID of the user that started watching this episode.
/// </summary>
public int UserID { get; set; }
/// <summary>
/// The ID of the episode started.
/// </summary>
public int EpisodeID { get; set; }
/// <summary>
/// The <see cref="Episode"/> started.
/// </summary>
public Episode? Episode { get; set; }
/// <summary>
/// Where the player has stopped watching the episode (between 0 and 100).
/// </summary>
public int WatchedPercentage { get; set; }
}
}

View File

@ -94,16 +94,16 @@ namespace Kyoo.Core.Controllers
resource.StudioId = resource.Studio.Id; resource.StudioId = resource.Studio.Id;
} }
if (resource.People != null) // if (resource.People != null)
{ // {
foreach (PeopleRole role in resource.People) // foreach (PeopleRole role in resource.People)
{ // {
role.People = _database.LocalEntity<People>(role.People.Slug) // role.People = _database.LocalEntity<People>(role.People.Slug)
?? await _people.CreateIfNotExists(role.People); // ?? await _people.CreateIfNotExists(role.People);
role.PeopleID = role.People.Id; // role.PeopleID = role.People.Id;
_database.Entry(role).State = EntityState.Added; // _database.Entry(role).State = EntityState.Added;
} // }
} // }
} }
/// <inheritdoc /> /// <inheritdoc />
@ -117,11 +117,11 @@ namespace Kyoo.Core.Controllers
resource.Studio = changed.Studio; resource.Studio = changed.Studio;
} }
if (changed.People != null) // if (changed.People != null)
{ // {
await Database.Entry(resource).Collection(x => x.People!).LoadAsync(); // await Database.Entry(resource).Collection(x => x.People!).LoadAsync();
resource.People = changed.People; // resource.People = changed.People;
} // }
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -95,16 +95,16 @@ namespace Kyoo.Core.Controllers
resource.StudioId = resource.Studio.Id; resource.StudioId = resource.Studio.Id;
} }
if (resource.People != null) // if (resource.People != null)
{ // {
foreach (PeopleRole role in resource.People) // foreach (PeopleRole role in resource.People)
{ // {
role.People = _database.LocalEntity<People>(role.People.Slug) // role.People = _database.LocalEntity<People>(role.People.Slug)
?? await _people.CreateIfNotExists(role.People); // ?? await _people.CreateIfNotExists(role.People);
role.PeopleID = role.People.Id; // role.PeopleID = role.People.Id;
_database.Entry(role).State = EntityState.Added; // _database.Entry(role).State = EntityState.Added;
} // }
} // }
} }
/// <inheritdoc /> /// <inheritdoc />
@ -118,11 +118,11 @@ namespace Kyoo.Core.Controllers
resource.Studio = changed.Studio; resource.Studio = changed.Studio;
} }
if (changed.People != null) // if (changed.People != null)
{ // {
await Database.Entry(resource).Collection(x => x.People!).LoadAsync(); // await Database.Entry(resource).Collection(x => x.People!).LoadAsync();
resource.People = changed.People; // resource.People = changed.People;
} // }
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -166,7 +166,7 @@ namespace Kyoo.Core.Api
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<T>> Edit([FromBody] T resource) public async Task<ActionResult<T>> Edit([FromBody] T resource)
{ {
if (resource.Id != null) if (resource.Id != Guid.Empty)
return await Repository.Edit(resource); return await Repository.Edit(resource);
T old = await Repository.Get(resource.Slug); T old = await Repository.Get(resource.Slug);

View File

@ -33,28 +33,28 @@ namespace Kyoo.Core.Api
/// <inheritdoc /> /// <inheritdoc />
public override void WriteJson(JsonWriter writer, PeopleRole? value, JsonSerializer serializer) public override void WriteJson(JsonWriter writer, PeopleRole? value, JsonSerializer serializer)
{ {
if (value == null) // if (value == null)
{ // {
writer.WriteNull(); // writer.WriteNull();
return; // return;
} // }
//
ICollection<PeopleRole>? oldPeople = value.Show?.People; // ICollection<PeopleRole>? oldPeople = value.Show?.People;
ICollection<PeopleRole>? oldRoles = value.People?.Roles; // ICollection<PeopleRole>? oldRoles = value.People?.Roles;
if (value.Show != null) // if (value.Show != null)
value.Show.People = null; // value.Show.People = null;
if (value.People != null) // if (value.People != null)
value.People.Roles = null; // value.People.Roles = null;
//
JObject obj = JObject.FromObject((value.ForPeople ? value.People : value.Show)!, serializer); // JObject obj = JObject.FromObject((value.ForPeople ? value.People : value.Show)!, serializer);
obj.Add("role", value.Role); // obj.Add("role", value.Role);
obj.Add("type", value.Type); // obj.Add("type", value.Type);
obj.WriteTo(writer); // obj.WriteTo(writer);
//
if (value.Show != null) // if (value.Show != null)
value.Show.People = oldPeople; // value.Show.People = oldPeople;
if (value.People != null) // if (value.People != null)
value.People.Roles = oldRoles; // value.People.Roles = oldRoles;
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -72,10 +72,10 @@ namespace Kyoo.Postgresql
/// </summary> /// </summary>
public DbSet<Episode> Episodes { get; set; } public DbSet<Episode> Episodes { get; set; }
/// <summary> // /// <summary>
/// All people of Kyoo. See <see cref="People"/>. // /// All people of Kyoo. See <see cref="People"/>.
/// </summary> // /// </summary>
public DbSet<People> People { get; set; } // public DbSet<People> People { get; set; }
/// <summary> /// <summary>
/// All studios of Kyoo. See <see cref="Studio"/>. /// All studios of Kyoo. See <see cref="Studio"/>.
@ -87,10 +87,10 @@ namespace Kyoo.Postgresql
/// </summary> /// </summary>
public DbSet<User> Users { get; set; } public DbSet<User> Users { get; set; }
/// <summary> // /// <summary>
/// All people's role. See <see cref="PeopleRole"/>. // /// All people's role. See <see cref="PeopleRole"/>.
/// </summary> // /// </summary>
public DbSet<PeopleRole> PeopleRoles { get; set; } // public DbSet<PeopleRole> PeopleRoles { get; set; }
/// <summary> /// <summary>
/// Add a many to many link between two resources. /// Add a many to many link between two resources.
@ -243,9 +243,8 @@ namespace Kyoo.Postgresql
.Ignore(x => x.PreviousEpisode) .Ignore(x => x.PreviousEpisode)
.Ignore(x => x.NextEpisode); .Ignore(x => x.NextEpisode);
modelBuilder.Entity<PeopleRole>() // modelBuilder.Entity<PeopleRole>()
.Ignore(x => x.ForPeople); // .Ignore(x => x.ForPeople);
modelBuilder.Entity<Show>() modelBuilder.Entity<Show>()
.HasMany(x => x.Seasons) .HasMany(x => x.Seasons)
.WithOne(x => x.Show) .WithOne(x => x.Show)
@ -271,17 +270,12 @@ namespace Kyoo.Postgresql
_HasManyToMany<Collection, Movie>(modelBuilder, x => x.Movies, x => x.Collections); _HasManyToMany<Collection, Movie>(modelBuilder, x => x.Movies, x => x.Collections);
_HasManyToMany<Collection, Show>(modelBuilder, x => x.Shows, x => x.Collections); _HasManyToMany<Collection, Show>(modelBuilder, x => x.Shows, x => x.Collections);
modelBuilder.Entity<User>()
.HasMany(x => x.Watched)
.WithMany("Users")
.UsingEntity(x => x.ToTable(LinkName<User, Show>()));
_HasMetadata<Collection>(modelBuilder); _HasMetadata<Collection>(modelBuilder);
_HasMetadata<Movie>(modelBuilder); _HasMetadata<Movie>(modelBuilder);
_HasMetadata<Show>(modelBuilder); _HasMetadata<Show>(modelBuilder);
_HasMetadata<Season>(modelBuilder); _HasMetadata<Season>(modelBuilder);
_HasMetadata<Episode>(modelBuilder); _HasMetadata<Episode>(modelBuilder);
_HasMetadata<People>(modelBuilder); // _HasMetadata<People>(modelBuilder);
_HasMetadata<Studio>(modelBuilder); _HasMetadata<Studio>(modelBuilder);
_HasImages<Collection>(modelBuilder); _HasImages<Collection>(modelBuilder);
@ -289,7 +283,7 @@ namespace Kyoo.Postgresql
_HasImages<Show>(modelBuilder); _HasImages<Show>(modelBuilder);
_HasImages<Season>(modelBuilder); _HasImages<Season>(modelBuilder);
_HasImages<Episode>(modelBuilder); _HasImages<Episode>(modelBuilder);
_HasImages<People>(modelBuilder); // _HasImages<People>(modelBuilder);
_HasAddedDate<Collection>(modelBuilder); _HasAddedDate<Collection>(modelBuilder);
_HasAddedDate<Movie>(modelBuilder); _HasAddedDate<Movie>(modelBuilder);
@ -300,15 +294,12 @@ namespace Kyoo.Postgresql
modelBuilder.Entity<User>().OwnsOne(x => x.Logo); modelBuilder.Entity<User>().OwnsOne(x => x.Logo);
modelBuilder.Entity<WatchedEpisode>()
.HasKey(x => new { User = x.UserID, Episode = x.EpisodeID });
modelBuilder.Entity<Collection>() modelBuilder.Entity<Collection>()
.HasIndex(x => x.Slug) .HasIndex(x => x.Slug)
.IsUnique(); .IsUnique();
modelBuilder.Entity<People>() // modelBuilder.Entity<People>()
.HasIndex(x => x.Slug) // .HasIndex(x => x.Slug)
.IsUnique(); // .IsUnique();
modelBuilder.Entity<Movie>() modelBuilder.Entity<Movie>()
.HasIndex(x => x.Slug) .HasIndex(x => x.Slug)
.IsUnique(); .IsUnique();