Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/461 add pagination getuserprojects endpoint #504

Merged
22 changes: 19 additions & 3 deletions API/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ public async Task<IActionResult> GetUser(int userId)
[Authorize]
[ProducesResponseType(typeof(UserOutput), (int) HttpStatusCode.OK)]
[ProducesResponseType(typeof(ProblemDetails), (int) HttpStatusCode.NotFound)]
public async Task<IActionResult> GetUserProjects()
public async Task<IActionResult> GetUserProjects(
[FromQuery] ProjectFilterParamsInput projectFilterParamsResource
)
{
User user = await HttpContext.GetContextUser(userService).ConfigureAwait(false);
if(user == null)
Expand All @@ -186,9 +188,23 @@ public async Task<IActionResult> GetUserProjects()
return NotFound(problem);
}

IEnumerable<Project> userProjects = await projectService.GetUserProjects(user.Id);
ProjectFilterParams projectFilterParams =
mapper.Map<ProjectFilterParamsInput, ProjectFilterParams>(projectFilterParamsResource);

return Ok(mapper.Map<IEnumerable<Project>, IEnumerable<ProjectResultInput>>(userProjects));
IEnumerable<Project> userProjects = await projectService.GetUserProjects(user.Id, projectFilterParams);
IEnumerable<ProjectResultInput> results =
mapper.Map<IEnumerable<Project>, IEnumerable<ProjectResultInput>>(userProjects);

ProjectResultsInput resultsResource = new ProjectResultsInput
{
Results = results.ToArray(),
Count = results.Count(),
TotalCount = await projectService.ProjectsCount(projectFilterParams, user.Id),
Page = projectFilterParams.Page,
TotalPages = await projectService.GetProjectsTotalPages(projectFilterParams, user.Id)
};

return Ok(resultsResource);
}

/// <summary>
Expand Down
157 changes: 154 additions & 3 deletions Postman/dex.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "45ee041e-e0a8-4433-bdd8-3517c9bf6a93",
"_postman_id": "cfd740d0-2cb3-4a6d-9ca6-25db86e7c9c7",
"name": "DEV",
"description": "Testing Digital Excellence API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
Expand Down Expand Up @@ -1640,6 +1640,76 @@
}
]
},
{
"name": "UserProjects",
"item": [
{
"name": "UserProject-GetProject-Self-Administrator",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var projectName = pm.environment.get(\"projectName\");\r",
"\r",
"var jsonData = pm.response.json();\r",
"\r",
"eval(pm.environment.get(\"commonTests\"))();\r",
"\r",
"pm.test(\"Status code is 200\", function(){\r",
" pm.response.to.have.status(200);\r",
"});\r",
"\r",
"pm.test(\"Response must be valid and have a json body\", function() {\r",
" pm.response.to.be.ok;\r",
" pm.response.to.be.withBody;\r",
" pm.response.to.be.json;\r",
"});\r",
"\r",
"pm.test(\"Project pagination displays correct amount of projects and all project count matches\", function() {\r",
" pm.expect(jsonData.results.length).to.eql(1);\r",
" pm.expect(jsonData.totalCount).to.eql(3);\r",
"})"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "IdentityId",
"value": "{{administratorUserIdentityId}}",
"type": "text"
}
],
"url": {
"raw": "{{apiUrl}}/api/user/projects?page=1&amountOnPage=1",
"host": [
"{{apiUrl}}"
],
"path": [
"api",
"user",
"projects"
],
"query": [
{
"key": "page",
"value": "1"
},
{
"key": "amountOnPage",
"value": "1"
}
]
}
},
"response": []
}
]
},
{
"name": "Institution",
"item": [
Expand Down Expand Up @@ -13067,7 +13137,8 @@
"});",
"",
"pm.test(\"Project count matches: 6\", function () {",
" pm.expect(jsonData.length).to.eql(6);",
" pm.expect(jsonData.results.length).to.eql(1);",
" pm.expect(jsonData.totalCount).to.eql(6);",
"});"
],
"type": "text/javascript"
Expand All @@ -13084,14 +13155,24 @@
}
],
"url": {
"raw": "{{apiUrl}}/api/user/projects",
"raw": "{{apiUrl}}/api/user/projects?page=1&amountOnPage=1",
"host": [
"{{apiUrl}}"
],
"path": [
"api",
"user",
"projects"
],
"query": [
{
"key": "page",
"value": "1"
},
{
"key": "amountOnPage",
"value": "1"
}
]
}
},
Expand Down Expand Up @@ -29201,6 +29282,76 @@
}
]
},
{
"name": "UserProjects",
"item": [
{
"name": "UserProject-GetProject-Self-Alumni",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var projectName = pm.environment.get(\"projectName\");\r",
"\r",
"var jsonData = pm.response.json();\r",
"\r",
"eval(pm.environment.get(\"commonTests\"))();\r",
"\r",
"pm.test(\"Status code is 200\", function(){\r",
" pm.response.to.have.status(200);\r",
"});\r",
"\r",
"pm.test(\"Response must be valid and have a json body\", function() {\r",
" pm.response.to.be.ok;\r",
" pm.response.to.be.withBody;\r",
" pm.response.to.be.json;\r",
"});\r",
"\r",
"pm.test(\"Project pagination displays correct amount of projects and all project count matches\", function() {\r",
" pm.expect(jsonData.results.length).to.eql(1);\r",
" pm.expect(jsonData.totalCount).to.eql(3);\r",
"})"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "IdentityId",
"value": "{{alumniIdentityId}}",
"type": "text"
}
],
"url": {
"raw": "{{apiUrl}}/api/user/projects?page=1&amountOnPage=1",
"host": [
"{{apiUrl}}"
],
"path": [
"api",
"user",
"projects"
],
"query": [
{
"key": "page",
"value": "1"
},
{
"key": "amountOnPage",
"value": "1"
}
]
}
},
"response": []
}
]
},
{
"name": "Project",
"item": [
Expand Down
Loading