Skip to content

Commit

Permalink
Fixed resource use. Added blocked translation menu
Browse files Browse the repository at this point in the history
  • Loading branch information
pmachapman committed Jan 18, 2023
1 parent 0ffb906 commit 55ba868
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 621 deletions.
43 changes: 43 additions & 0 deletions GoToBible.Providers/ApiProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace GoToBible.Providers;

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
Expand All @@ -22,6 +23,48 @@ namespace GoToBible.Providers;
/// <seealso cref="IProvider" />
public abstract class ApiProvider : IProvider
{
/// <summary>
/// A list of blocked translations that cause unnecessary duplicates.
/// </summary>
public static readonly ReadOnlyCollection<string> BlockedTranslations = new List<string>
{
"BibleApi-685d1470fe4d5c3b-01",
"BibleApi-6bab4d6c61b31b80-01",
"BibleApi-7142879509583d59-02",
"BibleApi-7142879509583d59-03",
"BibleApi-7142879509583d59-04",
"BibleApi-926aa5efbc5e04e2-01",
"BibleApi-9879dbb7cfe39e4d-02",
"BibleApi-9879dbb7cfe39e4d-03",
"BibleApi-9879dbb7cfe39e4d-04",
"BibleApi-bba9f40183526463-01",
"BibleApi-de4e12af7f28f599-02",
"BibleApi-f72b840c855f362c-04",
"BibliaApi-asv",
"BibliaApi-kjv",
"BibliaApi-kjv1900",
"BibliaApi-kjvapoc",
"DigitalBiblePlatformApi-AAHWBTN2ET",
"DigitalBiblePlatformApi-EN1ESV",
"DigitalBiblePlatformApi-ENGASV",
"DigitalBiblePlatformApi-ENGESH",
"DigitalBiblePlatformApi-ENGKJV",
"DigitalBiblePlatformApi-ENGREV",
"DigitalBiblePlatformApi-ENGWEB",
}.AsReadOnly();

/// <summary>
/// Name substitutions to help users of the web application.
/// </summary>
public static readonly IReadOnlyDictionary<string, string> NameSubstitutions = new Dictionary<string, string>
{
{ "The Holy Bible, American Standard Version", "American Standard Version" },
{ "English Standard Version®", "English Standard Version (2007)" },
{ "New American Standard Bible (NASB)", "New American Standard Bible (1995)" },
{ "King James (Authorised) Version (Ecumenical)", "King James Version" },
{ "TCENT", "Text-Critical English New Testament" },
};

/// <summary>
/// A map of the Bible book codes to the Passage Reference book names.
/// </summary>
Expand Down
9 changes: 1 addition & 8 deletions GoToBible.Providers/BookHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,7 @@ public ChapterReference GetNextChapter(string book, int chapter)
public int GetNumberOfChapters(string book)
{
string bookLower = book.ToLowerInvariant();
if (this.BookChapters.Contains(bookLower) && this.BookChapters[bookLower] is int chapters)
{
return chapters;
}
else
{
return 0;
}
return this.BookChapters.Contains(bookLower) && this.BookChapters[bookLower] is int chapters ? chapters : 0;
}

/// <summary>
Expand Down
47 changes: 3 additions & 44 deletions GoToBible.Web/Server/Controllers/TranslationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
namespace GoToBible.Web.Server.Controllers;

using System.Collections.Generic;
using System.Collections.ObjectModel;
using GoToBible.Model;
using GoToBible.Providers;
using Microsoft.AspNetCore.Mvc;

/// <summary>
Expand All @@ -20,47 +20,6 @@ namespace GoToBible.Web.Server.Controllers;
[Route("[controller]")]
public class TranslationsController : ControllerBase
{
/// <summary>
/// A list of blocked translations that cause unnecessary duplicates.
/// </summary>
private static readonly ReadOnlyCollection<string> BlockedTranslations = new List<string>
{
"BibleApi-685d1470fe4d5c3b-01",
"BibleApi-6bab4d6c61b31b80-01",
"BibleApi-7142879509583d59-02",
"BibleApi-7142879509583d59-03",
"BibleApi-7142879509583d59-04",
"BibleApi-926aa5efbc5e04e2-01",
"BibleApi-9879dbb7cfe39e4d-02",
"BibleApi-9879dbb7cfe39e4d-03",
"BibleApi-9879dbb7cfe39e4d-04",
"BibleApi-bba9f40183526463-01",
"BibleApi-de4e12af7f28f599-02",
"BibleApi-f72b840c855f362c-04",
"BibliaApi-asv",
"BibliaApi-kjv",
"BibliaApi-kjv1900",
"BibliaApi-kjvapoc",
"DigitalBiblePlatformApi-AAHWBTN2ET",
"DigitalBiblePlatformApi-EN1ESV",
"DigitalBiblePlatformApi-ENGASV",
"DigitalBiblePlatformApi-ENGESH",
"DigitalBiblePlatformApi-ENGKJV",
"DigitalBiblePlatformApi-ENGREV",
"DigitalBiblePlatformApi-ENGWEB",
}.AsReadOnly();

/// <summary>
/// Name substitutions to help users of the web application.
/// </summary>
private static readonly IReadOnlyDictionary<string, string> NameSubstitutions = new Dictionary<string, string>
{
{ "The Holy Bible, American Standard Version", "American Standard Version" },
{ "English Standard Version®", "English Standard Version (2007)" },
{ "NAS New American Standard Bible", "New American Standard Bible (1995)" },
{ "King James (Authorised) Version (Ecumenical)", "King James Version" },
};

/// <summary>
/// The providers.
/// </summary>
Expand All @@ -86,13 +45,13 @@ public async IAsyncEnumerable<Translation> Get()
await foreach (Translation translation in provider.GetTranslationsAsync())
{
// Clean up any names we are displaying
if (NameSubstitutions.TryGetValue(translation.Name, out string? translationName))
if (ApiProvider.NameSubstitutions.TryGetValue(translation.Name, out string? translationName))
{
translation.Name = translationName;
}

// Make sure this isn't a blocked translation
if (!BlockedTranslations.Contains($"{translation.Provider}-{translation.Code}"))
if (!ApiProvider.BlockedTranslations.Contains($"{translation.Provider}-{translation.Code}"))
{
yield return translation;
}
Expand Down
Loading

0 comments on commit 55ba868

Please sign in to comment.