102 lines
3.9 KiB
C#
102 lines
3.9 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using RMuseum.Models.Auth.Memory;
|
|
using RMuseum.Models.PDFLibrary;
|
|
using RMuseum.Models.PDFLibrary.ViewModels;
|
|
using RMuseum.Services;
|
|
using RSecurityBackend.Models.Auth.Memory;
|
|
using System.Net;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace RMuseum.Controllers
|
|
{
|
|
[Produces("application/json")]
|
|
[Route("api/pdf")]
|
|
public class PDFLibraryController : Controller
|
|
{
|
|
/// <summary>
|
|
/// start importing a local pdf file
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Authorize(Policy = RMuseumSecurableItem.PDFLibraryEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
|
[ProducesResponseType((int)HttpStatusCode.OK)]
|
|
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
|
public IActionResult StartImportingLocalPDF([FromBody] NewPDFBookViewModel model)
|
|
{
|
|
var res = _pdfService.StartImportingLocalPDF(model);
|
|
if (!string.IsNullOrEmpty(res.ExceptionString))
|
|
return BadRequest(res.ExceptionString);
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// add a new book
|
|
/// </summary>
|
|
/// <param name="book"></param>
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("book")]
|
|
[Authorize(Policy = RMuseumSecurableItem.PDFLibraryEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
|
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(Book))]
|
|
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
|
public async Task<IActionResult> AddBookAsync([FromBody] Book book)
|
|
{
|
|
var res = await _pdfService.AddBookAsync(book);
|
|
if (!string.IsNullOrEmpty(res.ExceptionString))
|
|
return BadRequest(res.ExceptionString);
|
|
return Ok(res.Result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// add a new author
|
|
/// </summary>
|
|
/// <param name="author"></param>
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("author")]
|
|
[Authorize(Policy = RMuseumSecurableItem.PDFLibraryEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
|
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(Author))]
|
|
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
|
public async Task<IActionResult> AddAuthorAsync([FromBody] Author author)
|
|
{
|
|
var res = await _pdfService.AddAuthorAsync(author);
|
|
if (!string.IsNullOrEmpty(res.ExceptionString))
|
|
return BadRequest(res.ExceptionString);
|
|
return Ok(res.Result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// add a new mukti volume pdf collection
|
|
/// </summary>
|
|
/// <param name="volumes"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("volumes")]
|
|
[Authorize(Policy = RMuseumSecurableItem.PDFLibraryEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
|
|
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(MultiVolumePDFCollection))]
|
|
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
|
public async Task<IActionResult> AddMultiVolumePDFCollection([FromBody] MultiVolumePDFCollection volumes)
|
|
{
|
|
var res = await _pdfService.AddMultiVolumePDFCollection(volumes);
|
|
if (!string.IsNullOrEmpty(res.ExceptionString))
|
|
return BadRequest(res.ExceptionString);
|
|
return Ok(res.Result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// PDF Service
|
|
/// </summary>
|
|
protected readonly IPDFLibraryService _pdfService;
|
|
|
|
/// <summary>
|
|
/// constructor
|
|
/// </summary>
|
|
/// <param name="pdfService"></param>
|
|
public PDFLibraryController(IPDFLibraryService pdfService)
|
|
{
|
|
_pdfService = pdfService;
|
|
}
|
|
}
|
|
}
|