#400 /api/pdf/pdfbook/by/contributer/{authorId}/groupby/role
This commit is contained in:
parent
26ec5db816
commit
dc26f01753
@ -661,6 +661,27 @@ namespace RMuseum.Controllers
|
||||
return Ok(pdfBooksInfo.Result.Books);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get published pdf books by author stats (group by role)
|
||||
/// </summary>
|
||||
/// <param name="authorId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("pdfbook/by/contributer/{authorId}/groupby/role")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable<AuthorRoleCount>))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
|
||||
public async Task<IActionResult> GetPublishedPDFBookbyAuthorGroupedByRoleAsync(int authorId)
|
||||
{
|
||||
var res = await _pdfService.GetPublishedPDFBookbyAuthorGroupedByRoleAsync(authorId);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
{
|
||||
return BadRequest(res.ExceptionString);
|
||||
}
|
||||
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add a new mukti volume pdf collection
|
||||
/// </summary>
|
||||
|
||||
18
RMuseum/Models/PDFLibrary/ViewModels/AuthorRoleCount.cs
Normal file
18
RMuseum/Models/PDFLibrary/ViewModels/AuthorRoleCount.cs
Normal file
@ -0,0 +1,18 @@
|
||||
namespace RMuseum.Models.PDFLibrary.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Author Role Count
|
||||
/// </summary>
|
||||
public class AuthorRoleCount
|
||||
{
|
||||
/// <summary>
|
||||
/// Role
|
||||
/// </summary>
|
||||
public string Role { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Counts
|
||||
/// </summary>
|
||||
public int Count { get; set; }
|
||||
}
|
||||
}
|
||||
@ -2499,6 +2499,13 @@
|
||||
<param name="role"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.GetPublishedPDFBookbyAuthorGroupedByRoleAsync(System.Int32)">
|
||||
<summary>
|
||||
get published pdf books by author stats (group by role)
|
||||
</summary>
|
||||
<param name="authorId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.PDFLibraryController.AddMultiVolumePDFCollection(RMuseum.Models.PDFLibrary.MultiVolumePDFCollection)">
|
||||
<summary>
|
||||
add a new mukti volume pdf collection
|
||||
@ -12224,6 +12231,21 @@
|
||||
Attributes
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RMuseum.Models.PDFLibrary.ViewModels.AuthorRoleCount">
|
||||
<summary>
|
||||
Author Role Count
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.PDFLibrary.ViewModels.AuthorRoleCount.Role">
|
||||
<summary>
|
||||
Role
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.PDFLibrary.ViewModels.AuthorRoleCount.Count">
|
||||
<summary>
|
||||
Counts
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RMuseum.Models.PDFLibrary.ViewModels.NewPDFBookViewModel">
|
||||
<summary>
|
||||
New PDFBook view model
|
||||
@ -17752,6 +17774,13 @@
|
||||
<param name="role"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.PDFLibraryService.GetPublishedPDFBookbyAuthorGroupedByRoleAsync(System.Int32)">
|
||||
<summary>
|
||||
get published pdf books by author stats (group by role)
|
||||
</summary>
|
||||
<param name="authorId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.PDFLibraryService.AddBookAsync(RMuseum.Models.PDFLibrary.Book)">
|
||||
<summary>
|
||||
add book
|
||||
@ -18688,6 +18717,13 @@
|
||||
<param name="role"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IPDFLibraryService.GetPublishedPDFBookbyAuthorGroupedByRoleAsync(System.Int32)">
|
||||
<summary>
|
||||
get published pdf books by author stats (group by role)
|
||||
</summary>
|
||||
<param name="authorId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IPDFLibraryService.AddBookAsync(RMuseum.Models.PDFLibrary.Book)">
|
||||
<summary>
|
||||
add book
|
||||
|
||||
@ -131,6 +131,14 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<(PaginationMetadata PagingMeta, PDFBook[] Books)>> GetPublishedPDFBooksByAuthorAsync(PagingParameterModel paging, int authorId, string role);
|
||||
|
||||
/// <summary>
|
||||
/// get published pdf books by author stats (group by role)
|
||||
/// </summary>
|
||||
/// <param name="authorId"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
Task<RServiceResult<AuthorRoleCount[]>> GetPublishedPDFBookbyAuthorGroupedByRoleAsync(int authorId);
|
||||
|
||||
/// <summary>
|
||||
/// add book
|
||||
/// </summary>
|
||||
|
||||
@ -789,6 +789,58 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get published pdf books by author stats (group by role)
|
||||
/// </summary>
|
||||
/// <param name="authorId"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
public async Task<RServiceResult<AuthorRoleCount[]>> GetPublishedPDFBookbyAuthorGroupedByRoleAsync(int authorId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var books = await _context.PDFBooks.AsNoTracking().Include(b => b.Contributers).ThenInclude(c => c.Author)
|
||||
.Where(a => a.Status == PublishStatus.Published && a.Contributers.Any(a => a.Author.Id == authorId))
|
||||
.ToListAsync();
|
||||
Dictionary<string, int> roleCount = new Dictionary<string, int>();
|
||||
foreach (var book in books)
|
||||
{
|
||||
foreach (var contributer in book.Contributers)
|
||||
{
|
||||
if(contributer.Author.Id == authorId)
|
||||
{
|
||||
if (roleCount.ContainsKey(contributer.Role))
|
||||
{
|
||||
roleCount[contributer.Role] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
roleCount[contributer.Role]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<AuthorRoleCount> authorRoles = new List<AuthorRoleCount>();
|
||||
foreach(var role in roleCount.Keys)
|
||||
{
|
||||
authorRoles.Add
|
||||
(
|
||||
new AuthorRoleCount()
|
||||
{
|
||||
Role = role,
|
||||
Count = roleCount[role]
|
||||
}
|
||||
);
|
||||
}
|
||||
return new RServiceResult<AuthorRoleCount[]>(authorRoles.ToArray());
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<AuthorRoleCount[]>(null, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add book
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user