#400 get volumes/{volumeId}/pdfs

This commit is contained in:
Hamid Reza Mohammadi 2023-07-25 13:46:17 +03:30
parent 65d0164345
commit 3a9116161c
4 changed files with 76 additions and 5 deletions

View File

@ -927,6 +927,26 @@ namespace RMuseum.Controllers
return BadRequest(res.ExceptionString);
return Ok(res.Result);
}
/// <summary>
/// get volumes pdf books
/// </summary>
/// <param name="volumeId"></param>
/// <returns></returns>
[HttpGet("volumes/{volumeId}/pdfs")]
[AllowAnonymous]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable<PDFBook>))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> GetVolumesPDFBooks(int volumeId)
{
var res = await _pdfService.GetVolumesPDFBooks(volumeId);
if (!string.IsNullOrEmpty(res.ExceptionString))
{
return BadRequest(res.ExceptionString);
}
return Ok(res.Result);
}
/// <summary>
/// PDF Service

View File

@ -2588,6 +2588,13 @@
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.PDFLibraryController.GetVolumesPDFBooks(System.Int32)">
<summary>
get volumes pdf books
</summary>
<param name="volumeId"></param>
<returns></returns>
</member>
<member name="F:RMuseum.Controllers.PDFLibraryController._pdfService">
<summary>
PDF Service
@ -17946,6 +17953,13 @@
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.PDFLibraryService.GetVolumesPDFBooks(System.Int32)">
<summary>
get volumes pdf books
</summary>
<param name="volumeId"></param>
<returns></returns>
</member>
<member name="F:RMuseum.Services.Implementation.PDFLibraryService._context">
<summary>
Database Context
@ -18989,6 +19003,13 @@
<param name="pdfpageId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IPDFLibraryService.GetVolumesPDFBooks(System.Int32)">
<summary>
get volumes pdf books
</summary>
<param name="volumeId"></param>
<returns></returns>
</member>
<member name="T:RMuseum.Services.IPictureFileService">
<summary>
manipulating picture files

View File

@ -254,5 +254,12 @@ namespace RMuseum.Services
/// <param name="pdfpageId"></param>
/// <returns></returns>
Task<RServiceResult<bool>> SetPDFBookCoverImageFromPageAsync(int pdfBookId, int pdfpageId);
/// <summary>
/// get volumes pdf books
/// </summary>
/// <param name="volumeId"></param>
/// <returns></returns>
Task<RServiceResult<PDFBook[]>> GetVolumesPDFBooks(int volumeId);
}
}

View File

@ -714,7 +714,7 @@ namespace RMuseum.Services.Implementation
{
role = role.Trim();
var pdfBook = await _context.PDFBooks.Include(b => b.Contributers).ThenInclude(a => a.Author).Where(b => b.Id == pdfBookId).SingleAsync();
if(pdfBook.Contributers.Any(a => a.Author.Id == authorId && a.Role == role))
if (pdfBook.Contributers.Any(a => a.Author.Id == authorId && a.Role == role))
{
return new RServiceResult<bool>(false, "author contribution already added");
}
@ -808,7 +808,7 @@ namespace RMuseum.Services.Implementation
{
foreach (var contributer in book.Contributers)
{
if(contributer.Author.Id == authorId)
if (contributer.Author.Id == authorId)
{
if (roleCount.ContainsKey(contributer.Role))
{
@ -823,7 +823,7 @@ namespace RMuseum.Services.Implementation
}
List<AuthorRoleCount> authorRoles = new List<AuthorRoleCount>();
foreach(var role in roleCount.Keys)
foreach (var role in roleCount.Keys)
{
authorRoles.Add
(
@ -834,7 +834,7 @@ namespace RMuseum.Services.Implementation
}
);
}
return new RServiceResult<AuthorRoleCount[]>(authorRoles.ToArray());
return new RServiceResult<AuthorRoleCount[]>(authorRoles.ToArray());
}
catch (Exception exp)
{
@ -871,7 +871,7 @@ namespace RMuseum.Services.Implementation
try
{
var dbBook = await _context.Books.Where(b => b.Id == model.Id).SingleAsync();
dbBook.Name = model.Name;
dbBook.Name = model.Name;
dbBook.Description = model.Description;
dbBook.CoverImageId = model.CoverImageId;
dbBook.ExtenalCoverImageUrl = model.ExtenalCoverImageUrl;
@ -1160,6 +1160,29 @@ namespace RMuseum.Services.Implementation
}
}
/// <summary>
/// get volumes pdf books
/// </summary>
/// <param name="volumeId"></param>
/// <returns></returns>
public async Task<RServiceResult<PDFBook[]>> GetVolumesPDFBooks(int volumeId)
{
try
{
var books =
await _context.PDFBooks.AsNoTracking()
.Include(a => a.CoverImage)
.Where(a => a.Status == PublishStatus.Published && a.MultiVolumePDFCollectionId == volumeId)
.OrderBy(t => t.VolumeOrder)
.ToArrayAsync();
return new RServiceResult<PDFBook[]>(books);
}
catch (Exception exp)
{
return new RServiceResult<PDFBook[]>(null, exp.ToString());
}
}
/// <summary>
/// Database Context
/// </summary>