From a9fa0ad6a9d046fe14eb7175121601b239df064a Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Sun, 8 Oct 2023 21:56:04 +0200 Subject: [PATCH] =?UTF-8?q?misc:=20allow=20omitting=20the=20series=20or=20?= =?UTF-8?q?child=20group=20ids=20=E2=80=A6but=20still=20not=20both=20at=20?= =?UTF-8?q?the=20same=20time=20when=20creating=20a=20new=20group!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shoko.Server/API/v3/Models/Shoko/Group.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Shoko.Server/API/v3/Models/Shoko/Group.cs b/Shoko.Server/API/v3/Models/Shoko/Group.cs index 7aef64e40..79b9215be 100644 --- a/Shoko.Server/API/v3/Models/Shoko/Group.cs +++ b/Shoko.Server/API/v3/Models/Shoko/Group.cs @@ -158,7 +158,7 @@ public class CreateOrUpdateGroupBody /// /// All the series to put into the group. /// - public List SeriesIDs { get; set; } = new(); + public List? SeriesIDs { get; set; } = new(); /// /// All groups to put into the group as sub-groups. @@ -167,7 +167,7 @@ public class CreateOrUpdateGroupBody /// If the parent group is a sub-group of any of the groups in this /// array, then the request will be aborted. /// - public List GroupIDs { get; set; } = new(); + public List? GroupIDs { get; set; } = new(); /// /// The group's custom name. @@ -256,26 +256,26 @@ public CreateOrUpdateGroupBody(SVR_AnimeGroup group) } // Get the groups and validate the group ids. - var childGroups = GroupIDs + var childGroups = GroupIDs == null ? new() : GroupIDs .Select(groupID => RepoFactory.AnimeGroup.GetByID(groupID)) .Where(childGroup => childGroup != null) .ToList(); - if (childGroups.Count != GroupIDs.Count) + if (childGroups.Count != (GroupIDs?.Count ?? 0)) { - var unknownGroupIDs = GroupIDs + var unknownGroupIDs = GroupIDs! .Where(id => !childGroups.Any(childGroup => childGroup.AnimeGroupID == id)) .ToList(); modelState.AddModelError(nameof(GroupIDs), $"Unable to get child groups with ids \"{string.Join("\", \"", unknownGroupIDs)}\"."); } // Get the series and validate the series ids. - var seriesList = SeriesIDs + var seriesList = SeriesIDs == null ? new() : SeriesIDs .Select(id => RepoFactory.AnimeSeries.GetByID(id)) .Where(s => s != null) .ToList(); - if (seriesList.Count != SeriesIDs.Count) + if (seriesList.Count != (SeriesIDs?.Count ?? 0)) { - var unknownSeriesIDs = SeriesIDs + var unknownSeriesIDs = SeriesIDs! .Where(id => !seriesList.Any(series => series.AnimeSeriesID == id)) .ToList(); modelState.AddModelError(nameof(SeriesIDs), $"Unable to get series with ids \"{string.Join("\", \"", unknownSeriesIDs)}\".");