json circleref problem uncovered

This commit is contained in:
Ruidy Nemausat 2020-02-10 11:48:38 +01:00
parent 4428762398
commit ec9e31171e
8 changed files with 51 additions and 21 deletions

View file

@ -25,7 +25,13 @@ namespace TicketManager.Controllers
[HttpGet] [HttpGet]
public async Task<ActionResult<IEnumerable<Project>>> GetProjects() public async Task<ActionResult<IEnumerable<Project>>> GetProjects()
{ {
return await _context.Projects.ToListAsync(); return await _context.Projects
.Include(p => p.Assignments)
.Include(p => p.Tickets)
.Include(p => p.Manager)
.Include(p => p.Files)
.AsNoTracking()
.ToListAsync();
} }
// GET: api/Projects/5 // GET: api/Projects/5
@ -34,6 +40,10 @@ namespace TicketManager.Controllers
{ {
var project = await _context.Projects var project = await _context.Projects
.Include(p => p.Assignments) .Include(p => p.Assignments)
.Include(p => p.Tickets)
.Include(p => p.Manager)
.Include(p => p.Files)
.AsNoTracking()
.FirstOrDefaultAsync(p => p.Id == id); .FirstOrDefaultAsync(p => p.Id == id);
// .FindAsync(id); // .FindAsync(id);

View file

@ -25,14 +25,25 @@ namespace TicketManager.Controllers
[HttpGet] [HttpGet]
public async Task<ActionResult<IEnumerable<Ticket>>> GetTickets() public async Task<ActionResult<IEnumerable<Ticket>>> GetTickets()
{ {
return await _context.Tickets.ToListAsync(); return await _context.Tickets
.Include(t => t.Creator)
.Include(p => p.Notes)
.Include(p => p.Edits)
.Include(p => p.Files)
.AsNoTracking()
.ToListAsync();
} }
// GET: api/Tickets/5 // GET: api/Tickets/5
[HttpGet("{id}")] [HttpGet("{id}")]
public async Task<ActionResult<Ticket>> GetTicket(int id) public async Task<ActionResult<Ticket>> GetTicket(int id)
{ {
var ticket = await _context.Tickets.FindAsync(id); var ticket = await _context.Tickets
.Include(t => t.Creator)
.Include(p => p.Notes)
.Include(p => p.Edits)
.Include(p => p.Files)
.FirstOrDefaultAsync(t => t.Id == id);
if (ticket == null) if (ticket == null)
{ {

View file

@ -25,14 +25,20 @@ namespace TicketManager.Controllers
[HttpGet] [HttpGet]
public async Task<ActionResult<IEnumerable<User>>> GetUsers() public async Task<ActionResult<IEnumerable<User>>> GetUsers()
{ {
return await _context.Users.ToListAsync(); return await _context.Users
.Include(p => p.Assignments)
.Include(p => p.Edits)
.ToListAsync();
} }
// GET: api/Users/5 // GET: api/Users/5
[HttpGet("{id}")] [HttpGet("{id}")]
public async Task<ActionResult<User>> GetUser(int id) public async Task<ActionResult<User>> GetUser(Guid id)
{ {
var user = await _context.Users.FindAsync(id); var user = await _context.Users
.Include(p => p.Assignments)
.Include(p => p.Edits)
.FirstOrDefaultAsync(p => p.Id == id);
if (user == null) if (user == null)
{ {
@ -46,7 +52,7 @@ namespace TicketManager.Controllers
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://aka.ms/RazorPagesCRUD. // more details see https://aka.ms/RazorPagesCRUD.
[HttpPut("{id}")] [HttpPut("{id}")]
public async Task<IActionResult> PutUser(int id, User user) public async Task<IActionResult> PutUser(Guid id, User user)
{ {
if (id != user.Id) if (id != user.Id)
{ {
@ -102,7 +108,7 @@ namespace TicketManager.Controllers
return user; return user;
} }
private bool UserExists(int id) private bool UserExists(Guid id)
{ {
return _context.Users.Any(e => e.Id == id); return _context.Users.Any(e => e.Id == id);
} }

View file

@ -1,10 +1,12 @@
using System;
namespace TicketManager.Models namespace TicketManager.Models
{ {
public class Assignment public class Assignment
{ {
public int Id { get; set; } public int Id { get; set; }
public User User { get; set; } public User User { get; set; }
public int UserId { get; set; } public Guid UserId { get; set; }
public Project Project { get; set; } public Project Project { get; set; }
public int ProjectId { get; set; } public int ProjectId { get; set; }
} }

View file

@ -24,7 +24,7 @@ namespace TicketManager.Models
public Status Status { get; set; } = Status.ToDo; public Status Status { get; set; } = Status.ToDo;
public User Manager { get; set; } public User Manager { get; set; }
public int ManagerId { get; set; } public Guid ManagerId { get; set; }
private List<Assignment> _assignments; private List<Assignment> _assignments;
public List<Assignment> Assignments public List<Assignment> Assignments
{ {
@ -40,13 +40,13 @@ namespace TicketManager.Models
{ return _tickets ?? new List<Ticket>(); } { return _tickets ?? new List<Ticket>(); }
set { _tickets = value; } set { _tickets = value; }
} }
private List<History> _edits; // private List<History> _edits;
public List<History> Edits // public List<History> Edits
{ // {
get // get
{ return _edits ?? new List<History>(); } // { return _edits ?? new List<History>(); }
set { _edits = value; } // set { _edits = value; }
} // }
private List<File> _files; private List<File> _files;
public List<File> Files public List<File> Files
{ {

View file

@ -17,9 +17,9 @@ namespace TicketManager.Models
public Category Category { get; set; } = Category.Undefined; public Category Category { get; set; } = Category.Undefined;
public User Creator { get; set; } public User Creator { get; set; }
public int CreatorId { get; set; } public Guid CreatorId { get; set; }
public Project Project { get; set; } // public Project Project { get; set; }
public int ProjectId { get; set; } // public int ProjectId { get; set; }
private List<Note> _notes; private List<Note> _notes;
public List<Note> Notes public List<Note> Notes
{ {

View file

@ -5,7 +5,7 @@ namespace TicketManager.Models
{ {
public class User public class User
{ {
public int Id { get; set; } public Guid Id { get; set; }
public string FirstName { get; set; } public string FirstName { get; set; }
public string LastName { get; set; } public string LastName { get; set; }
public string FullName => $"{FirstName} {LastName}"; public string FullName => $"{FirstName} {LastName}";

1
client/src/react-app-env.d.ts vendored Normal file
View file

@ -0,0 +1 @@
/// <reference types="react-scripts" />