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/416 Added support for multiple call to actions per project. #447

Merged
merged 11 commits into from
Jun 29, 2021
Merged
107 changes: 85 additions & 22 deletions API/Controllers/ProjectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,22 +330,53 @@ 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 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);
}

//This should be refactored. As for much of the code in the controllers, see issue #411 - Refactor controllers.
int maxAmountOfCallToActions = 4;
RubenFricke marked this conversation as resolved.
Show resolved Hide resolved

if(projectResource.CallToActions.Count > maxAmountOfCallToActions)
{
ProblemDetails problem = new ProblemDetails
{
Title = $"Maximum amount of {maxAmountOfCallToActions} call to actions exceeded.",
Detail =
$"It is not possible to create a project with more than {maxAmountOfCallToActions} 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 @@ -481,22 +512,54 @@ 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 = "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 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);
}

//This should be refactored. As for much of the code in the controllers, see issue #411 - Refactor controllers.
int maxAmountOfCallToActions = 4;

if(projectResource.CallToActions.Count > maxAmountOfCallToActions)
{
ProblemDetails problem = new ProblemDetails
{
Title = "Maximum amount of call to actions exceeded.",
Detail =
$"It is not possible to create a project with more than {maxAmountOfCallToActions} 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
2 changes: 1 addition & 1 deletion API/Resources/ProjectResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ 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>
/// 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
5 changes: 5 additions & 0 deletions Data/06_Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
<EmbeddedResource Remove="Configurations\IdentityMigrations\**" />
<None Remove="Configurations\IdentityMigrations\**" />
</ItemGroup>

<ItemGroup>
<Compile Remove="Migrations\20210528115240_Test.cs" />
<Compile Remove="Migrations\20210528115240_Test.Designer.cs" />
</ItemGroup>
Arilith marked this conversation as resolved.
Show resolved Hide resolved
<ItemGroup>
<PackageReference Include="Bogus" Version="29.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.3" />
Expand Down
Loading