This commit is contained in:
2020-04-22 17:24:14 +00:00
parent ad13adc0bd
commit bb2d6fe357

View File

@@ -12,7 +12,7 @@ using AyaNova.Models;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Util;
using AyaNova.Biz;
using System.Linq;
namespace AyaNova.Api.Controllers
{
@@ -52,7 +52,34 @@ namespace AyaNova.Api.Controllers
//TODO: list with : name, notes, id, mimetype, lastmodified date
//TODO: Update notes / filename PUT route
//TODO: Update notes / filename PUT route
/// <summary>
/// Get attachments for object type and id specified
///
/// Required Role: Read full object properties rights to object type specified
///
/// </summary>
/// <returns>file attachment list for object</returns>
[HttpGet("List")]
public async Task<IActionResult> GetList([FromQuery] AyaType ayaType, [FromQuery] long ayaId)
{
if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!Authorized.HasReadFullRole(HttpContext.Items, ayaType))
{
return StatusCode(403, new ApiNotAuthorizedResponse());
}
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
var ret = await ct.FileAttachment.AsNoTracking().Where(m => m.AttachToObjectId == ayaId && m.AttachToObjectType == ayaType).OrderBy(m => m.DisplayFileName).Select(m => new { m.Id, m.ConcurrencyToken, m.ContentType, m.DisplayFileName, m.LastModified, m.Notes }).ToArrayAsync();
return Ok(ApiOkResponse.Response(ret, true));
}
/// <summary>
/// Upload attachment file