Skip to content
Snippets Groups Projects

Breaking: Removed Quota Method

Merged Petar Hristov requested to merge Issue/1951-quotaImplementation into dev
@@ -67,72 +67,6 @@ namespace Coscine.Api.Blob.Controllers
return new CustomUri($"https://hdl.handle.net/{_prefix}/{resourceId}@path={Uri.EscapeDataString(path)}");
}
/// <summary>
/// This method returns the amount of allocated space for the given resource
/// </summary>
/// <param name="resourceId">Id of a resource</param>
/// <returns>Data, file count and byte size used or Status Code 400, 404, 401 or 500 </returns>
[HttpGet("[controller]/{resourceId}/quota")]
public IActionResult GetQuota(string resourceId)
{
if (!Guid.TryParse(resourceId, out Guid resourceGuid))
{
return BadRequest($"{resourceId} is not a GUID.");
}
var user = _authenticator.GetUser();
Resource resource;
try
{
resource = _resourceModel.GetById(resourceGuid);
if (resource == null)
{
return NotFound($"Could not find resource with id: {resourceId}");
}
}
catch (Exception)
{
return NotFound($"Could not find resource with id: {resourceId}");
}
if (resource.Type == null)
{
var resourceTypeModel = new ResourceTypeModel();
resource.Type = resourceTypeModel.GetById(resource.TypeId);
}
if (user == null || !_resourceModel.HasAccess(user, resource, UserRoles.Owner, UserRoles.Member))
{
return BadRequest("User does not have permission to the resource.");
}
var resourceTypeDefinition = ResourceTypeFactory.Instance.GetResourceType(resource);
if (resourceTypeDefinition == null)
{
return BadRequest($"No provider for: \"{resource.Type.DisplayName}\".");
}
var resourceTypeInformation = resourceTypeDefinition.GetResourceTypeInformation().Result;
if (resource.ResourceTypeOptionId.HasValue && resourceTypeInformation.IsQuotaAvailable)
{
try
{
var totalFileSize = resourceTypeDefinition.GetResourceQuotaUsed(resourceId).Result;
return Ok($"{{ \"data\": {{ \"usedSizeByte\": {totalFileSize} }}}}");
}
catch (Exception e)
{
_coscineLogger.Log("Get Quota failed", e);
return BadRequest("Error in communication with the resource");
}
}
else
{
return BadRequest("The resource quota must be adjustable.");
}
}
/// <summary>
/// This method checks if the given file exists and returns it
/// </summary>
Loading