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.Data;
|
||||||
using TicketManager.Models;
|
using TicketManager.Models;
|
||||||
using TicketManager.DTO;
|
using TicketManager.DTO;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace TicketManager.Controllers
|
namespace TicketManager.Controllers
|
||||||
{
|
{
|
||||||
|
|
@ -263,11 +263,13 @@ namespace TicketManager.Controllers
|
||||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
[HttpPatch("{id}/members")]
|
[HttpPatch("{id}/members")]
|
||||||
public async Task<ActionResult<Project>> SetProjectMembers(int id, List<AppUser> projectMembers)
|
public async Task<ActionResult<Project>> SetProjectMembers(
|
||||||
// [SAFETY] Use RequestDTO to limits posibilities.
|
[FromRoute] int id,
|
||||||
|
[FromBody] Guid[] membersId)
|
||||||
{
|
{
|
||||||
Project project = await _context.Projects
|
Project project = await _context.Projects
|
||||||
.Include(p => p.Assignments)
|
.Include(p => p.Assignments)
|
||||||
|
.ThenInclude(p => p.User)
|
||||||
.FirstOrDefaultAsync(p => p.Id == id);
|
.FirstOrDefaultAsync(p => p.Id == id);
|
||||||
|
|
||||||
if (project == null)
|
if (project == null)
|
||||||
|
|
@ -275,6 +277,10 @@ namespace TicketManager.Controllers
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var projectMembers = await _context.AppUsers
|
||||||
|
.Where(u => membersId.Contains(u.Id))
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
project.SetMembers(projectMembers);
|
project.SetMembers(projectMembers);
|
||||||
_context.Entry(project).State = EntityState.Modified;
|
_context.Entry(project).State = EntityState.Modified;
|
||||||
try
|
try
|
||||||
|
|
@ -282,10 +288,10 @@ namespace TicketManager.Controllers
|
||||||
|
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
catch (DbUpdateException /* ex */)
|
catch (DbUpdateException ex)
|
||||||
{
|
{
|
||||||
//Log the error (uncomment ex variable name and write a log.)
|
//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, " +
|
"Try again, and if the problem persists, " +
|
||||||
"see your system administrator.");
|
"see your system administrator.");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace TicketManager.Models
|
||||||
int Id { get; set; }
|
int Id { get; set; }
|
||||||
string Title { get; set; }
|
string Title { get; set; }
|
||||||
string Description { get; set; }
|
string Description { get; set; }
|
||||||
DateTime CreatedAt { get; }
|
DateTime CreationDate { get; }
|
||||||
DateTime PlannedEnding { get; set; }
|
DateTime PlannedEnding { get; set; }
|
||||||
List<Activity> Activities { get; set; }
|
List<Activity> Activities { get; set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ FILE=Scripts/response.json
|
||||||
rm $FILE
|
rm $FILE
|
||||||
date >> $FILE
|
date >> $FILE
|
||||||
|
|
||||||
URL=$ROOT/tickets/
|
URL=$ROOT/projects/1/members
|
||||||
cat $URL >> $FILE
|
cat $URL >> $FILE
|
||||||
|
|
||||||
curl --insecure $URL | json_pp >> $FILE
|
curl --insecure $URL | json_pp >> $FILE
|
||||||
Loading…
Reference in a new issue