You can now send emails if you don't use Authentication (#2718)

This commit is contained in:
Joe Milazzo 2024-02-14 14:36:55 -06:00 committed by GitHub
parent 2d81527bd1
commit 7b7609652c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
42 changed files with 414 additions and 350 deletions

View file

@ -1,6 +1,9 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using API.DTOs;
using API.Entities;
using API.Entities.Enums;
using API.Services.Tasks.Scanner.Parser;
@ -26,13 +29,52 @@ public static class VolumeListExtensions
return volumes.MinBy(x => x.MinNumber);
}
if (volumes.Any(x => x.MinNumber != 0f)) // TODO: Refactor this so we can avoid a magic number
if (volumes.HasAnyNonLooseLeafVolumes())
{
return volumes.OrderBy(x => x.MinNumber).FirstOrDefault(x => x.MinNumber != 0);
return volumes.FirstNonLooseLeafOrDefault();
}
// We only have 1 volume of chapters, we need to be cautious if there are specials, as we don't want to order them first
return volumes.MinBy(x => x.MinNumber);
}
/// <summary>
/// If the collection of volumes has any non-loose leaf volumes
/// </summary>
/// <param name="volumes"></param>
/// <returns></returns>
public static bool HasAnyNonLooseLeafVolumes(this IEnumerable<Volume> volumes)
{
return volumes.Any(x => Math.Abs(x.MinNumber - Parser.DefaultChapterNumber) > 0.001f);
}
/// <summary>
/// Returns first non-loose leaf volume
/// </summary>
/// <param name="volumes"></param>
/// <returns></returns>
public static Volume? FirstNonLooseLeafOrDefault(this IEnumerable<Volume> volumes)
{
return volumes.OrderBy(x => x.MinNumber).FirstOrDefault(v => Math.Abs(v.MinNumber - Parser.DefaultChapterNumber) >= 0.001f);
}
/// <summary>
/// Returns the first (and only) loose leaf volume or null if none
/// </summary>
/// <param name="volumes"></param>
/// <returns></returns>
public static Volume? GetLooseLeafVolumeOrDefault(this IEnumerable<Volume> volumes)
{
return volumes.FirstOrDefault(v => Math.Abs(v.MinNumber - Parser.DefaultChapterNumber) < 0.001f);
}
public static IEnumerable<VolumeDto> WhereNotLooseLeaf(this IEnumerable<VolumeDto> volumes)
{
return volumes.Where(v => Math.Abs(v.MinNumber - Parser.DefaultChapterNumber) >= 0.001f);
}
public static IEnumerable<VolumeDto> WhereLooseLeaf(this IEnumerable<VolumeDto> volumes)
{
return volumes.Where(v => Math.Abs(v.MinNumber - Parser.DefaultChapterNumber) < 0.001f);
}
}