Skip to content

changed endpoint for getting al hightlights. Status code is now 200 w… #248

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

Merged
merged 12 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions API/Controllers/EmbedController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace API.Controllers
Expand Down Expand Up @@ -67,17 +68,20 @@ public EmbedController(IEmbedService embedService, IMapper mapper, IProjectServi
[Authorize(Policy = nameof(Defaults.Scopes.EmbedRead))]
public async Task<IActionResult> GetAllEmbeddedProjects()
{
IEnumerable<EmbeddedProject> embeddedProjects = await embedService.GetEmbeddedProjectsAsync();
IEnumerable<EmbeddedProject> embeddedProjects;

if(!embeddedProjects.Any())
try
{
embeddedProjects = await embedService.GetEmbeddedProjectsAsync();
} catch(Exception)
{
ProblemDetails problem = new ProblemDetails
{
Title = "No Embedded Projects found.",
Detail = "There are no Embedded projects in the database.",
Instance = "FEA62EAE-3D3C-4CE7-BDD8-6B273D56068D"
Title = "Failed getting embedded porjects.",
Detail = "An unexpected error occurred.",
Instance = "322A1ED6-4AAD-445C-940B-EE9C247B491C"
};
return NotFound(problem);
return BadRequest(problem);
}
return Ok(mapper.Map<IEnumerable<EmbeddedProject>, IEnumerable<EmbeddedProjectResourceResult>>(embeddedProjects));
}
Expand Down
21 changes: 13 additions & 8 deletions API/Controllers/HighlightController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Models.Defaults;
using Serilog;
using Services.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -60,18 +61,22 @@ public HighlightController(IHighlightService highlightService, IMapper mapper)
[HttpGet]
public async Task<IActionResult> GetAllHighlights()
{
IEnumerable<Highlight> highlights = await highlightService.GetHighlightsAsync();
if(!highlights.Any())
IEnumerable<Highlight> highlights;
try
{
highlights = await highlightService.GetHighlightsAsync();
} catch(Exception)
{
ProblemDetails problem = new ProblemDetails
{
Title = "Failed getting highlights.",
Detail = "The database does not contain any highlights.",
Instance = "FC6A4F97-C815-4A92-8A73-2ECF1729B161"
};
return NotFound(problem);
{
Title = "Failed getting highlight.",
Detail = "An unexpected error occurred.",
Instance = "8310EE19-C0E9-4236-AFDD-C1A01F8A78F7"
};
return BadRequest(problem);
}


return Ok(mapper.Map<IEnumerable<Highlight>, IEnumerable<HighlightResourceResult>>(highlights));
}

Expand Down
39 changes: 25 additions & 14 deletions API/Controllers/RoleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Models.Defaults;
using Serilog;
using Services.Services;
using System;
using static Models.Defaults.Defaults;

namespace API.Controllers
Expand Down Expand Up @@ -46,16 +47,21 @@ public RoleController(IRoleService roleService, IUserService userService, IMappe
[Authorize(Policy = nameof(Scopes.RoleRead))]
public async Task<IActionResult> GetAllRoles()
{
List<Role> roles = await roleService.GetAllAsync().ConfigureAwait(false);
if(roles.Count == 0)
List<Role> roles;

try
{
roles = await roleService.GetAllAsync()
.ConfigureAwait(false);
} catch(Exception)
{
ProblemDetails problem = new ProblemDetails
{
Title = "Failed getting all roles.",
Detail = "There where no roles found in the database.",
Instance = "3EB1E953-96D7-45FE-8C5C-05306AF8D060"
{
Title = "Failed getting all roles.",
Detail = "Unexpected error occurred.",
Instance = "6010C506-44FA-4616-82C3-BD77F70CC1A9"
};
return NotFound(problem);
return BadRequest(problem);
}

return Ok(mapper.Map<IEnumerable<Role>, IEnumerable<RoleResourceResult>>(roles));
Expand All @@ -69,17 +75,22 @@ public async Task<IActionResult> GetAllRoles()
[Authorize(Policy = nameof(Scopes.RoleRead))]
public IActionResult GetAllPossibleScopes()
{
List<string> scopeList = roleService.GetValidScopes();
if(scopeList.Count == 0)
List<string> scopeList;

try
{
scopeList = roleService.GetValidScopes();
} catch(Exception)
{
ProblemDetails problem = new ProblemDetails
{
Title = "No valid Scopes found",
Detail = "There where no valid scopes found.",
Instance = "DEB2161D-A8E7-4AAE-BB0F-CDB3CA5D5B9E"
{
Title = "No valid Scopes found",
Detail = "Unexpected error occurred.",
Instance = "C796E78E-75C1-4CE3-8E43-4A32997B4852"
};
return NotFound(problem);
return BadRequest(problem);
}

return Ok(scopeList);
}

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fixed a bug where GetAllHighlights endpoint return status code 404 when empty. - [#207](https://github.com/DigitalExcellence/dex-backend/issues/207)
- Fixed issue where local docker-compose would not work due to missing connection string - [#234](https://github.com/DigitalExcellence/dex-backend/issues/234)

### Security
Expand Down