Skip to content

Commit

Permalink
fix: fix create/modify groups in v3
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed Oct 6, 2023
1 parent 491e99a commit d4a9222
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,8 @@ public CL_Response<CL_AnimeSeries_User> 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)
{
Expand Down
2 changes: 2 additions & 0 deletions Shoko.Server/API/v3/Controllers/SeriesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,8 @@ public ActionResult MoveSeries([FromRoute] int seriesID, [FromRoute] int groupID

series.MoveSeries(group);

group.TopLevelAnimeGroup?.UpdateStatsFromTopLevel(true, true);

return Ok();
}

Expand Down
12 changes: 5 additions & 7 deletions Shoko.Server/API/v3/Models/Shoko/Group.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions Shoko.Server/Models/SVR_AnimeGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion Shoko.Server/Models/SVR_AnimeSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d4a9222

Please sign in to comment.