This commit is contained in:
2023-04-20 00:31:49 +00:00
parent b301b907b3
commit 99c0505a06
3 changed files with 68 additions and 54 deletions

View File

@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
@@ -7,7 +8,7 @@ using Microsoft.Extensions.Logging;
using Sockeye.Models;
using Sockeye.Api.ControllerHelpers;
using Sockeye.Biz;
using System.Linq;
namespace Sockeye.Api.Controllers
{
@@ -102,39 +103,43 @@ namespace Sockeye.Api.Controllers
// /// <summary>
// /// Get the top level ancestor of provided type and id
// /// (e.g. find the WorkOrder principle for a WorkOrderItemPart object descendant)
// /// </summary>
// /// <param name="sockType"></param>
// /// <param name="id"></param>
// /// <returns>A type and id of ancestor</returns>
// [HttpGet("ancestor/{sockType}/{id}")]
// public async Task<IActionResult> GetAncestor([FromRoute] SockType sockType, [FromRoute] long id)
// {
// if (serverState.IsClosed)
// return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
/// <summary>
/// Get the top level ancestor of provided type and id
/// (e.g. find the WorkOrder principle for a WorkOrderItemPart object descendant)
/// </summary>
/// <param name="sockType"></param>
/// <param name="id"></param>
/// <returns>A type and id of ancestor</returns>
[HttpGet("ancestor/{sockType}/{id}")]
public async Task<IActionResult> GetAncestor([FromRoute] SockType sockType, [FromRoute] long id)
{
if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
// //since this is for opening an entire object it's appropriate to check if they have any role first
// if (!Authorized.HasAnyRole(HttpContext.Items, sockType))
// return StatusCode(403, new ApiNotAuthorizedResponse());
//since this is for opening an entire object it's appropriate to check if they have any role first
if (!Authorized.HasAnyRole(HttpContext.Items, sockType))
return StatusCode(403, new ApiNotAuthorizedResponse());
// if (!ModelState.IsValid)
// return BadRequest(new ApiErrorResponse(ModelState));
// if (id == 0)
// return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, "id can't be zero"));
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
if (id == 0)
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, "id can't be zero"));
// switch (sockType)
// {
switch (sockType)
{
case SockType.SubscriptionItem:
{
var subId = await ct.SubscriptionItem.AsNoTracking().Where(z => z.Id == id).Select(z => z.SubscriptionId).SingleOrDefaultAsync();
return Ok(ApiOkResponse.Response(new { SockType = (int)SockType.Subscription, Id = subId }));
}
default:
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, "Only types with ancestors are valid"));
// default:
// return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, "Only types with ancestors are valid"));
}
// }
// }
}