Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
P
Project
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Labels
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Environments
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Coscine
B
backend
apis
Project
Commits
c2ac00f2
Commit
c2ac00f2
authored
Jul 25, 2019
by
Benedikt Heinrichs
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New: ResourceTypeController and listing all resources to a project (coscine/issues#181)
parent
d6a3c2ca
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
0 deletions
+83
-0
src/Project.Tests/DefaultControllerTests.cs
src/Project.Tests/DefaultControllerTests.cs
+15
-0
src/Project/Controllers/ProjectController.cs
src/Project/Controllers/ProjectController.cs
+32
-0
src/Project/Controllers/ResourceTypeController.cs
src/Project/Controllers/ResourceTypeController.cs
+35
-0
src/Project/Project.csproj
src/Project/Project.csproj
+1
-0
No files found.
src/Project.Tests/DefaultControllerTests.cs
View file @
c2ac00f2
...
...
@@ -109,6 +109,21 @@ namespace Coscine.Api.Project.Tests
resourceModel
.
Insert
(
resource2
);
projectModel
.
AddResource
(
project2
,
resource2
);
Resources
.
Add
(
resource2
);
project
=
new
Coscine
.
Database
.
Model
.
Project
()
{
Description
=
"Description"
,
Organization
=
"Organization"
,
DisplayName
=
"TestProject"
,
StartDate
=
DateTime
.
Now
,
EndDate
=
DateTime
.
Now
.
AddYears
(
1
),
Keywords
=
"Test1;Test2"
};
Guid
.
TryParse
(
"3d058224-8bbc-45f1-8ad1-042b65d0e83b"
,
out
Guid
newId
);
project
.
Id
=
newId
;
projectModel
.
Insert
(
project
);
projectRole
=
projectModel
.
SetOwner
(
project
,
user
);
}
...
...
src/Project/Controllers/ProjectController.cs
View file @
c2ac00f2
...
...
@@ -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
)
{
...
...
src/Project/Controllers/ResourceTypeController.cs
0 → 100644
View file @
c2ac00f2
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
));
}));
}
}
}
src/Project/Project.csproj
View file @
c2ac00f2
...
...
@@ -565,6 +565,7 @@
<ItemGroup>
<Compile
Include=
"Controllers\ProjectController.cs"
/>
<Compile
Include=
"Controllers\ResourceController.cs"
/>
<Compile
Include=
"Controllers\ResourceTypeController.cs"
/>
<Compile
Include=
"Controllers\SubProjectController.cs"
/>
<Compile
Include=
"Models\ProjectModel.cs"
/>
<Compile
Include=
"Models\ProjectResourceModel.cs"
/>
...
...
Ghost User
@ghost
mentioned in commit
f91a1c23
·
Aug 16, 2019
mentioned in commit
f91a1c23
mentioned in commit f91a1c2321609c4d0768b3560622779d49efc6a3
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment