mirror of
https://github.com/rjNemo/ticket_manager
synced 2026-06-06 00:36:39 +00:00
ticket model & endpoints done
This commit is contained in:
parent
734d8e931b
commit
b4b8b6f254
12 changed files with 102 additions and 59 deletions
|
|
@ -10,7 +10,7 @@ using TicketManager.Models;
|
|||
|
||||
namespace TicketManager.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[Route("api/v1/[controller]")]
|
||||
[ApiController]
|
||||
public class UsersController : ControllerBase
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ using TicketManager.Models;
|
|||
|
||||
namespace TicketManager.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[Route("api/v1/[controller]")]
|
||||
[ApiController]
|
||||
public class FilesController : ControllerBase
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ using TicketManager.Models;
|
|||
|
||||
namespace TicketManager.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[Route("api/v1/[controller]")]
|
||||
[ApiController]
|
||||
public class HistoriesController : ControllerBase
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ using TicketManager.Models;
|
|||
|
||||
namespace TicketManager.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[Route("api/v1/[controller]")]
|
||||
[ApiController]
|
||||
public class NotesController : ControllerBase
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ using TicketManager.Models;
|
|||
namespace TicketManager.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/[controller]")]
|
||||
[Route("api/v1/[controller]")]
|
||||
[ApiController]
|
||||
public class ProjectsController : ControllerBase
|
||||
{
|
||||
|
|
@ -152,7 +152,7 @@ namespace TicketManager.Controllers
|
|||
return project.GetMembers();
|
||||
}
|
||||
|
||||
[HttpPut("{id}/setMembers")]
|
||||
[HttpPut("{id}/members")]
|
||||
public async Task<ActionResult<Project>> SetProjectMembers(int id, List<AppUser> projectMembers)
|
||||
{
|
||||
Project project = await GetProjectByIdAsync(id);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ using TicketManager.Models;
|
|||
|
||||
namespace TicketManager.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[Route("api/v1/[controller]")]
|
||||
[ApiController]
|
||||
public class TicketsController : ControllerBase
|
||||
{
|
||||
|
|
@ -25,25 +25,14 @@ namespace TicketManager.Controllers
|
|||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<Ticket>>> GetTickets()
|
||||
{
|
||||
return await _context.Tickets
|
||||
.Include(t => t.Creator)
|
||||
.Include(p => p.Notes)
|
||||
.Include(p => p.Edits)
|
||||
.Include(p => p.Files)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
return await getAllTicketsAsync();
|
||||
}
|
||||
|
||||
// GET: api/Tickets/5
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<Ticket>> GetTicket(int 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);
|
||||
var ticket = await getTicketByIdAsync(id);
|
||||
|
||||
if (ticket == null)
|
||||
{
|
||||
|
|
@ -113,9 +102,47 @@ namespace TicketManager.Controllers
|
|||
return ticket;
|
||||
}
|
||||
|
||||
[HttpGet("{id}/assignees")]
|
||||
public async Task<ActionResult<List<AppUser>>> GetTicketAssignees(int id)
|
||||
{
|
||||
Ticket ticket = await getTicketByIdAsync(id);
|
||||
return ticket.GetAssignees();
|
||||
}
|
||||
|
||||
[HttpPut("{id}/closed")]
|
||||
public async Task<ActionResult> CloseTicket(int id)
|
||||
{
|
||||
Ticket ticket = await getTicketByIdAsync(id);
|
||||
ticket.Close();
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
private bool TicketExists(int id)
|
||||
{
|
||||
return _context.Tickets.Any(e => e.Id == id);
|
||||
}
|
||||
|
||||
private IQueryable<Ticket> ticketQuery() // problem with link
|
||||
{
|
||||
return _context.Tickets
|
||||
.Include(p => p.Project)
|
||||
.ThenInclude(a => a.Assignments)
|
||||
.ThenInclude(p => p.User)
|
||||
// .Include(p => p.Edits)
|
||||
// .Include(p => p.Notes)
|
||||
// .Include(p => p.Files)
|
||||
.Include(p => p.Creator)
|
||||
;
|
||||
}
|
||||
|
||||
private async Task<ActionResult<IEnumerable<Ticket>>> getAllTicketsAsync()
|
||||
{
|
||||
return await ticketQuery().ToListAsync();
|
||||
}
|
||||
|
||||
private async Task<Ticket> getTicketByIdAsync(int id)
|
||||
{
|
||||
return await ticketQuery().FirstOrDefaultAsync(a => a.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace TicketManager.Models
|
|||
|
||||
[DataType(DataType.Date)]
|
||||
[Display(Name = "Member since"), DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}")]
|
||||
public DateTime Created_at { get; set; } = DateTime.Now;
|
||||
public DateTime Created_at { get; private set; } = DateTime.Now;
|
||||
|
||||
// [Display(Name = "Avatar")]
|
||||
// public byte[] Picture { get; set; }
|
||||
|
|
|
|||
|
|
@ -5,11 +5,25 @@ namespace TicketManager.Models
|
|||
{
|
||||
public class File
|
||||
{
|
||||
|
||||
|
||||
public int Id { get; set; }
|
||||
public string Location { get; set; }
|
||||
|
||||
public string FileName { get; set; }
|
||||
|
||||
private string _location;
|
||||
public string Location
|
||||
{
|
||||
get { return _location; }
|
||||
private set
|
||||
{
|
||||
string filesUrl = "";
|
||||
_location = $"{filesUrl}/{FileName}";
|
||||
}
|
||||
}
|
||||
public string Description { get; set; }
|
||||
public int Size { get; set; }
|
||||
public string Format { get; set; }
|
||||
public int Size { get; set; } // deduce auto from FileName
|
||||
public string Format { get; set; } // deduce auto from FileName
|
||||
|
||||
public AppUser AddedBy { get; set; }
|
||||
public int UserId { get; set; }
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace TicketManager.Models
|
|||
{
|
||||
return _progression;
|
||||
}
|
||||
set
|
||||
private set
|
||||
{
|
||||
_progression = Tickets.Count() == 0 ? 0 :
|
||||
(decimal)this.Tickets.
|
||||
|
|
|
|||
|
|
@ -1,14 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
|
||||
namespace TicketManager.Models
|
||||
{
|
||||
public class Ticket : ITask
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(100)]
|
||||
public string Title { get; set; }
|
||||
|
||||
[StringLength(100)]
|
||||
public string Description { get; set; }
|
||||
public DateTime CreatedAt { get; set; } = DateTime.Now;
|
||||
|
||||
[DataType(DataType.Date)]
|
||||
[Display(Name = "Creation Date"), DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}")]
|
||||
public DateTime CreatedAt { get; private set; } = DateTime.Now;
|
||||
|
||||
[DataType(DataType.Date)]
|
||||
[Display(Name = "Estimated Ending Date"), DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}")]
|
||||
public DateTime PlannedEnding { get; set; }
|
||||
|
||||
public Status Status { get; set; } = Status.ToDo;
|
||||
|
|
@ -16,42 +29,28 @@ namespace TicketManager.Models
|
|||
public Difficulty Difficulty { get; set; } = Difficulty.Undefined;
|
||||
public Category Category { get; set; } = Category.Undefined;
|
||||
|
||||
[Display(Name = "Created By")]
|
||||
public AppUser Creator { get; set; }
|
||||
public Guid CreatorId { get; set; }
|
||||
|
||||
[Display(Name = "Project")]
|
||||
public Project Project { get; set; }
|
||||
public int ProjectId { get; set; }
|
||||
private List<Note> _notes;
|
||||
public List<Note> Notes
|
||||
{
|
||||
get
|
||||
{
|
||||
return _notes ?? new List<Note>();
|
||||
}
|
||||
set { _notes = value; }
|
||||
}
|
||||
private List<History> _edits;
|
||||
public List<History> Edits
|
||||
{
|
||||
get
|
||||
{
|
||||
return _edits ?? new List<History>();
|
||||
}
|
||||
set { _edits = value; }
|
||||
}
|
||||
private List<File> _files;
|
||||
public List<File> Files
|
||||
{
|
||||
get
|
||||
{
|
||||
return _files ?? new List<File>();
|
||||
}
|
||||
set { _files = value; }
|
||||
}
|
||||
public List<Note> Notes = new List<Note>();
|
||||
|
||||
public List<History> Edits = new List<History>();
|
||||
|
||||
public List<File> Files = new List<File>();
|
||||
|
||||
// Methods
|
||||
public void GetAssignees() { throw new NotImplementedException("Not Implemented"); }
|
||||
public List<AppUser> GetAssignees()
|
||||
{
|
||||
return Project.Assignments.Select(a => a.User).ToList();
|
||||
}
|
||||
public void GetLastUpdateTime() { throw new NotImplementedException("Not Implemented"); }
|
||||
public void Close() { throw new NotImplementedException("Not Implemented"); }
|
||||
public void AddFile() { throw new NotImplementedException("Not Implemented"); }
|
||||
public void Close()
|
||||
{
|
||||
Status = Status.Done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
## API Documentation
|
||||
|
||||
- [Internal Link. Don't forget to update](https://localhost:5001/swagger/index.html)
|
||||
### v1
|
||||
|
||||
- [Internal Link. Don't forget to update](https://localhost:5001/swagger)
|
||||
|
||||
## Features
|
||||
|
||||
|
|
@ -39,3 +41,4 @@
|
|||
- Ensure Tickets Files belong to Project Files
|
||||
- Write a query class to refactor code and optimize perf on get queries (AsNoTracking)
|
||||
- Async model methods ?
|
||||
- setMembers & removeMembers from project api not working
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ namespace TicketManager
|
|||
{
|
||||
Version = "v1",
|
||||
Title = "Ticket Manager API",
|
||||
Description = "A simple example ASP.NET Core Web API",
|
||||
Description = "Ticket Manger API for Teams",
|
||||
Contact = new OpenApiContact
|
||||
{
|
||||
Name = "Ruidy Nemausat",
|
||||
|
|
@ -91,7 +91,7 @@ namespace TicketManager
|
|||
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Ticket Manager API V1");
|
||||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Ticket Manager API v1");
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue