Skip to content

Commit

Permalink
more work, rethinking things
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Grinstead committed Sep 27, 2023
1 parent 40c4c8f commit c8f1df2
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 173 deletions.
23 changes: 2 additions & 21 deletions src/Aquifer.API/Modules/Bibles/BibleResponse.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
namespace Aquifer.API.Modules.Bibles;

public class OldBibleBookResponse
{
public int LanguageId { get; set; }
public string Name { get; set; } = null!;

public IEnumerable<BibleBookResponseContent> Contents { get; set; } =
new List<BibleBookResponseContent>();
}

public class OldBibleBookResponseContent
{
public int BookId { get; set; }
public string DisplayName { get; set; } = null!;
public string TextUrl { get; set; } = null!;
public object? AudioUrls { get; set; }
public int TextSize { get; set; }
public int AudioSize { get; set; }
}

public class BibleResponse
{
public int Id { get; set; }
public string Name { get; set; } = null!;
public string Abbreviation { get; set; } = null!;

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

public class BibleResponseBook
Expand Down
45 changes: 9 additions & 36 deletions src/Aquifer.API/Modules/Bibles/BiblesModule.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Aquifer.API.Utilities;
using Aquifer.Data;
using Aquifer.Data;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.EntityFrameworkCore;

Expand All @@ -9,51 +8,25 @@ public class BiblesModule : IModule
{
public IEndpointRouteBuilder MapEndpoints(IEndpointRouteBuilder endpoints)
{
var oldGroup = endpoints.MapGroup("bibles");
oldGroup.MapGet("language/{languageId:int}", GetBibleContentsByLanguage);

var group = endpoints.MapGroup("bible-versions");
group.MapGet("language/{languageId:int}", GetBibleVersionsByLanguage);
group.MapGet("language/{languageId:int}", GetBibleByLanguage);
group.MapGet("{bibleId:int}/books/{bookId:int}", GetBibleBookDetails);

return endpoints;
}

private async Task<Ok<List<BibleBookResponse>>> GetBibleContentsByLanguage(int languageId,
AquiferDbContext dbContext,
CancellationToken cancellationToken)
{
var bibles = await dbContext.Bibles.Where(x => x.LanguageId == languageId)
.Select(x => new BibleBookResponse
{
LanguageId = x.LanguageId,
Name = x.Name,
Contents = x.BibleBookContents.Select(y => new BibleBookResponseContent
{
BookId = y.BookId,
DisplayName = y.DisplayName,
TextUrl = y.TextUrl,
TextSize = y.TextSize,
AudioUrls = JsonUtilities.DefaultSerialize(y.AudioUrls),
AudioSize = y.AudioSize
})
}).ToListAsync(cancellationToken);

return TypedResults.Ok(bibles);
}

private async Task<Ok<List<BibleVersionResponse>>> GetBibleVersionsByLanguage(int languageId,
private async Task<Ok<List<BibleResponse>>> GetBibleByLanguage(int languageId,
AquiferDbContext dbContext,
CancellationToken cancellationToken)
{
var bibles = await dbContext.Bibles.Where(x => x.LanguageId == languageId)
.Select(bibleVersion => new BibleVersionResponse
.Select(bible => new BibleResponse
{
Name = bibleVersion.Name,
Abbreviation = bibleVersion.Abbreviation,
Id = bibleVersion.Id,
Books = bibleVersion.BibleBookContents.OrderBy(book => book.BookId).Select(book =>
new BibleVersionResponseBook
Name = bible.Name,
Abbreviation = bible.Abbreviation,
Id = bible.Id,
Books = bible.BibleBookContents.OrderBy(book => book.BookId).Select(book =>
new BibleResponseBook
{
BookId = book.BookId,
DisplayName = book.DisplayName,
Expand Down
43 changes: 0 additions & 43 deletions src/Aquifer.API/Modules/Passages/PassageResourcesResponse.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Aquifer.API/Modules/Passages/PassageResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public class PassageResourceResponse
public int ContentId { get; set; }

[JsonConverter(typeof(JsonStringEnumConverter))]
public ResourceEntityType TypeValue { get; set; }
public ResourceEntityType TypeName { get; set; }

[JsonConverter(typeof(JsonStringEnumConverter))]
public ResourceContentMediaType MediaTypeValue { get; set; }
public ResourceContentMediaType MediaTypeName { get; set; }

public int ContentSize { get; set; }
}
61 changes: 4 additions & 57 deletions src/Aquifer.API/Modules/Passages/PassagesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,10 @@ public class PassagesModule : IModule
public IEndpointRouteBuilder MapEndpoints(IEndpointRouteBuilder endpoints)
{
var group = endpoints.MapGroup("passages");
group.MapGet("/resources/language/{languageId:int}", GetPassageResourcesByLanguage).WithOpenApi(o => new (o) {Deprecated = true});
group.MapGet("/language/{languageId:int}", GetPassagesByLanguage);
return endpoints;
}

private async Task<Ok<List<PassageResourcesResponse>>> GetPassageResourcesByLanguage(int languageId,
AquiferDbContext dbContext,
CancellationToken cancellationToken)
{
var passageContent = (await dbContext.Passages.Select(passage =>
new PassageResourcesResponse
{
PassageStartDetails = BibleUtilities.TranslateVerseId(passage.StartVerseId),
PassageEndDetails = BibleUtilities.TranslateVerseId(passage.EndVerseId),
Resources = passage.PassageResources.Select(passageResource =>
new PassageResourcesResponseResource
{
Type = (int)passageResource.Resource.Type,
MediaType = (int)passageResource.Resource.MediaType,
EnglishLabel = passageResource.Resource.EnglishLabel,
Tag = passageResource.Resource.Tag,
Content =
passageResource.Resource.ResourceContents.Select(resourceContent =>
new PassageResourcesResponseResourceContent
{
LanguageId = resourceContent.LanguageId,
DisplayName = resourceContent.DisplayName,
Summary = resourceContent.Summary,
Content = JsonUtilities.DefaultSerialize(resourceContent.Content),
ContentSize = resourceContent.ContentSize
}).FirstOrDefault(content => content.LanguageId == languageId),
SupportingResources = passageResource.Resource.SupportingResources
.Where(sr => sr.Type != ResourceEntityType.TyndaleBibleDictionary)
.Select(supportingResource => new PassageResourcesResponseResource
{
Type = (int)supportingResource.Type,
MediaType = (int)supportingResource.MediaType,
EnglishLabel = supportingResource.EnglishLabel,
Tag = supportingResource.Tag,
Content = supportingResource.ResourceContents.Select(resourceContent =>
new PassageResourcesResponseResourceContent
{
LanguageId = resourceContent.LanguageId,
DisplayName = resourceContent.DisplayName,
Summary = resourceContent.Summary,
Content = JsonUtilities.DefaultSerialize(resourceContent.Content),
ContentSize = resourceContent.ContentSize
}).FirstOrDefault(content => content.LanguageId == languageId)
})
})
}).ToListAsync(cancellationToken))
.OrderBy(passage => passage.BookId)
.ThenBy(passage => passage.StartChapter).ThenBy(passage => passage.StartVerse).ToList();

return TypedResults.Ok(passageContent);
}

private async Task<Ok<List<PassageResponse>>> GetPassagesByLanguage(int languageId,
AquiferDbContext dbContext,
CancellationToken cancellationToken,
Expand All @@ -91,8 +38,8 @@ private async Task<Ok<List<PassageResponse>>> GetPassagesByLanguage(int language
{
ContentId = content.Id,
ContentSize = content.ContentSize,
MediaTypeValue = content.MediaType,
TypeValue = passageResource.Resource.Type
MediaTypeName = content.MediaType,
TypeName = passageResource.Resource.Type
})),
SupportingResources = passage.PassageResources.SelectMany(passageResource => passageResource
.Resource.SupportingResources
Expand All @@ -104,8 +51,8 @@ private async Task<Ok<List<PassageResponse>>> GetPassagesByLanguage(int language
{
ContentId = content.Id,
ContentSize = content.ContentSize,
MediaTypeValue = content.MediaType,
TypeValue = passageResource.Resource.Type
MediaTypeName = content.MediaType,
TypeName = passageResource.Resource.Type
})
)
}
Expand Down
17 changes: 17 additions & 0 deletions src/Aquifer.API/Modules/Resources/ResourceContentJsonSchema.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Aquifer.API.Modules.Resources;

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

public class ResourceContentAudioJsonSchema
{
public ResourceContentAudioTypeJsonSchema Webm { get; set; } = null!;
public ResourceContentAudioTypeJsonSchema Mp3 { get; set; } = null!;
}

public class ResourceContentAudioTypeJsonSchema
{
public string Url { get; set; } = null!;
}
Loading

0 comments on commit c8f1df2

Please sign in to comment.