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:
parent
9168e12483
commit
7b1714349d
9 changed files with 44 additions and 75 deletions
|
|
@ -70,8 +70,9 @@ namespace API.Controllers
|
|||
|
||||
|
||||
if (await _userRepository.SaveAllAsync())
|
||||
{
|
||||
//TODO: Enqueue scan library task
|
||||
{
|
||||
var createdLibrary = await _libraryRepository.GetLibraryForNameAsync(library.Name);
|
||||
BackgroundJob.Enqueue(() => _directoryService.ScanLibrary(createdLibrary.Id));
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
|
@ -128,27 +129,22 @@ namespace API.Controllers
|
|||
|
||||
[Authorize(Policy = "RequireAdminRole")]
|
||||
[HttpPost("scan")]
|
||||
public async Task<ActionResult> ScanLibrary(int libraryId)
|
||||
public ActionResult ScanLibrary(int libraryId)
|
||||
{
|
||||
var library = await _libraryRepository.GetLibraryDtoForIdAsync(libraryId);
|
||||
|
||||
// We have to send a json encoded Library (aka a DTO) to the Background Job thread.
|
||||
// Because we use EF, we have circular dependencies back to Library and it will crap out
|
||||
// TODO: Refactor this to use libraryId and move Library call in method.
|
||||
BackgroundJob.Enqueue(() => _directoryService.ScanLibrary(library));
|
||||
BackgroundJob.Enqueue(() => _directoryService.ScanLibrary(libraryId));
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet("libraries-for")]
|
||||
public async Task<ActionResult<IEnumerable<LibraryDto>>> GetLibrariesForUser(string username)
|
||||
{
|
||||
return Ok(await _libraryRepository.GetLibrariesForUsernameAysnc(username));
|
||||
return Ok(await _libraryRepository.GetLibrariesDtoForUsernameAsync(username));
|
||||
}
|
||||
|
||||
[HttpGet("series")]
|
||||
public async Task<ActionResult<IEnumerable<Series>>> GetSeriesForLibrary(int libraryId)
|
||||
{
|
||||
return Ok(await _seriesRepository.GetSeriesForLibraryIdAsync(libraryId));
|
||||
return Ok(await _seriesRepository.GetSeriesDtoForLibraryIdAsync(libraryId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,13 +27,13 @@ namespace API.Controllers
|
|||
[HttpGet("{seriesId}")]
|
||||
public async Task<ActionResult<SeriesDto>> GetSeries(int seriesId)
|
||||
{
|
||||
return Ok(await _seriesRepository.GetSeriesByIdAsync(seriesId));
|
||||
return Ok(await _seriesRepository.GetSeriesDtoByIdAsync(seriesId));
|
||||
}
|
||||
|
||||
[HttpGet("volumes")]
|
||||
public async Task<ActionResult<IEnumerable<VolumeDto>>> GetVolumes(int seriesId)
|
||||
{
|
||||
return Ok(await _seriesRepository.GetVolumesAsync(seriesId));
|
||||
return Ok(await _seriesRepository.GetVolumesDtoAsync(seriesId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.DTOs;
|
||||
using API.Entities;
|
||||
using API.Extensions;
|
||||
using API.Interfaces;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
|
@ -51,7 +50,7 @@ namespace API.Controllers
|
|||
|
||||
if (user == null) return BadRequest("Could not validate user");
|
||||
|
||||
var libs = await _libraryRepository.GetLibrariesForUsernameAysnc(user.UserName);
|
||||
var libs = await _libraryRepository.GetLibrariesDtoForUsernameAsync(user.UserName);
|
||||
|
||||
return Ok(libs.Any(x => x.Id == libraryId));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue