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 63387d8
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/Aquifer.API/Modules/Bibles/BibleResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ public class BibleResponse
public string Name { get; set; } = null!;
public string Abbreviation { get; set; } = null!;

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

public class BibleResponseBook
Expand Down
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 @@ -7,6 +7,6 @@ public class ResourceContentUrlJsonSchema

public class ResourceContentAudioJsonSchema
{
public ResourceContentUrlJsonSchema Webm { get; set; } = null!;
public ResourceContentUrlJsonSchema Mp3 { get; set; } = null!;
public ResourceContentUrlJsonSchema? Webm { get; set; } = null!;
public ResourceContentUrlJsonSchema? Mp3 { get; set; } = null!;
}
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; }
}
21 changes: 13 additions & 8 deletions src/Aquifer.API/Modules/Resources/ResourcesModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Aquifer.API.Utilities;
using Aquifer.Data;
using Aquifer.Data.Entities;
using Microsoft.ApplicationInsights;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -115,26 +116,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();
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 +157,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 63387d8

Please sign in to comment.