Skip to content
Snippets Groups Projects

Topic/181 resource handling

Merged David Schimmel requested to merge Topic/181-resourceHandling into Product/168-BasicStructure
3 files
+ 68
0
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -6,6 +6,7 @@ using Coscine.Api.Project.ReturnObjects;
using Coscine.ApiCommons;
using Coscine.ApiCommons.Exceptions;
using Coscine.ApiCommons.Factories;
using Coscine.Database.Model;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
@@ -61,6 +62,37 @@ namespace Coscine.Api.Project.Controllers
}));
}
[HttpGet("[controller]/{id}/resources")]
public IActionResult GetResources(string id)
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
var project = _projectModel.GetById(Guid.Parse(id));
ResourceModel resourceModel = new ResourceModel();
ResourceTypeModel resourceTypeModel = new ResourceTypeModel();
if (_projectModel.CanSeeProject(user, project))
{
return resourceModel.GetAllWhere((resource) =>
(from projectResource in resource.ProjectResourceResourceIdIds
where projectResource.ProjectId == project.Id
select projectResource).Any())
.Select((resource) =>
{
ResourceType resourceType = resource.Type;
if (resourceType == null)
{
resourceType = resourceTypeModel.GetById(resource.TypeId);
}
return new ResourceObject(resource.Id, resource.ExternalId, resource.Url, new ResourceTypeObject(resourceType.Id, resourceType.DisplayName));
});
}
else
{
throw new UnauthorizedAccessException("User cannot see resources of given project!");
}
}));
}
[HttpPost("[controller]/{id}")]
public IActionResult Update(string id)
{
Loading