Commit 3557ae5e authored by David Schimmel's avatar David Schimmel
Browse files

Merge branch 'Topic/181-resourceHandling' into 'Product/168-BasicStructure'

Topic/181 resource handling

See merge request coscine/api/project!6
parents 0b9b1388 4db68b64
...@@ -6,6 +6,7 @@ using Coscine.Api.Project.ReturnObjects; ...@@ -6,6 +6,7 @@ using Coscine.Api.Project.ReturnObjects;
using Coscine.ApiCommons; using Coscine.ApiCommons;
using Coscine.ApiCommons.Exceptions; using Coscine.ApiCommons.Exceptions;
using Coscine.ApiCommons.Factories; using Coscine.ApiCommons.Factories;
using Coscine.Database.Model;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -61,6 +62,37 @@ namespace Coscine.Api.Project.Controllers ...@@ -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}")] [HttpPost("[controller]/{id}")]
public IActionResult Update(string id) public IActionResult Update(string id)
{ {
......
using Coscine.Api.Project.Models;
using Coscine.Api.Project.ReturnObjects;
using Coscine.ApiCommons;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Api.Project.Controllers
{
public class ResourceTypeController : Controller
{
private readonly Authenticator _authenticator;
private readonly ResourceTypeModel _resourceTypeModel;
public ResourceTypeController()
{
_authenticator = new Authenticator(this, Program.Configuration);
_resourceTypeModel = new ResourceTypeModel();
}
[Route("[controller]")]
public IActionResult Index()
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
return _resourceTypeModel.GetAll().Select((resourceType) => new ResourceTypeObject(resourceType.Id, resourceType.DisplayName));
}));
}
}
}
...@@ -565,6 +565,7 @@ ...@@ -565,6 +565,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Controllers\ProjectController.cs" /> <Compile Include="Controllers\ProjectController.cs" />
<Compile Include="Controllers\ResourceController.cs" /> <Compile Include="Controllers\ResourceController.cs" />
<Compile Include="Controllers\ResourceTypeController.cs" />
<Compile Include="Controllers\RoleController.cs" /> <Compile Include="Controllers\RoleController.cs" />
<Compile Include="Controllers\SubProjectController.cs" /> <Compile Include="Controllers\SubProjectController.cs" />
<Compile Include="Controllers\ProjectRoleController.cs" /> <Compile Include="Controllers\ProjectRoleController.cs" />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment