#11 view uploads api
This commit is contained in:
parent
572fc6e6e1
commit
bcd2db2e2f
@ -6,6 +6,7 @@ using RMuseum.Models.Auth.Memory;
|
||||
using RMuseum.Models.GanjoorAudio;
|
||||
using RMuseum.Models.GanjoorAudio.ViewModels;
|
||||
using RMuseum.Models.UploadSession;
|
||||
using RMuseum.Models.UploadSession.ViewModels;
|
||||
using RMuseum.Services;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using RSecurityBackend.Services;
|
||||
@ -68,6 +69,51 @@ namespace RMuseum.Controllers
|
||||
return Ok(res.Result.Items);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get User Uploads
|
||||
/// </summary>
|
||||
/// <param name="paging">default: false, user must have narration::moderate permission to be able to see all users uploads</param>
|
||||
/// <param name="allUsers"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("uploads")]
|
||||
[Authorize]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable<UploadSessionViewModel>))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.Forbidden, Type = typeof(string))]
|
||||
|
||||
public async Task<IActionResult> GetUploads([FromQuery] PagingParameterModel paging, bool allUsers = false)
|
||||
{
|
||||
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
|
||||
Guid sessionId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "SessionId").Value);
|
||||
|
||||
if (allUsers)
|
||||
{
|
||||
RServiceResult<bool>
|
||||
canView =
|
||||
await _userPermissionChecker.Check
|
||||
(
|
||||
loggedOnUserId,
|
||||
sessionId,
|
||||
RMuseumSecurableItem.AudioNarrationEntityShortName,
|
||||
RMuseumSecurableItem.ModerateOperationShortName
|
||||
);
|
||||
if (!string.IsNullOrEmpty(canView.ExceptionString))
|
||||
return BadRequest(canView.ExceptionString);
|
||||
|
||||
if (!canView.Result)
|
||||
return StatusCode((int)HttpStatusCode.Forbidden);
|
||||
}
|
||||
|
||||
var res = await _audioService.GetUploads(paging, allUsers ? Guid.Empty : loggedOnUserId);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
|
||||
// Paging Header
|
||||
HttpContext.Response.Headers.Add("paging-headers", JsonConvert.SerializeObject(res.Result.PagingMeta));
|
||||
|
||||
return Ok(res.Result.Items);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Narration Upload
|
||||
/// </summary>
|
||||
|
||||
@ -0,0 +1,81 @@
|
||||
using Org.BouncyCastle.Crypto.Tls;
|
||||
using RSecurityBackend.Models.Auth.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RMuseum.Models.UploadSession.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Upload session view model
|
||||
/// </summary>
|
||||
public class UploadSessionViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="src"></param>
|
||||
public UploadSessionViewModel(UploadSession src)
|
||||
{
|
||||
Id = src.Id;
|
||||
SessionType = src.SessionType;
|
||||
User = new PublicRAppUser(src.User);
|
||||
UploadStartTime = src.UploadStartTime;
|
||||
UploadEndTime = src.UploadEndTime;
|
||||
ProcessStartTime = src.ProcessStartTime;
|
||||
ProcessEndTime = src.ProcessEndTime;
|
||||
ProcessProgress = src.ProcessProgress;
|
||||
Status = src.Status;
|
||||
UploadedFiles = src.UploadedFiles;
|
||||
}
|
||||
/// <summary>
|
||||
/// Id
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Session Type
|
||||
/// </summary>
|
||||
public UploadSessionType SessionType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// User
|
||||
/// </summary>
|
||||
public PublicRAppUser User { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Upload Start Time
|
||||
/// </summary>
|
||||
public DateTime UploadStartTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Upload End Time
|
||||
/// </summary>
|
||||
public DateTime UploadEndTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Process Start Time
|
||||
/// </summary>
|
||||
public DateTime ProcessStartTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Process End Time
|
||||
/// </summary>
|
||||
public DateTime ProcessEndTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Process Progress
|
||||
/// </summary>
|
||||
public int ProcessProgress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Status
|
||||
/// </summary>
|
||||
public UploadSessionProcessStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Uploaded Files
|
||||
/// </summary>
|
||||
public ICollection<UploadSessionFile> UploadedFiles { get; set; }
|
||||
}
|
||||
}
|
||||
@ -629,6 +629,14 @@
|
||||
<param name="status">default: -1, unfiltered</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.AudioNarrationController.GetUploads(RSecurityBackend.Models.Generic.PagingParameterModel,System.Boolean)">
|
||||
<summary>
|
||||
Get User Uploads
|
||||
</summary>
|
||||
<param name="paging">default: false, user must have narration::moderate permission to be able to see all users uploads</param>
|
||||
<param name="allUsers"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.AudioNarrationController.UploadNarrations">
|
||||
<summary>
|
||||
Narration Upload
|
||||
@ -3001,6 +3009,67 @@
|
||||
Audio
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RMuseum.Models.UploadSession.ViewModels.UploadSessionViewModel">
|
||||
<summary>
|
||||
Upload session view model
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Models.UploadSession.ViewModels.UploadSessionViewModel.#ctor(RMuseum.Models.UploadSession.UploadSession)">
|
||||
<summary>
|
||||
Constructor
|
||||
</summary>
|
||||
<param name="src"></param>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.UploadSession.ViewModels.UploadSessionViewModel.Id">
|
||||
<summary>
|
||||
Id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.UploadSession.ViewModels.UploadSessionViewModel.SessionType">
|
||||
<summary>
|
||||
Session Type
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.UploadSession.ViewModels.UploadSessionViewModel.User">
|
||||
<summary>
|
||||
User
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.UploadSession.ViewModels.UploadSessionViewModel.UploadStartTime">
|
||||
<summary>
|
||||
Upload Start Time
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.UploadSession.ViewModels.UploadSessionViewModel.UploadEndTime">
|
||||
<summary>
|
||||
Upload End Time
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.UploadSession.ViewModels.UploadSessionViewModel.ProcessStartTime">
|
||||
<summary>
|
||||
Process Start Time
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.UploadSession.ViewModels.UploadSessionViewModel.ProcessEndTime">
|
||||
<summary>
|
||||
Process End Time
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.UploadSession.ViewModels.UploadSessionViewModel.ProcessProgress">
|
||||
<summary>
|
||||
Process Progress
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.UploadSession.ViewModels.UploadSessionViewModel.Status">
|
||||
<summary>
|
||||
Status
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.UploadSession.ViewModels.UploadSessionViewModel.UploadedFiles">
|
||||
<summary>
|
||||
Uploaded Files
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RMuseum.Services.IArtifactService">
|
||||
<summary>
|
||||
Artifact Item Service
|
||||
@ -3595,6 +3664,14 @@
|
||||
<param name="userId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IAudioNarrationService.GetUploads(RSecurityBackend.Models.Generic.PagingParameterModel,System.Guid)">
|
||||
<summary>
|
||||
Get uploads descending by upload time
|
||||
</summary>
|
||||
<param name="paging"></param>
|
||||
<param name="userId">if userId is empty all user uploads would be returned</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:RMuseum.Services.Implementation.ArtifactService">
|
||||
<summary>
|
||||
IArtifactService implementation
|
||||
@ -4381,6 +4458,14 @@
|
||||
<param name="userId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.AudioNarrationService.GetUploads(RSecurityBackend.Models.Generic.PagingParameterModel,System.Guid)">
|
||||
<summary>
|
||||
Get uploads descending by upload time
|
||||
</summary>
|
||||
<param name="paging"></param>
|
||||
<param name="userId">if userId is empty all user uploads would be returned</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:RMuseum.Services.Implementation.AudioNarrationService.Configuration">
|
||||
<summary>
|
||||
Configuration
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
using RMuseum.Models.GanjoorAudio;
|
||||
using RMuseum.Models.GanjoorAudio.ViewModels;
|
||||
using RMuseum.Models.UploadSession;
|
||||
using RMuseum.Models.UploadSession.ViewModels;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
@ -87,6 +88,14 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> DeleteUserNarrationProfiles(Guid id, Guid userId);
|
||||
|
||||
/// <summary>
|
||||
/// Get uploads descending by upload time
|
||||
/// </summary>
|
||||
/// <param name="paging"></param>
|
||||
/// <param name="userId">if userId is empty all user uploads would be returned</param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<(PaginationMetadata PagingMeta, UploadSessionViewModel[] Items)>> GetUploads(PagingParameterModel paging, Guid userId);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ using RMuseum.Migrations;
|
||||
using RMuseum.Models.GanjoorAudio;
|
||||
using RMuseum.Models.GanjoorAudio.ViewModels;
|
||||
using RMuseum.Models.UploadSession;
|
||||
using RMuseum.Models.UploadSession.ViewModels;
|
||||
using RMuseum.Services.Implementation.ImportedFromDesktopGanjoor;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using RSecurityBackend.Services.Implementation;
|
||||
@ -598,6 +599,42 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get uploads descending by upload time
|
||||
/// </summary>
|
||||
/// <param name="paging"></param>
|
||||
/// <param name="userId">if userId is empty all user uploads would be returned</param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<(PaginationMetadata PagingMeta, UploadSessionViewModel[] Items)>> GetUploads(PagingParameterModel paging, Guid userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var source =
|
||||
|
||||
_context.UploadSessions
|
||||
.Include(u => u.User)
|
||||
.Include(u => u.UploadedFiles)
|
||||
.Where(u => userId == Guid.Empty || u.UseId == userId )
|
||||
.OrderByDescending(u => u.UploadEndTime)
|
||||
.AsQueryable();
|
||||
|
||||
(PaginationMetadata PagingMeta, UploadSession[] Items) paginatedResult =
|
||||
await QueryablePaginator<UploadSession>.Paginate(source, paging);
|
||||
|
||||
List<UploadSessionViewModel> res = new List<UploadSessionViewModel>();
|
||||
foreach (UploadSession upload in paginatedResult.Items)
|
||||
{
|
||||
res.Add(new UploadSessionViewModel(upload));
|
||||
}
|
||||
|
||||
return new RServiceResult<(PaginationMetadata PagingMeta, UploadSessionViewModel[] Items)>((paginatedResult.PagingMeta, res.ToArray()));
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<(PaginationMetadata PagingMeta, UploadSessionViewModel[] Items)>((PagingMeta: null, Items: null), exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configuration
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user