Refactored ScanLibrary to accept and library id rather than DTO. Refactored ScanLibrary to use Task.Run() rather than having synchronous repo methods.

This commit is contained in:
Joseph Milazzo 2021-01-02 12:48:48 -06:00
parent 9168e12483
commit 7b1714349d
9 changed files with 44 additions and 75 deletions

View file

@ -36,16 +36,7 @@ namespace API.Data
return _context.SaveChanges() > 0;
}
public Library GetLibraryForName(string libraryName)
{
return _context.Library
.Where(x => x.Name == libraryName)
.Include(f => f.Folders)
.Include(s => s.Series)
.Single();
}
public async Task<IEnumerable<LibraryDto>> GetLibrariesForUsernameAysnc(string userName)
public async Task<IEnumerable<LibraryDto>> GetLibrariesDtoForUsernameAsync(string userName)
{
return await _context.Library
.Include(l => l.AppUsers)
@ -53,21 +44,22 @@ namespace API.Data
.ProjectTo<LibraryDto>(_mapper.ConfigurationProvider).ToListAsync();
}
public async Task<Library> GetLibraryForNameAsync(string libraryName)
{
return await _context.Library
.Where(x => x.Name == libraryName)
.Include(f => f.Folders)
.Include(s => s.Series)
.SingleAsync();
}
public async Task<IEnumerable<LibraryDto>> GetLibrariesAsync()
{
return await _context.Library
.Include(f => f.Folders)
.ProjectTo<LibraryDto>(_mapper.ConfigurationProvider).ToListAsync();
}
public async Task<LibraryDto> GetLibraryDtoForIdAsync(int libraryId)
{
return await _context.Library
.Where(x => x.Id == libraryId)
.Include(f => f.Folders)
.ProjectTo<LibraryDto>(_mapper.ConfigurationProvider).SingleAsync();
}
public async Task<Library> GetLibraryForIdAsync(int libraryId)
{
return await _context.Library

View file

@ -46,7 +46,7 @@ namespace API.Data
return _context.Series.SingleOrDefault(x => x.Name == name);
}
public async Task<IEnumerable<SeriesDto>> GetSeriesForLibraryIdAsync(int libraryId)
public async Task<IEnumerable<SeriesDto>> GetSeriesDtoForLibraryIdAsync(int libraryId)
{
return await _context.Series
.Where(series => series.LibraryId == libraryId)
@ -54,22 +54,14 @@ namespace API.Data
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider).ToListAsync();
}
public async Task<IEnumerable<VolumeDto>> GetVolumesAsync(int seriesId)
public async Task<IEnumerable<VolumeDto>> GetVolumesDtoAsync(int seriesId)
{
return await _context.Volume
.Where(vol => vol.SeriesId == seriesId)
.OrderBy(volume => volume.Number)
.ProjectTo<VolumeDto>(_mapper.ConfigurationProvider).ToListAsync();
}
public IEnumerable<VolumeDto> GetVolumesDto(int seriesId)
{
return _context.Volume
.Where(vol => vol.SeriesId == seriesId)
.OrderBy(vol => vol.Number)
.ProjectTo<VolumeDto>(_mapper.ConfigurationProvider).ToList();
}
public IEnumerable<Volume> GetVolumes(int seriesId)
{
return _context.Volume
@ -78,7 +70,7 @@ namespace API.Data
.ToList();
}
public async Task<SeriesDto> GetSeriesByIdAsync(int seriesId)
public async Task<SeriesDto> GetSeriesDtoByIdAsync(int seriesId)
{
return await _context.Series.Where(x => x.Id == seriesId)
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider).SingleAsync();