From 053e058ea1d37c3611295f73f56e325d2cb255f3 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Mon, 24 Jul 2023 16:19:39 +0330 Subject: [PATCH] #400 pdf get all anonymous api --- RMuseum/Controllers/PDFLibraryController.cs | 40 +++++++++++++++++++ RMuseum/RMuseum.xml | 23 +++++++++++ RMuseum/Services/IPDFLibraryService.cs | 8 ++++ .../Implementation/PDFLibraryService.cs | 19 +++++++++ 4 files changed, 90 insertions(+) diff --git a/RMuseum/Controllers/PDFLibraryController.cs b/RMuseum/Controllers/PDFLibraryController.cs index 20d395cc..6f89ad5b 100644 --- a/RMuseum/Controllers/PDFLibraryController.cs +++ b/RMuseum/Controllers/PDFLibraryController.cs @@ -14,6 +14,8 @@ using System.Net; using System.Threading.Tasks; using RSecurityBackend.Services; using RMuseum.Services.Implementation; +using System.Collections.Generic; +using Newtonsoft.Json; namespace RMuseum.Controllers { @@ -21,6 +23,44 @@ namespace RMuseum.Controllers [Route("api/pdf")] public class PDFLibraryController : Controller { + /// + ///get all published pdfbooks (including CoverImage info but not pages or tagibutes info) - check paging-headers for paging info + /// + /// + /// + + [HttpGet] + [AllowAnonymous] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + + public async Task GetAllPDFBooks([FromQuery] PagingParameterModel paging) + { + var pdfBooksInfo = await _pdfService.GetAllPDFBooks(paging, new PublishStatus[] { PublishStatus.Published }); + if (!string.IsNullOrEmpty(pdfBooksInfo.ExceptionString)) + { + return BadRequest(pdfBooksInfo.ExceptionString); + } + + if (pdfBooksInfo.Result.Books.Count() > 0) + { + DateTime lastModification = pdfBooksInfo.Result.Books.Max(i => i.LastModified); + Response.GetTypedHeaders().LastModified = lastModification; + + var requestHeaders = Request.GetTypedHeaders(); + if (requestHeaders.IfModifiedSince.HasValue && + requestHeaders.IfModifiedSince.Value >= lastModification) + { + return StatusCode(StatusCodes.Status304NotModified); + } + } + + // Paging Header + HttpContext.Response.Headers.Add("paging-headers", JsonConvert.SerializeObject(pdfBooksInfo.Result.PagingMeta)); + + return Ok(pdfBooksInfo.Result.Books); + } + /// /// start importing a local pdf file /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index b578c7db..694a4e20 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -2343,6 +2343,13 @@ + + + get all published pdfbooks (including CoverImage info but not pages or tagibutes info) - check paging-headers for paging info + + + + start importing a local pdf file @@ -17514,6 +17521,14 @@ + + + get all pdfbooks (including CoverImage info but not pages or tagibutes info) + + + + + start importing local pdf file @@ -18385,6 +18400,14 @@ + + + get all pdfbooks (including CoverImage info but not pages or tagibutes info) + + + + + add author diff --git a/RMuseum/Services/IPDFLibraryService.cs b/RMuseum/Services/IPDFLibraryService.cs index 71217df3..21b03739 100644 --- a/RMuseum/Services/IPDFLibraryService.cs +++ b/RMuseum/Services/IPDFLibraryService.cs @@ -19,6 +19,14 @@ namespace RMuseum.Services /// Task> GetPDFBookByIdAsync(int id, PublishStatus[] statusArray); + /// + /// get all pdfbooks (including CoverImage info but not pages or tagibutes info) + /// + /// + /// + /// + Task> GetAllPDFBooks(PagingParameterModel paging, PublishStatus[] statusArray); + /// /// add author /// diff --git a/RMuseum/Services/Implementation/PDFLibraryService.cs b/RMuseum/Services/Implementation/PDFLibraryService.cs index 9c7ae294..cc3db26a 100644 --- a/RMuseum/Services/Implementation/PDFLibraryService.cs +++ b/RMuseum/Services/Implementation/PDFLibraryService.cs @@ -51,6 +51,25 @@ namespace RMuseum.Services.Implementation } } + /// + /// get all pdfbooks (including CoverImage info but not pages or tagibutes info) + /// + /// + /// + /// + public async Task> GetAllPDFBooks(PagingParameterModel paging, PublishStatus[] statusArray) + { + var source = + _context.PDFBooks.AsNoTracking() + .Include(a => a.CoverImage) + .Where(a => statusArray.Contains(a.Status)) + .OrderByDescending(t => t.DateTime) + .AsQueryable(); + (PaginationMetadata PagingMeta, PDFBook[] Books) paginatedResult = + await QueryablePaginator.Paginate(source, paging); + return new RServiceResult<(PaginationMetadata PagingMeta, PDFBook[] Books)>(paginatedResult); + } + /// /// start importing local pdf file ///