diff --git a/Controllers/ProjectsController.cs b/Controllers/ProjectsController.cs
index 5e6ffca..2087b2d 100644
--- a/Controllers/ProjectsController.cs
+++ b/Controllers/ProjectsController.cs
@@ -65,11 +65,6 @@ namespace TicketManager.Controllers
return project;
}
-
-
- // PUT: api/Projects/5
- // To protect from overposting attacks, please enable the specific properties you want to bind to, for
- // more details see https://aka.ms/RazorPagesCRUD.
///
/// Updates a specific project.
///
@@ -122,10 +117,26 @@ namespace TicketManager.Controllers
return NoContent();
}
- // POST: api/Projects
- // To protect from overposting attacks, please enable the specific properties you want to bind to, for
- // more details see https://aka.ms/RazorPagesCRUD.
+ ///
+ /// Creates a project.
+ ///
+ ///
+ /// Sample request:
+ ///
+ /// POST: api/Projects/
+ /// {
+ /// "firstName": "Thomas",
+ /// "lastName": "Price",
+ /// "presentation": "New Team?!",
+ /// "email": "tp@mail.com",
+ /// "phone": "0198237645"
+ /// }
+ ///
+ ///
+ /// Returns the created project
[HttpPost]
+ [ProducesResponseType(StatusCodes.Status201Created)]
+ [ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task> PostProject(Project project)
{
_context.Projects.Add(project);
@@ -134,41 +145,21 @@ namespace TicketManager.Controllers
return CreatedAtAction("GetProject", new { id = project.Id }, project);
}
- [HttpPost("{id}/addmembers")]
- public async Task> PostAssignment(int id, List usersToAdd)
- {
- var project = await _context.Projects.FindAsync(id);
- if (project == null)
- { return NotFound(); }
- project.AddMembers(usersToAdd);
- // foreach (var assignment in assignments)
- // { _context.Assignments.Add(assignment); }
-
- await _context.SaveChangesAsync();
- // try
- // {
- // await _context.SaveChangesAsync();
- // }
- // catch (DbUpdateException)
- // {
- // if (AssignmentExists(assignment.ProjectId))
- // {
- // return Conflict();
- // }
- // else
- // {
- // throw;
- // }
- // }
-
- // return CreatedAtAction("GetAssignment", new { id = assignment.ProjectId }, assignment);
- return project;
- }
-
- // DELETE: api/Projects/5
+ ///
+ /// Deletes a project.
+ ///
+ ///
+ /// Sample request:
+ ///
+ /// DELETE: api/Projects/5
+ ///
+ ///
+ /// Returns the deleted project
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status404NotFound)]
[HttpDelete("{id}")]
public async Task> DeleteProject(int id)
{
@@ -177,13 +168,23 @@ namespace TicketManager.Controllers
{
return NotFound();
}
-
_context.Projects.Remove(project);
await _context.SaveChangesAsync();
-
return project;
}
- // GET: api/Projects/5/Members
+
+ ///
+ /// Gets a project members.
+ ///
+ ///
+ /// Sample request:
+ ///
+ /// GET: api/Projects/5/Members
+ ///
+ ///
+ /// Returns the project members
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status404NotFound)]
[HttpGet("{id}/members")]
public async Task>> GetProjectMembers(int id)
{
@@ -193,6 +194,25 @@ namespace TicketManager.Controllers
return project.GetMembers();
}
+ ///
+ /// Updates a project members.
+ ///
+ ///
+ /// Sample request:
+ ///
+ /// PUT: api/Projects/5/Members
+ /// {
+ /// "id": "357727fd-5262-4522-b8a3-38271d43de84",
+ /// "firstName": "Thomas",
+ /// "lastName": "Price",
+ /// "presentation": "New Team?!",
+ /// "email": "tp@mail.com",
+ /// "phone": "0198237645"
+ /// }
+ ///
+ /// No content
+ [ProducesResponseType(StatusCodes.Status204NoContent)]
+ [ProducesResponseType(StatusCodes.Status404NotFound)]
[HttpPut("{id}/members")]
public async Task> SetProjectMembers(int id, List projectMembers)
{
@@ -212,6 +232,26 @@ namespace TicketManager.Controllers
return NoContent();
}
+ ///
+ /// Assign a user to a project.
+ ///
+ ///
+ /// Sample request:
+ ///
+ /// POST: api/Projects/addmembers
+ /// [{
+ /// "id": "357727fd-5262-4522-b8a3-38271d43de84",
+ /// "firstName": "Thomas",
+ /// "lastName": "Price",
+ /// "presentation": "New Team?!",
+ /// "email": "tp@mail.com",
+ /// "phone": "0198237645"
+ /// }]
+ ///
+ ///
+ /// Returns the created project
+ [ProducesResponseType(StatusCodes.Status204NoContent)]
+ [ProducesResponseType(StatusCodes.Status404NotFound)]
[HttpPut("{id}/addMembers")]
public async Task> AddMembersToProject(int id, List usersToAdd)
{
@@ -235,6 +275,26 @@ namespace TicketManager.Controllers
return NoContent();
}
+ ///
+ /// Remove a user to a project.
+ ///
+ ///
+ /// Sample request:
+ ///
+ /// PUT: api/Projects/removemembers
+ /// [{
+ /// "id": "357727fd-5262-4522-b8a3-38271d43de84",
+ /// "firstName": "Thomas",
+ /// "lastName": "Price",
+ /// "presentation": "New Team?!",
+ /// "email": "tp@mail.com",
+ /// "phone": "0198237645"
+ /// }]
+ ///
+ ///
+ /// Returns the created project
+ [ProducesResponseType(StatusCodes.Status204NoContent)]
+ [ProducesResponseType(StatusCodes.Status404NotFound)]
[HttpPut("{id}/removeMembers")]
public async Task> RemoveMembersFromProject(int id, List usersToRemove)
{
@@ -258,10 +318,7 @@ namespace TicketManager.Controllers
{
return _context.Projects.Any(e => e.Id == id);
}
- private bool AssignmentExists(int id)
- {
- return _context.Assignments.Any(e => e.ProjectId == id);
- }
+
private async Task>> GetAllProjectsAsync()
{