From 8f68337c4b8ea019b16bc7166f6c085e8778081e Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Tue, 25 Jul 2023 11:26:32 +0330 Subject: [PATCH] #400 book related pdf books --- RMuseum/Controllers/PDFLibraryController.cs | 41 ++++++++++++++++++- RMuseum/RMuseum.xml | 24 +++++++++++ RMuseum/Services/IPDFLibraryService.cs | 8 ++++ .../Implementation/PDFLibraryService.cs | 26 ++++++++++++ 4 files changed, 98 insertions(+), 1 deletion(-) diff --git a/RMuseum/Controllers/PDFLibraryController.cs b/RMuseum/Controllers/PDFLibraryController.cs index 76d65698..12db0239 100644 --- a/RMuseum/Controllers/PDFLibraryController.cs +++ b/RMuseum/Controllers/PDFLibraryController.cs @@ -763,7 +763,7 @@ namespace RMuseum.Controllers /// [HttpGet("book/by/author/{authorId}")] [AllowAnonymous] - [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] public async Task GetBooksByAuthorAsync([FromQuery] PagingParameterModel paging, int authorId, string role = null) @@ -814,6 +814,45 @@ namespace RMuseum.Controllers return Ok(res.Result); } + /// + /// get book related pdf books + /// + /// + /// + /// + + [HttpGet("pdfbook/by/book/{bookId}")] + [AllowAnonymous] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + + public async Task GetBookRelatedPFFBooksAsync([FromQuery] PagingParameterModel paging, int bookId) + { + var res = await _pdfService.GetBookRelatedPFFBooksAsync(paging, bookId); + if (!string.IsNullOrEmpty(res.ExceptionString)) + { + return BadRequest(res.ExceptionString); + } + + if (res.Result.Books.Count() > 0) + { + DateTime lastModification = res.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(res.Result.PagingMeta)); + + return Ok(res.Result.Books); + } + /// /// add a new multi volume pdf collection /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 7fc34a3d..82cab705 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -2552,6 +2552,14 @@ + + + get book related pdf books + + + + + add a new multi volume pdf collection @@ -17881,6 +17889,14 @@ + + + get book related pdf books + + + + + add multi volume pdf collection @@ -18871,6 +18887,14 @@ + + + get book related pdf books + + + + + add multi volume pdf collection diff --git a/RMuseum/Services/IPDFLibraryService.cs b/RMuseum/Services/IPDFLibraryService.cs index b3a1b297..d694c576 100644 --- a/RMuseum/Services/IPDFLibraryService.cs +++ b/RMuseum/Services/IPDFLibraryService.cs @@ -194,6 +194,14 @@ namespace RMuseum.Services Task> GetBookbyAuthorGroupedByRoleAsync(int authorId); + /// + /// get book related pdf books + /// + /// + /// + /// + Task> GetBookRelatedPFFBooksAsync(PagingParameterModel paging, int bookId); + /// /// add multi volume pdf collection /// diff --git a/RMuseum/Services/Implementation/PDFLibraryService.cs b/RMuseum/Services/Implementation/PDFLibraryService.cs index f46fcac8..a4bb7621 100644 --- a/RMuseum/Services/Implementation/PDFLibraryService.cs +++ b/RMuseum/Services/Implementation/PDFLibraryService.cs @@ -1048,6 +1048,32 @@ namespace RMuseum.Services.Implementation } } + /// + /// get book related pdf books + /// + /// + /// + /// + public async Task> GetBookRelatedPFFBooksAsync(PagingParameterModel paging, int bookId) + { + try + { + var source = + _context.PDFBooks.AsNoTracking() + .Include(a => a.CoverImage) + .Where(a => a.Status == PublishStatus.Published && a.BookId == bookId) + .OrderByDescending(t => t.DateTime) + .AsQueryable(); + (PaginationMetadata PagingMeta, PDFBook[] Books) paginatedResult = + await QueryablePaginator.Paginate(source, paging); + return new RServiceResult<(PaginationMetadata PagingMeta, PDFBook[] Books)>(paginatedResult); + } + catch (Exception exp) + { + return new RServiceResult<(PaginationMetadata PagingMeta, PDFBook[] Books)>((null, null), exp.ToString()); + } + } + /// /// add multi volume pdf collection