roadie/Roadie.Api/Controllers/AdminController.cs
2019-07-03 11:21:29 -05:00

166 lines
No EOL
6.7 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Roadie.Api.Services;
using Roadie.Library.Caching;
using Roadie.Library.Configuration;
using Roadie.Library.Identity;
using System;
using System.Net;
using System.Threading.Tasks;
namespace Roadie.Api.Controllers
{
[Route("admin")]
[ApiController]
[Authorize("Admin")]
public class AdminController : EntityControllerBase
{
private IAdminService AdminService { get; }
public AdminController(IAdminService adminService, ILoggerFactory logger, ICacheManager cacheManager,
UserManager<ApplicationUser> userManager, IRoadieSettings roadieSettings)
: base(cacheManager, roadieSettings, userManager)
{
Logger = logger.CreateLogger("RoadieApi.Controllers.AdminController");
AdminService = adminService;
}
[HttpGet("clearcache")]
[ProducesResponseType(200)]
public IActionResult ClearCache()
{
CacheManager.Clear();
Logger.LogInformation("Cache Cleared");
return Ok();
}
[HttpPost("delete/artist/{id}")]
[ProducesResponseType(200)]
public async Task<IActionResult> DeleteArtist(Guid id)
{
var result = await AdminService.DeleteArtist(await UserManager.GetUserAsync(User), id);
if (!result.IsSuccess) return StatusCode((int)HttpStatusCode.InternalServerError);
return Ok(result);
}
[HttpPost("delete/artist/releases/{id}")]
[ProducesResponseType(200)]
public async Task<IActionResult> DeleteArtistReleases(Guid id)
{
var result = await AdminService.DeleteArtistReleases(await UserManager.GetUserAsync(User), id);
if (!result.IsSuccess) return StatusCode((int)HttpStatusCode.InternalServerError);
return Ok(result);
}
[HttpPost("delete/artistsecondaryimage/{id}/{index}")]
[ProducesResponseType(200)]
public async Task<IActionResult> DeleteArtistSecondaryImage(Guid id, int index)
{
var result = await AdminService.DeleteArtistSecondaryImage(await UserManager.GetUserAsync(User), id, index);
if (!result.IsSuccess) return StatusCode((int)HttpStatusCode.InternalServerError);
return Ok(result);
}
[HttpPost("delete/release/{id}")]
[ProducesResponseType(200)]
public async Task<IActionResult> DeleteRelease(Guid id, bool? doDeleteFiles)
{
var result = await AdminService.DeleteRelease(await UserManager.GetUserAsync(User), id, doDeleteFiles);
if (!result.IsSuccess) return StatusCode((int)HttpStatusCode.InternalServerError);
return Ok(result);
}
[HttpPost("delete/releasesecondaryimage/{id}/{index}")]
[ProducesResponseType(200)]
public async Task<IActionResult> DeleteReleaseSecondaryImage(Guid id, int index)
{
var result =
await AdminService.DeleteReleaseSecondaryImage(await UserManager.GetUserAsync(User), id, index);
if (!result.IsSuccess) return StatusCode((int)HttpStatusCode.InternalServerError);
return Ok(result);
}
[HttpPost("delete/track/{id}")]
[ProducesResponseType(200)]
public async Task<IActionResult> DeleteTrack(Guid id, bool? doDeleteFile)
{
var result = await AdminService.DeleteTrack(await UserManager.GetUserAsync(User), id, doDeleteFile);
if (!result.IsSuccess) return StatusCode((int)HttpStatusCode.InternalServerError);
return Ok(result);
}
[HttpPost("delete/user/{id}")]
[ProducesResponseType(200)]
public async Task<IActionResult> DeleteUser(Guid id)
{
var result = await AdminService.DeleteUser(await UserManager.GetUserAsync(User), id);
if (!result.IsSuccess) return StatusCode((int)HttpStatusCode.InternalServerError);
return Ok(result);
}
[HttpPost("missingcollectionreleases")]
[ProducesResponseType(200)]
public async Task<IActionResult> MissingCollectionReleases()
{
var result = await AdminService.MissingCollectionReleases(await UserManager.GetUserAsync(User));
if (!result.IsSuccess) return StatusCode((int)HttpStatusCode.InternalServerError);
return Ok(result);
}
[HttpPost("scan/collection/rescanall")]
[ProducesResponseType(200)]
public async Task<IActionResult> ScanAllCollections()
{
var result = await AdminService.ScanAllCollections(await UserManager.GetUserAsync(User));
if (!result.IsSuccess) return StatusCode((int)HttpStatusCode.InternalServerError);
return Ok(result);
}
[HttpPost("scan/artist/{id}")]
[ProducesResponseType(200)]
public async Task<IActionResult> ScanArtist(Guid id)
{
var result = await AdminService.ScanArtist(await UserManager.GetUserAsync(User), id);
if (!result.IsSuccess) return StatusCode((int)HttpStatusCode.InternalServerError);
return Ok(result);
}
[HttpPost("scan/collection/{id}")]
[ProducesResponseType(200)]
public async Task<IActionResult> ScanCollection(Guid id)
{
var result = await AdminService.ScanCollection(await UserManager.GetUserAsync(User), id);
if (!result.IsSuccess) return StatusCode((int)HttpStatusCode.InternalServerError);
return Ok(result);
}
[HttpGet("scan/inbound")]
[ProducesResponseType(200)]
public async Task<IActionResult> ScanInbound()
{
var result = await AdminService.ScanInboundFolder(await UserManager.GetUserAsync(User));
if (!result.IsSuccess) return StatusCode((int)HttpStatusCode.InternalServerError);
return Ok(result);
}
[HttpGet("scan/library")]
[ProducesResponseType(200)]
public async Task<IActionResult> ScanLibrary()
{
var result = await AdminService.ScanLibraryFolder(await UserManager.GetUserAsync(User));
if (!result.IsSuccess) return StatusCode((int)HttpStatusCode.InternalServerError);
return Ok(result);
}
[HttpPost("scan/release/{id}")]
[ProducesResponseType(200)]
public async Task<IActionResult> ScanRelease(Guid id)
{
var result = await AdminService.ScanRelease(await UserManager.GetUserAsync(User), id);
if (!result.IsSuccess) return StatusCode((int)HttpStatusCode.InternalServerError);
return Ok(result);
}
}
}