From d4a922233e84b150e4da44296221c7a09dce69b7 Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Fri, 6 Oct 2023 02:51:15 +0200 Subject: [PATCH] fix: fix create/modify groups in v3 --- .../ShokoServiceImplementation_Entities.cs | 2 ++ Shoko.Server/API/v3/Controllers/SeriesController.cs | 2 ++ Shoko.Server/API/v3/Models/Shoko/Group.cs | 12 +++++------- Shoko.Server/Models/SVR_AnimeGroup.cs | 4 ++-- Shoko.Server/Models/SVR_AnimeSeries.cs | 5 ++++- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Shoko.Server/API/v1/Implementations/ShokoServiceImplementation/ShokoServiceImplementation_Entities.cs b/Shoko.Server/API/v1/Implementations/ShokoServiceImplementation/ShokoServiceImplementation_Entities.cs index 96688f016..20c73f183 100755 --- a/Shoko.Server/API/v1/Implementations/ShokoServiceImplementation/ShokoServiceImplementation_Entities.cs +++ b/Shoko.Server/API/v1/Implementations/ShokoServiceImplementation/ShokoServiceImplementation_Entities.cs @@ -2200,6 +2200,8 @@ public CL_Response MoveSeries(int animeSeriesID, int newAni ser.MoveSeries(grp); + grp.TopLevelAnimeGroup?.UpdateStatsFromTopLevel(true, true); + var anime = RepoFactory.AniDB_Anime.GetByAnimeID(ser.AniDB_ID); if (anime == null) { diff --git a/Shoko.Server/API/v3/Controllers/SeriesController.cs b/Shoko.Server/API/v3/Controllers/SeriesController.cs index 60dd2480f..666183461 100644 --- a/Shoko.Server/API/v3/Controllers/SeriesController.cs +++ b/Shoko.Server/API/v3/Controllers/SeriesController.cs @@ -1448,6 +1448,8 @@ public ActionResult MoveSeries([FromRoute] int seriesID, [FromRoute] int groupID series.MoveSeries(group); + group.TopLevelAnimeGroup?.UpdateStatsFromTopLevel(true, true); + return Ok(); } diff --git a/Shoko.Server/API/v3/Models/Shoko/Group.cs b/Shoko.Server/API/v3/Models/Shoko/Group.cs index 0e9c7c92a..b93b2c40f 100644 --- a/Shoko.Server/API/v3/Models/Shoko/Group.cs +++ b/Shoko.Server/API/v3/Models/Shoko/Group.cs @@ -308,6 +308,10 @@ public CreateOrUpdateGroupBody(SVR_AnimeGroup group) if (group.AnimeGroupID == 0) RepoFactory.AnimeGroup.Save(group); + // Move the group under the new parent. + if (ParentID.HasValue) + group.AnimeGroupParentID = ParentID.Value == 0 ? null : ParentID.Value; + // Check if the names have changed if we omit the value, or if // we set it to true. if (!HasCustomName.HasValue || HasCustomName.Value) @@ -367,18 +371,12 @@ public CreateOrUpdateGroupBody(SVR_AnimeGroup group) continue; childGroup.AnimeGroupParentID = group.AnimeGroupID; - RepoFactory.AnimeGroup.Save(group, false, false); + RepoFactory.AnimeGroup.Save(childGroup, false, false); } // Move the series over to the new group. foreach (var series in seriesList) - { - // Skip adding series already part of the group. - if (series.AnimeGroupID == group.AnimeGroupID) - continue; - series.MoveSeries(group); - } // Set the main series and maybe update the group // name/description. diff --git a/Shoko.Server/Models/SVR_AnimeGroup.cs b/Shoko.Server/Models/SVR_AnimeGroup.cs index 7e1e59010..6e7f7862b 100644 --- a/Shoko.Server/Models/SVR_AnimeGroup.cs +++ b/Shoko.Server/Models/SVR_AnimeGroup.cs @@ -297,7 +297,7 @@ public bool ValidateMainSeries() if (DefaultAnimeSeriesID.HasValue) { var series = allSeries.Find(series => series.AnimeSeriesID == DefaultAnimeSeriesID.Value); - if (series != null) + if (series == null) { DefaultAnimeSeriesID = null; changed = true; @@ -308,7 +308,7 @@ public bool ValidateMainSeries() if (MainAniDBAnimeID.HasValue) { var series = allSeries.Find(series => series.AniDB_ID == MainAniDBAnimeID.Value); - if (series != null) + if (series == null) { MainAniDBAnimeID = null; changed = true; diff --git a/Shoko.Server/Models/SVR_AnimeSeries.cs b/Shoko.Server/Models/SVR_AnimeSeries.cs index 1cbbdd26f..ec50faf95 100644 --- a/Shoko.Server/Models/SVR_AnimeSeries.cs +++ b/Shoko.Server/Models/SVR_AnimeSeries.cs @@ -1539,12 +1539,15 @@ public bool Hidden public void MoveSeries(SVR_AnimeGroup newGroup) { + // Skip moving series if it's already part of the group. + if (AnimeGroupID == newGroup.AnimeGroupID) + return; + var oldGroupID = AnimeGroupID; // Update the stats for the series and group. AnimeGroupID = newGroup.AnimeGroupID; DateTimeUpdated = DateTime.Now; UpdateStats(true, true); - newGroup.TopLevelAnimeGroup?.UpdateStatsFromTopLevel(true, true); var oldGroup = RepoFactory.AnimeGroup.GetByID(oldGroupID); if (oldGroup != null)