Skip to content

Commit

Permalink
fix: validate main series for group when main series has changed
Browse files Browse the repository at this point in the history
or when you edit the group in v1
  • Loading branch information
revam committed Oct 5, 2023
1 parent a1b52b7 commit 003a32e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -2150,6 +2150,8 @@ public CL_Response<CL_AnimeGroup_User> SaveGroup(CL_AnimeGroup_Save_Request cont
grp.SortName = contract.SortName;
}

grp.ValidateMainSeries();

RepoFactory.AnimeGroup.Save(grp, true, true);

var userRecord = grp.GetUserRecord(userID);
Expand Down
34 changes: 33 additions & 1 deletion Shoko.Server/Models/SVR_AnimeGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,10 @@ public void SetMainSeries(SVR_AnimeSeries series)
// the new id instead of the old.
DefaultAnimeSeriesID = series?.AnimeSeriesID;

ValidateMainSeries();

// Reset the name/description if the group is not manually named.
if (series == null && (IsManuallyNamed == 0 || OverrideDescription == 0))
if (IsManuallyNamed == 0 || OverrideDescription == 0)
series = GetMainSeries();
if (IsManuallyNamed == 0)
GroupName = SortName = series!.GetSeriesName();
Expand All @@ -286,6 +288,36 @@ public void SetMainSeries(SVR_AnimeSeries series)
RepoFactory.AnimeGroup.Save(this, false, false);
}

public bool ValidateMainSeries()
{
var changed = false;
var allSeries = GetAllSeries(true);

// User overridden main series.
if (DefaultAnimeSeriesID.HasValue)
{
var series = allSeries.Find(series => series.AnimeSeriesID == DefaultAnimeSeriesID.Value);
if (series != null)
{
DefaultAnimeSeriesID = null;
changed = true;
}
}

// Auto selected main series.
if (MainAniDBAnimeID.HasValue)
{
var series = allSeries.Find(series => series.AniDB_ID == MainAniDBAnimeID.Value);
if (series != null)
{
MainAniDBAnimeID = null;
changed = true;
}
}

return changed;
}

public List<SVR_AnimeSeries> GetSeries(bool skipSorting = false)
{
if (skipSorting)
Expand Down

0 comments on commit 003a32e

Please sign in to comment.