Cleanup of lazy loading code. Made some DTOs use init rather than set to keep it clean.

This commit is contained in:
Joseph Milazzo 2021-03-12 13:20:08 -06:00
parent 33515ad865
commit af35d8aad5
18 changed files with 103 additions and 68 deletions

View file

@ -244,6 +244,25 @@ namespace API.Data
s.UserReview = rating.Review;
}
}
public async Task<byte[]> GetVolumeCoverImageAsync(int volumeId)
{
return await _context.Volume
.Where(v => v.Id == volumeId)
.Select(v => v.CoverImage)
.AsNoTracking()
.SingleOrDefaultAsync();
}
public async Task<byte[]> GetSeriesCoverImageAsync(int seriesId)
{
return await _context.Series
.Where(s => s.Id == seriesId)
.Select(s => s.CoverImage)
.AsNoTracking()
.SingleOrDefaultAsync();
}
private async Task AddVolumeModifiers(int userId, List<VolumeDto> volumes)
{
var userProgress = await _context.AppUserProgresses

View file

@ -50,7 +50,21 @@ namespace API.Data
.Where(c => c.VolumeId == volumeId)
.ToListAsync();
}
/// <summary>
/// Returns the cover image for a chapter id.
/// </summary>
/// <param name="chapterId"></param>
/// <returns></returns>
public async Task<byte[]> GetChapterCoverImageAsync(int chapterId)
{
return await _context.Chapter
.Where(c => c.Id == chapterId)
.Select(c => c.CoverImage)
.AsNoTracking()
.SingleOrDefaultAsync();
}
public async Task<ChapterDto> GetChapterDtoAsync(int chapterId)
{