mirror of
https://github.com/rjNemo/ticket_manager
synced 2026-06-06 00:36:39 +00:00
Updated SetProjectsMembers to take Guid list as arg
This commit is contained in:
parent
5fe28f5c38
commit
02a123b247
3 changed files with 13 additions and 7 deletions
|
|
@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore;
|
|||
using TicketManager.Data;
|
||||
using TicketManager.Models;
|
||||
using TicketManager.DTO;
|
||||
|
||||
using System;
|
||||
|
||||
namespace TicketManager.Controllers
|
||||
{
|
||||
|
|
@ -263,11 +263,13 @@ namespace TicketManager.Controllers
|
|||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[HttpPatch("{id}/members")]
|
||||
public async Task<ActionResult<Project>> SetProjectMembers(int id, List<AppUser> projectMembers)
|
||||
// [SAFETY] Use RequestDTO to limits posibilities.
|
||||
public async Task<ActionResult<Project>> SetProjectMembers(
|
||||
[FromRoute] int id,
|
||||
[FromBody] Guid[] membersId)
|
||||
{
|
||||
Project project = await _context.Projects
|
||||
.Include(p => p.Assignments)
|
||||
.ThenInclude(p => p.User)
|
||||
.FirstOrDefaultAsync(p => p.Id == id);
|
||||
|
||||
if (project == null)
|
||||
|
|
@ -275,6 +277,10 @@ namespace TicketManager.Controllers
|
|||
return NotFound();
|
||||
}
|
||||
|
||||
var projectMembers = await _context.AppUsers
|
||||
.Where(u => membersId.Contains(u.Id))
|
||||
.ToListAsync();
|
||||
|
||||
project.SetMembers(projectMembers);
|
||||
_context.Entry(project).State = EntityState.Modified;
|
||||
try
|
||||
|
|
@ -282,10 +288,10 @@ namespace TicketManager.Controllers
|
|||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateException /* ex */)
|
||||
catch (DbUpdateException ex)
|
||||
{
|
||||
//Log the error (uncomment ex variable name and write a log.)
|
||||
ModelState.AddModelError("", "Unable to save changes. " +
|
||||
ModelState.AddModelError(ex.ToString(), "Unable to save changes. " +
|
||||
"Try again, and if the problem persists, " +
|
||||
"see your system administrator.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace TicketManager.Models
|
|||
int Id { get; set; }
|
||||
string Title { get; set; }
|
||||
string Description { get; set; }
|
||||
DateTime CreatedAt { get; }
|
||||
DateTime CreationDate { get; }
|
||||
DateTime PlannedEnding { get; set; }
|
||||
List<Activity> Activities { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ FILE=Scripts/response.json
|
|||
rm $FILE
|
||||
date >> $FILE
|
||||
|
||||
URL=$ROOT/tickets/
|
||||
URL=$ROOT/projects/1/members
|
||||
cat $URL >> $FILE
|
||||
|
||||
curl --insecure $URL | json_pp >> $FILE
|
||||
Loading…
Reference in a new issue