Skip to content

Commit

Permalink
address more feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Grinstead committed Sep 29, 2023
1 parent 03fd007 commit 9de42a3
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 28 deletions.
11 changes: 5 additions & 6 deletions src/Aquifer.API/Modules/Bibles/BibleResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
public class BibleResponse
{
public int Id { get; set; }
public string Name { get; set; } = null!;
public string Abbreviation { get; set; } = null!;
public required string Name { get; set; }
public required string Abbreviation { get; set; }

public IEnumerable<BibleResponseBook> Books { get; set; } =
new List<BibleResponseBook>();
public required IEnumerable<BibleResponseBook> Books { get; set; }
}

public class BibleResponseBook
{
public string BookCode { get; set; }
public string DisplayName { get; set; } = null!;
public required string BookCode { get; set; }
public required string DisplayName { get; set; }
public int TextSize { get; set; }
public int AudioSize { get; set; }
public int ChapterCount { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/Aquifer.API/Modules/Languages/LanguageResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public class LanguageResponse
{
public int Id { get; set; }
public string Iso6393Code { get; set; } = null!;
public string EnglishDisplay { get; set; } = null!;
public required string Iso6393Code { get; set; }
public required string EnglishDisplay { get; set; }
}
2 changes: 1 addition & 1 deletion src/Aquifer.API/Modules/Languages/LanguagesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public IEndpointRouteBuilder MapEndpoints(IEndpointRouteBuilder endpoints)
return endpoints;
}

public async Task<Ok<List<LanguageResponse>>> GetLanguages(AquiferDbContext dbContext)
private async Task<Ok<List<LanguageResponse>>> GetLanguages(AquiferDbContext dbContext)
{
var languages = await dbContext.Languages.Select(x => new LanguageResponse
{
Expand Down
4 changes: 2 additions & 2 deletions src/Aquifer.API/Modules/Passages/PassagesResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Aquifer.API.Modules.Passages;
public class PassagesBookResponse
{
public int BookId { get; set; }
public IEnumerable<PassagesResponsePassage> Passages { get; set; } = null!;
public required IEnumerable<PassagesResponsePassage> Passages { get; set; }
}

public class PassagesResponsePassage
Expand All @@ -27,7 +27,7 @@ public class PassagesResponsePassage

public class PassageDetailsResponse : PassagesResponsePassage
{
public IEnumerable<PassageDetailsResponseContent> Contents { get; set; } = null!;
public required IEnumerable<PassageDetailsResponseContent> Contents { get; set; }
}

public class PassageDetailsResponseContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ namespace Aquifer.API.Modules.Resources;

public class ResourceContentInfoForBookResponse
{
public IEnumerable<ResourceContentInfoForChapter> Chapters { get; set; } = null!;
public required IEnumerable<ResourceContentInfoForChapter> Chapters { get; set; }
}

public class ResourceContentInfoForChapter
{
public int ChapterNumber { get; set; }
public IEnumerable<ResourceContentInfo> Contents { get; set; } = null!;
public required IEnumerable<ResourceContentInfo> Contents { get; set; }
}

public class ResourceContentInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ namespace Aquifer.API.Modules.Resources;

public class ResourceContentUrlJsonSchema
{
public string Url { get; set; } = null!;
public string? Url { get; set; }
}

public class ResourceContentAudioJsonSchema
{
public ResourceContentUrlJsonSchema Webm { get; set; } = null!;
public ResourceContentUrlJsonSchema Mp3 { get; set; } = null!;
public ResourceContentUrlJsonSchema? Webm { get; set; }
public ResourceContentUrlJsonSchema? Mp3 { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public class ResourceContentMetadataResponse
{
public string DisplayName { get; set; } = null!;
public object? Additional { get; set; }
public string? DisplayName { get; set; }
public object? Metadata { get; set; }
}
31 changes: 21 additions & 10 deletions src/Aquifer.API/Modules/Resources/ResourcesModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Aquifer.API.Utilities;
using Aquifer.Data;
using Aquifer.Data.Entities;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
Expand All @@ -19,17 +21,22 @@ public IEndpointRouteBuilder MapEndpoints(IEndpointRouteBuilder endpoints)
return endpoints;
}

private async Task<Ok<ResourceContentInfoForBookResponse>> GetResourcesForBook(
private async Task<Results<Ok<ResourceContentInfoForBookResponse>, BadRequest<string>>> GetResourcesForBook(
int languageId,
int bookId,
AquiferDbContext dbContext,
CancellationToken cancellationToken,
[FromQuery] ResourceEntityType[]? resourceTypes = null
)
{
if (resourceTypes == null)
{
return TypedResults.BadRequest("resourceTypes query param must be specified");
}

var passageResourceContent = await dbContext.PassageResources
// find all passages that overlap with the current book
.Where(pr => resourceTypes != null && resourceTypes.Contains(pr.Resource.Type) &&
.Where(pr => resourceTypes.Contains(pr.Resource.Type) &&
((pr.Passage.StartVerseId > BibleUtilities.LowerBoundOfBook(bookId) &&
pr.Passage.StartVerseId < BibleUtilities.UpperBoundOfBook(bookId)) ||
(pr.Passage.EndVerseId > BibleUtilities.LowerBoundOfBook(bookId) &&
Expand Down Expand Up @@ -115,26 +122,30 @@ private async Task<Results<Ok<object>, NotFound, ProblemHttpResult, RedirectHttp
if (content.MediaType == ResourceContentMediaType.Audio)
{
var deserialized = JsonUtilities.DefaultDeserialize<ResourceContentAudioJsonSchema>(content.Content);
if (deserialized != null)
if (audioType == "webm" && deserialized.Webm != null)
{
url = audioType == "webm" ? deserialized.Webm.Url : deserialized.Mp3.Url;
url = deserialized.Webm.Url;
}
else if (deserialized.Mp3 != null)
{
url = deserialized.Mp3.Url;
}
}
else
{
var deserialized = JsonUtilities.DefaultDeserialize<ResourceContentUrlJsonSchema>(content.Content);
if (deserialized != null)
{
url = deserialized.Url;
}
url = deserialized.Url;
}

if (url != null)
{
return TypedResults.Redirect(url);
}

return TypedResults.Problem();
var telemetry = new TelemetryClient(TelemetryConfiguration.CreateDefault());
telemetry.TrackException(
new Exception($"Content with ID {contentId} exists but has unexpected `Content` JSON."));
return TypedResults.NotFound();
}

private async Task<Results<Ok<ResourceContentMetadataResponse>, NotFound>> GetResourceMetadataById(
Expand All @@ -152,7 +163,7 @@ CancellationToken cancellationToken
var response = new ResourceContentMetadataResponse
{
DisplayName = content.DisplayName,
Additional = content.MediaType == ResourceContentMediaType.Text
Metadata = content.MediaType == ResourceContentMediaType.Text
? null
: JsonUtilities.DefaultDeserialize(content.Content)
};
Expand Down

0 comments on commit 9de42a3

Please sign in to comment.