Skip to content

Commit

Permalink
Merge pull request #447 from DigitalExcellence/feature/416-2-multiple…
Browse files Browse the repository at this point in the history
…-calltoactions

Feature/416 Added support for multiple call to actions per project.
  • Loading branch information
RubenFricke authored Jun 29, 2021
2 parents 0b99e31 + b962081 commit 5f693c1
Show file tree
Hide file tree
Showing 12 changed files with 9,988 additions and 7,360 deletions.
86 changes: 70 additions & 16 deletions API/Controllers/ProjectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,21 +359,46 @@ public async Task<IActionResult> CreateProjectAsync([FromBody] ProjectResource p
return BadRequest(problem);
}

if(projectResource.CallToAction != null)
if(projectResource.CallToActions != null)
{
IEnumerable<CallToActionOption> callToActionOptions =
await callToActionOptionService.GetCallToActionOptionFromValueAsync(
projectResource.CallToAction.OptionValue);
if(!callToActionOptions.Any())
if(projectResource.CallToActions.GroupBy(cta => cta.OptionValue).Any(cta => cta.Count() > 1))
{
ProblemDetails problem = new ProblemDetails
{
Title = "Call to action value was not found.",
Detail = "The specified call to action value was not found while creating the project.",
Instance = "40EE82EB-930F-40C8-AE94-0041F7573FE9"
Title = "Duplicate call to action option value.",
Detail = "It is not possible to create a project with multiple of the same call to actions.",
Instance = "D2C8416A-9C55-408B-9468-F0E5C635F9B7"
};
return BadRequest(problem);
}

if(projectResource.CallToActions.Count > projectResource.MaximumCallToActions)
{
ProblemDetails problem = new ProblemDetails
{
Title = $"Maximum amount of {projectResource.MaximumCallToActions} call to actions exceeded.",
Detail = $"It is not possible to create a project with more than {projectResource.MaximumCallToActions} call to actions.",
Instance = "E780005D-BBEB-423E-BA01-58145D3DBDF5"
};
return BadRequest(problem);
}
foreach(CallToActionResource callToAction in projectResource.CallToActions)
{
IEnumerable<CallToActionOption> callToActionOptions =
await callToActionOptionService.GetCallToActionOptionFromValueAsync(
callToAction.OptionValue);
if(!callToActionOptions.Any())
{
ProblemDetails problem = new ProblemDetails
{
Title = "Call to action value was not found.",
Detail = $"The call to action optionvalue: '{callToAction.OptionValue}' was not found while creating the project.",
Instance = "40EE82EB-930F-40C8-AE94-0041F7573FE9"
};
return BadRequest(problem);
}
}

}

Project project = mapper.Map<ProjectResource, Project>(projectResource);
Expand Down Expand Up @@ -537,21 +562,50 @@ public async Task<IActionResult> UpdateProject(int projectId, [FromBody] Project
return Unauthorized(problem);
}

if(projectResource.CallToAction != null)
if(projectResource.CallToActions != null)
{
IEnumerable<CallToActionOption> callToActionOptions =
await callToActionOptionService.GetCallToActionOptionFromValueAsync(
projectResource.CallToAction.OptionValue);
if(!callToActionOptions.Any())
if(projectResource.CallToActions.GroupBy(cta => cta.OptionValue).Any(cta => cta.Count() > 1))
{
ProblemDetails problem = new ProblemDetails
{
Title = "Duplicate call to action option value.",
Detail = "It is not possible to create a project with multiple of the same call to actions.",
Instance = "D2C8416A-9C55-408B-9468-F0E5C635F9B7"
};
return BadRequest(problem);
}

if(projectResource.CallToActions.Count > projectResource.MaximumCallToActions)
{
ProblemDetails problem = new ProblemDetails
{
Title = "Call to action value was not found.",
Detail = "The specified call to action value was not found while creating the project.",
Instance = "40EE82EB-930F-40C8-AE94-0041F7573FE9"
Title = $"Maximum amount of {projectResource.MaximumCallToActions} call to actions exceeded.",
Detail =
$"It is not possible to create a project with more than {projectResource.MaximumCallToActions} call to actions.",
Instance = "E780005D-BBEB-423E-BA01-58145D3DBDF5"
};
return BadRequest(problem);
}

foreach(CallToActionResource callToAction in projectResource.CallToActions)
{
IEnumerable<CallToActionOption> callToActionOptions =
await callToActionOptionService.GetCallToActionOptionFromValueAsync(
callToAction.OptionValue);

if(!callToActionOptions.Any())
{
ProblemDetails problem = new ProblemDetails
{
Title = "Call to action value was not found.",
Detail =
$"The call to action optionvalue: '{callToAction.OptionValue}' was not found while creating the project.",
Instance = "40EE82EB-930F-40C8-AE94-0041F7573FE9"
};
return BadRequest(problem);
}
}

}

if (projectResource.InstitutePrivate != project.InstitutePrivate)
Expand Down
7 changes: 6 additions & 1 deletion API/Resources/ProjectResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ public class ProjectResource
/// <summary>
/// This gets or sets the call to action
/// </summary>
public CallToActionResource CallToAction { get; set; }
public List<CallToActionResource> CallToActions { get; set; }

/// <summary>
/// The maximum allowed call to actions per project.
/// </summary>
public int MaximumCallToActions { get { return 4; } }

/// <summary>
/// This gets or sets the institute private property
Expand Down
2 changes: 1 addition & 1 deletion API/Resources/ProjectResourceResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class ProjectResourceResult
/// <summary>
/// This gets or sets the call to action.
/// </summary>
public CallToActionResourceResult CallToAction { get; set; }
public List<CallToActionResourceResult> CallToActions { get; set; }

/// <summary>
/// This gets or sets the likes of the project.
Expand Down
4 changes: 2 additions & 2 deletions API/Resources/ProjectResultResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public class ProjectResultResource
public FileResourceResult ProjectIcon { get; set; }

/// <summary>
/// This gets or sets the call to action of the project.
/// This gets or sets the call to actions of the project.
/// </summary>
public CallToActionResourceResult CallToAction { get; set; }
public List<CallToActionResourceResult> CallToActions { get; set; }

/// <summary>
/// This gets or sets the likes of the project.
Expand Down
Loading

0 comments on commit 5f693c1

Please sign in to comment.