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/362 categories #378

Merged
merged 52 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
03fd8c3
Added Tags, added project tag connection, added tag migration, seeded…
JVerbruggen Feb 24, 2021
c17526a
All project and tag endpoints work
JVerbruggen Feb 26, 2021
c476ddd
Added changelog record
JVerbruggen Feb 26, 2021
15684f3
Added administrator tag postman tests
JVerbruggen Feb 26, 2021
e3e376b
Added postman ACL tests for all users, updated necessary env vars
JVerbruggen Feb 26, 2021
2f0b47d
Tweaked roles and postman tests
JVerbruggen Feb 26, 2021
af5cabf
Added Unit Tests
JVerbruggen Feb 26, 2021
80a94f0
Name now required at creation tag
JVerbruggen Mar 1, 2021
4dbb3a8
Updated documentation
JVerbruggen Mar 1, 2021
0820bdf
Removed unnecessary userservice from tagcontroller
JVerbruggen Mar 1, 2021
93eb22b
Updated responsetype attributes
JVerbruggen Mar 1, 2021
4b72b15
Updated HTTP status code delete tag conflict
JVerbruggen Mar 1, 2021
bd0d6ae
Update API/Resources/ProjectTagResourceResult.cs
JVerbruggen Mar 1, 2021
7ed003c
Update API/Resources/TagResourceResult.cs
JVerbruggen Mar 1, 2021
c307c58
Update CHANGELOG.md
JVerbruggen Mar 1, 2021
03a50ec
Fixed role and tag service switch
JVerbruggen Mar 1, 2021
432c089
Updated GUID problems from GetTag
JVerbruggen Mar 1, 2021
083b07a
Renamed Tag to Category
JVerbruggen Mar 4, 2021
8d4bc9c
Removed itemgroup tag identityserver csproj
JVerbruggen Mar 4, 2021
1c47bf9
Corrected an oopsie in identityserver csproj, removing getallasync...
JVerbruggen Mar 4, 2021
c4cf004
Removed GetAllAsync completely
JVerbruggen Mar 4, 2021
78c9176
Added own + other project controller response tags (niray request)
JVerbruggen Mar 4, 2021
cf7e759
Added summary comments, fixed unit tests
JVerbruggen Mar 4, 2021
2c08a6e
Fixed role unit test because of name change tags
JVerbruggen Mar 4, 2021
7369a62
Renamed ALL postman tests and vars (hour long big sigh)
JVerbruggen Mar 4, 2021
b536cf6
Solved merge conflict
JVerbruggen Mar 4, 2021
46d7b47
Updated postman for multiple iterations now, cleaned up project repo
JVerbruggen Mar 8, 2021
ab6e795
Fixed some final translation errors
JVerbruggen Mar 11, 2021
d66adb0
Changed back mysterious apirequesthandler changes
JVerbruggen Mar 11, 2021
6016b3b
Put back merge conflict code ramon
JVerbruggen Mar 11, 2021
2ba79b1
Fixed tagId to ctaegoryId
JVerbruggen Mar 11, 2021
8bf1a91
Altered applicationdbcontextmodelsnapshot
JVerbruggen Mar 11, 2021
0b33a62
Update CHANGELOG.md
JVerbruggen Mar 12, 2021
2454620
Update API/Controllers/ProjectController.cs
JVerbruggen Mar 12, 2021
6cd31f8
Added producesresponsetype to responses controller
JVerbruggen Mar 12, 2021
c72ac39
Resolved invalid ProducesResponseType type attribute
RubenFricke Mar 14, 2021
5bafd35
Added category option to create project endpoint
JVerbruggen Mar 16, 2021
f51dd8a
Merge branch 'feature/362-add-tags-categories' of https://github.com/…
JVerbruggen Mar 16, 2021
65a7d12
Working on adding with update
JVerbruggen Mar 16, 2021
5f87250
Category update on project update not necessary
JVerbruggen Apr 1, 2021
16f96a7
Changed add category to project response type to Project
JVerbruggen Apr 1, 2021
1e12864
Added postman test to test categorize on project create
JVerbruggen Apr 1, 2021
4a71a9f
Repaired postman on project create test
JVerbruggen Apr 1, 2021
96254c9
Merged with develop
JVerbruggen Apr 1, 2021
a69a384
Merged postman collection
JVerbruggen Apr 1, 2021
52be976
Optimised project categories fetching from repo
JVerbruggen Apr 8, 2021
5772c14
removed init from projectcategory list
JVerbruggen Apr 12, 2021
d869c19
changed category name length from max to 100
JVerbruggen Apr 12, 2021
551d1ad
Added category update on project update
JVerbruggen Apr 12, 2021
309787f
Forgot to update problem details guid
JVerbruggen Apr 13, 2021
1e749ab
Merged postman collection manually
JVerbruggen Apr 13, 2021
1225e2c
Merged develop into here
JVerbruggen Apr 13, 2021
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
6 changes: 6 additions & 0 deletions API/Configuration/MappingProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ public MappingProfile()
CreateMap<RoleResource, Role>();
CreateMap<Role, RoleResourceResult>();

CreateMap<TagResource, Tag>();
CreateMap<Tag, TagResourceResult>();
CreateMap<ProjectTag, ProjectTagResourceResult>()
.ForMember(q => q.Id, opt => opt.MapFrom(q=> q.Tag.Id))
.ForMember(q => q.Name, opt => opt.MapFrom(q => q.Tag.Name));

CreateMap<EmbeddedProjectResource, EmbeddedProject>();
CreateMap<EmbeddedProject, EmbeddedProjectResourceResult>();

Expand Down
185 changes: 183 additions & 2 deletions API/Controllers/ProjectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class ProjectController : ControllerBase
private readonly IFileUploader fileUploader;
private readonly IMapper mapper;
private readonly IProjectService projectService;
private readonly IProjectTagService projectTagService;
private readonly ITagService tagService;
private readonly IUserProjectLikeService userProjectLikeService;
private readonly IUserProjectService userProjectService;
private readonly IUserService userService;
Expand All @@ -78,6 +80,8 @@ public class ProjectController : ControllerBase
/// projects.
/// </param>
/// <param name="callToActionOptionService">The call to action option service is used to communicate with the logic layer.</param>
/// <param name="tagService">The tag service is used to work with tags</param>
/// <param name="projectTagService">The project tag service is used to connect projects and tags</param>
public ProjectController(IProjectService projectService,
IUserService userService,
IMapper mapper,
Expand All @@ -86,7 +90,9 @@ public ProjectController(IProjectService projectService,
IAuthorizationHelper authorizationHelper,
IFileUploader fileUploader,
IUserProjectService userProjectService,
ICallToActionOptionService callToActionOptionService)
ICallToActionOptionService callToActionOptionService,
ITagService tagService,
IProjectTagService projectTagService)
{
this.projectService = projectService;
this.userService = userService;
Expand All @@ -97,6 +103,8 @@ public ProjectController(IProjectService projectService,
this.authorizationHelper = authorizationHelper;
this.userProjectService = userProjectService;
this.callToActionOptionService = callToActionOptionService;
this.tagService = tagService;
this.projectTagService = projectTagService;
}

/// <summary>
Expand Down Expand Up @@ -170,7 +178,8 @@ public async Task<IActionResult> GetAllProjects(
filteredProjects.Add(project);
}
}
} else
}
else
{
foreach(Project project in projects)
{
Expand Down Expand Up @@ -792,6 +801,178 @@ public async Task<IActionResult> UnlikeProject(int projectId)
return Ok(mapper.Map<ProjectLike, UserProjectLikeResourceResult>(projectLike));
}

/// <summary>
/// Tag a project
/// </summary>
/// <param name="projectId"></param>
/// <param name="tagId"></param>
JVerbruggen marked this conversation as resolved.
Show resolved Hide resolved
/// <returns>
/// 200 if OK
/// 404 if project or tag not found
/// 401 if user not authorized
/// 409 if project already tagged
/// </returns>
[HttpPost("tag/{projectId}/{tagId}")]
[Authorize]
[ProducesResponseType(StatusCodes.Status200OK)]
JVerbruggen marked this conversation as resolved.
Show resolved Hide resolved
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status409Conflict)]
public async Task<IActionResult> ProjectAddTag(int projectId, int tagId)
{
Project project = await projectService.FindAsync(projectId)
.ConfigureAwait(false);
if(project == null)
{
ProblemDetails problem = new ProblemDetails
{
Title = "Failed to tag the project.",
Detail = "The project could not be found in the database.",
Instance = "1C8D069D-E6CE-43E2-9CF9-D82C0A71A292"
};
return NotFound(problem);
}

Tag tag = await tagService.FindAsync(tagId)
.ConfigureAwait(false);

if(tag == null)
{
ProblemDetails problem = new ProblemDetails
{
Title = "Failed to tag the project.",
Detail = "The tag could not be found in the database.",
Instance = "93C6B5BD-EC14-482A-9907-001C888F3D3F"
};
return NotFound(problem);
}

User user = await HttpContext.GetContextUser(userService)
.ConfigureAwait(false);
bool isAllowed = await authorizationHelper.UserIsAllowed(user,
nameof(Defaults.Scopes.AdminProjectWrite),
nameof(Defaults.Scopes.InstitutionProjectWrite),
project.UserId);

if(!(project.UserId == user.Id || isAllowed))
{
ProblemDetails problem = new ProblemDetails
{
Title = "Failed to tag the project.",
Detail = "The user is not allowed to modify the project.",
Instance = "1243016C-081F-441C-A388-3D56B0998D2E"
};
return Unauthorized(problem);
}

ProjectTag alreadyTagged = await projectTagService.GetProjectTag(projectId, tagId);

if(alreadyTagged != null)
{
ProblemDetails problem = new ProblemDetails
{
Title = "Failed to tag the project.",
Detail = "Project has already been tagged with this tag.",
Instance = "4986CBC6-FB6D-4255-ACE8-833E92B25FBD"
};
return Conflict(problem);
}


ProjectTag projectTag = new ProjectTag(project, tag);
await projectTagService.AddAsync(projectTag)
.ConfigureAwait(false);

projectTagService.Save();

return Ok(mapper.Map<ProjectTag, ProjectTagResourceResult>(projectTag));
}

/// <summary>
/// Remove a tag from a project
/// </summary>
/// <param name="projectId"></param>
/// <param name="tagId"></param>
JVerbruggen marked this conversation as resolved.
Show resolved Hide resolved
/// <returns>
/// 200 if OK
/// 404 if project or tag not found
/// 401 if user not authorized
/// 409 if project not tagged
/// </returns>
[HttpDelete("tag/{projectId}/{tagId}")]
[Authorize]
[ProducesResponseType(StatusCodes.Status200OK)]
JVerbruggen marked this conversation as resolved.
Show resolved Hide resolved
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status409Conflict)]
public async Task<IActionResult> ProjectRemoveTag(int projectId, int tagId)
{
Project project = await projectService.FindAsync(projectId)
.ConfigureAwait(false);
if(project == null)
{
ProblemDetails problem = new ProblemDetails
{
Title = "Failed to remove the tag from the project.",
Detail = "The project could not be found in the database.",
Instance = "2CC94251-9103-4AAC-B461-F99939E78AD0"
};
return NotFound(problem);
}

Tag tag = await tagService.FindAsync(tagId)
.ConfigureAwait(false);

if(tag == null)
{
ProblemDetails problem = new ProblemDetails
{
Title = "Failed to remove the tag from the project.",
Detail = "The tag could not be found in the database.",
Instance = "3E41B5DC-F78B-429B-89AB-1A98A6F65FDC"
};
return NotFound(problem);
}

User user = await HttpContext.GetContextUser(userService)
.ConfigureAwait(false);
bool isAllowed = await authorizationHelper.UserIsAllowed(user,
nameof(Defaults.Scopes.AdminProjectWrite),
nameof(Defaults.Scopes.InstitutionProjectWrite),
project.UserId);

if(!(project.UserId == user.Id || isAllowed))
{
ProblemDetails problem = new ProblemDetails
{
Title = "Failed to remove the tag from the project.",
Detail = "The user is not allowed to modify the project.",
Instance = "4D1878C1-1606-4224-841A-73F30AE4F930"
};
return Unauthorized(problem);
}

ProjectTag alreadyTagged = await projectTagService.GetProjectTag(projectId, tagId);

if(alreadyTagged == null)
{
ProblemDetails problem = new ProblemDetails
{
Title = "Failed to remove the tag from the project.",
Detail = "Project has not been tagged with this tag.",
Instance = "5EABA4F3-47E6-45A7-8522-E87268716912"
};
return Conflict(problem);
}

await projectTagService.RemoveAsync(alreadyTagged.Id)
.ConfigureAwait(false);

projectTagService.Save();

return Ok(mapper.Map<Project, ProjectResourceResult>(project));
}

}

}
Loading