Some code cleanup

This commit is contained in:
Joseph Milazzo 2021-03-22 16:38:51 -05:00
parent 585e965a85
commit d73bd22db2
34 changed files with 814 additions and 383 deletions

View file

@ -10,7 +10,6 @@ using API.Extensions;
using API.Interfaces;
using API.Interfaces.Services;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

View file

@ -6,6 +6,7 @@ namespace API.Controllers
{
public class FallbackController : Controller
{
// ReSharper disable once S4487
private readonly ITaskScheduler _taskScheduler;
public FallbackController(ITaskScheduler taskScheduler)

View file

@ -1,28 +1,16 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using API.DTOs;
using System.Threading.Tasks;
using API.Extensions;
using API.Interfaces;
using API.Interfaces.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace API.Controllers
{
public class ImageController : BaseApiController
{
private readonly IDirectoryService _directoryService;
private readonly ICacheService _cacheService;
private readonly ILogger<ImageController> _logger;
private readonly IUnitOfWork _unitOfWork;
public ImageController(IDirectoryService directoryService, ICacheService cacheService,
ILogger<ImageController> logger, IUnitOfWork unitOfWork)
public ImageController(IUnitOfWork unitOfWork)
{
_directoryService = directoryService;
_cacheService = cacheService;
_logger = logger;
_unitOfWork = unitOfWork;
}

View file

@ -147,7 +147,6 @@ namespace API.Controllers
[HttpPost("scan")]
public ActionResult Scan(int libraryId)
{
// TODO: We shouldn't queue up a job if one is already in progress
_taskScheduler.ScanLibrary(libraryId);
return Ok();
}

View file

@ -35,7 +35,7 @@ namespace API.Controllers
var chapter = await _cacheService.Ensure(chapterId);
if (chapter == null) return BadRequest("There was an issue finding image file for reading");
var (path, mangaFile) = await _cacheService.GetCachedPagePath(chapter, page);
var (path, _) = await _cacheService.GetCachedPagePath(chapter, page);
if (string.IsNullOrEmpty(path) || !System.IO.File.Exists(path)) return BadRequest($"No such image for page {page}");
var content = await _directoryService.ReadFileAsync(path);
@ -53,7 +53,7 @@ namespace API.Controllers
var chapter = await _cacheService.Ensure(chapterId);
if (chapter == null) return BadRequest("There was an issue finding image file for reading");
var (path, mangaFile) = await _cacheService.GetCachedPagePath(chapter, 0);
var (_, mangaFile) = await _cacheService.GetCachedPagePath(chapter, 0);
return Ok(mangaFile.FilePath);
}

View file

@ -105,9 +105,9 @@ namespace API.Controllers
if (series == null) return BadRequest("Series does not exist");
// TODO: check if new name isn't an existing series
var existingSeries = await _unitOfWork.SeriesRepository.GetSeriesByNameAsync(updateSeries.Name); // NOTE: This isnt checking library
if (existingSeries != null && existingSeries.Id != series.Id)
// TODO: Ensure we check against Library for Series Name change
var existingSeries = await _unitOfWork.SeriesRepository.GetSeriesByNameAsync(updateSeries.Name);
if (existingSeries != null && existingSeries.Id != series.Id )
{
return BadRequest("A series already exists with this name. Name must be unique.");
}
@ -115,8 +115,7 @@ namespace API.Controllers
series.LocalizedName = updateSeries.LocalizedName;
series.SortName = updateSeries.SortName;
series.Summary = updateSeries.Summary;
//series.CoverImage = updateSeries.CoverImage;
_unitOfWork.SeriesRepository.Update(series);
if (await _unitOfWork.Complete())
@ -139,16 +138,5 @@ namespace API.Controllers
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
return Ok(await _unitOfWork.SeriesRepository.GetInProgress(user.Id, libraryId, limit));
}
[HttpGet("continue-reading")]
public async Task<ActionResult<IEnumerable<SeriesDto>>> GetContinueReading(int libraryId = 0, int limit = 20)
{
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
return Ok(await _unitOfWork.VolumeRepository.GetContinueReading(user.Id, libraryId, limit));
}
}
}

View file

@ -21,17 +21,15 @@ namespace API.Controllers
private readonly IConfiguration _config;
private readonly IDirectoryService _directoryService;
private readonly IBackupService _backupService;
private readonly ITaskScheduler _taskScheduler;
public ServerController(IHostApplicationLifetime applicationLifetime, ILogger<ServerController> logger, IConfiguration config,
IDirectoryService directoryService, IBackupService backupService, ITaskScheduler taskScheduler)
IDirectoryService directoryService, IBackupService backupService)
{
_applicationLifetime = applicationLifetime;
_logger = logger;
_config = config;
_directoryService = directoryService;
_backupService = backupService;
_taskScheduler = taskScheduler;
}
[HttpPost("restart")]

View file

@ -10,7 +10,6 @@ using API.Helpers.Converters;
using API.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
@ -110,7 +109,7 @@ namespace API.Controllers
[HttpGet("log-levels")]
public ActionResult<IEnumerable<string>> GetLogLevels()
{
return Ok(new string[] {"Trace", "Debug", "Information", "Warning", "Critical", "None"});
return Ok(new [] {"Trace", "Debug", "Information", "Warning", "Critical", "None"});
}
}
}