diff --git a/Controllers/HistoriesController.cs b/Controllers/HistoriesController.cs deleted file mode 100644 index 67eee4a..0000000 --- a/Controllers/HistoriesController.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; -using TicketManager.Data; -using TicketManager.Models; - -namespace TicketManager.Controllers -{ - [Authorize] - [Route("api/v1/[controller]")] - [ApiController] - public class HistoriesController : ControllerBase - { - private readonly AppDbContext _context; - - public HistoriesController(AppDbContext context) - { - _context = context; - } - - // GET: api/Histories - [HttpGet] - public async Task>> GetEdits() - { - return await _context.Edits.ToListAsync(); - } - - // GET: api/Histories/5 - [HttpGet("{id}")] - public async Task> GetHistory(int id) - { - var history = await _context.Edits.FindAsync(id); - - if (history == null) - { - return NotFound(); - } - - return history; - } - - // PUT: api/Histories/5 - // To protect from overposting attacks, please enable the specific properties you want to bind to, for - // more details see https://aka.ms/RazorPagesCRUD. - [HttpPut("{id}")] - public async Task PutHistory(int id, History history) - { - if (id != history.Id) - { - return BadRequest(); - } - - _context.Entry(history).State = EntityState.Modified; - - try - { - await _context.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!HistoryExists(id)) - { - return NotFound(); - } - else - { - throw; - } - } - - return NoContent(); - } - - // POST: api/Histories - // To protect from overposting attacks, please enable the specific properties you want to bind to, for - // more details see https://aka.ms/RazorPagesCRUD. - [HttpPost] - public async Task> PostHistory(History history) - { - _context.Edits.Add(history); - await _context.SaveChangesAsync(); - - return CreatedAtAction("GetHistory", new { id = history.Id }, history); - } - - // DELETE: api/Histories/5 - [HttpDelete("{id}")] - public async Task> DeleteHistory(int id) - { - var history = await _context.Edits.FindAsync(id); - if (history == null) - { - return NotFound(); - } - - _context.Edits.Remove(history); - await _context.SaveChangesAsync(); - - return history; - } - - private bool HistoryExists(int id) - { - return _context.Edits.Any(e => e.Id == id); - } - } -} diff --git a/Controllers/ProjectsController.cs b/Controllers/ProjectsController.cs index 1167f67..d8232d9 100644 --- a/Controllers/ProjectsController.cs +++ b/Controllers/ProjectsController.cs @@ -1,16 +1,18 @@ using System.Collections.Generic; using System.Threading.Tasks; +using System.Linq; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using TicketManager.Data; using TicketManager.Models; +using TicketManager.DTO; namespace TicketManager.Controllers { // [Authorize(Roles = "Admin")] - [Authorize] + // [Authorize] [Produces("application/json")] [Route("api/v1/[controller]")] [ApiController] @@ -36,6 +38,7 @@ namespace TicketManager.Controllers [ProducesResponseType(StatusCodes.Status200OK)] public async Task> GetProjects() { + return await _projects.List(); } @@ -53,11 +56,14 @@ namespace TicketManager.Controllers [HttpGet("{id}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task> GetProject(int id) + public async Task> GetProject(int id) { Project project = await _projects.Get(id); - if (project == null) { return NotFound(); } - return project; + if (project == null) + { + return NotFound(); + } + return new ProjectDTO(project); } /// diff --git a/Data/AppDbContext.cs b/Data/AppDbContext.cs index b249c6b..af77479 100644 --- a/Data/AppDbContext.cs +++ b/Data/AppDbContext.cs @@ -12,7 +12,7 @@ namespace TicketManager.Data public DbSet AppUsers { get; set; } public DbSet Tickets { get; set; } public DbSet Assignments { get; set; } - public DbSet Edits { get; set; } + public DbSet Activities { get; set; } public DbSet Notes { get; set; } public DbSet Files { get; set; } diff --git a/Data/AppUserRepository.cs b/Data/AppUserRepository.cs index 66a2cde..a8b4a62 100644 --- a/Data/AppUserRepository.cs +++ b/Data/AppUserRepository.cs @@ -16,7 +16,7 @@ namespace TicketManager.Data .Include(p => p.Assignments) .ThenInclude(a => a.Project) .ThenInclude(p => p.Tickets) - .Include(p => p.Edits); + .Include(p => p.Activities); } public async Task GetUser(Guid id) diff --git a/DataTransfertObjects/ProjectDTO.cs b/DataTransfertObjects/ProjectDTO.cs new file mode 100644 index 0000000..df34f0b --- /dev/null +++ b/DataTransfertObjects/ProjectDTO.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using TicketManager.Models; + +namespace TicketManager.DTO +{ + public class ProjectDTO + { + public ProjectDTO(Project project) + { + Id = project.Id; + Title = project.Title; + Description = project.Description; + CreatedAt = project.CreatedAt; + Progression = project.Progression; + Status = project.Status.ToString(); + Manager = project.Manager; + AppUsers = project.GetMembers(); + Tickets = project.Tickets; + Activities = project.Activities; + Files = project.Files; + } + + public int Id { get; set; } + + public string Title { get; set; } + + public string Description { get; set; } + + public DateTime CreatedAt { get; private set; } = DateTime.Now; + + public DateTime PlannedEnding { get; set; } + + public decimal Progression { get; set; } + + public string Status { get; set; } + + public AppUser Manager { get; set; } + public List AppUsers { get; set; } = new List(); + + public List Tickets { get; set; } = new List(); + + public List Activities { get; set; } = new List(); + + public List Files { get; set; } = new List(); + } +} \ No newline at end of file diff --git a/Models/History.cs b/Models/Activity.cs similarity index 86% rename from Models/History.cs rename to Models/Activity.cs index e039343..dcad951 100644 --- a/Models/History.cs +++ b/Models/Activity.cs @@ -1,9 +1,8 @@ using System; -using System.Collections.Generic; namespace TicketManager.Models { - public class History + public class Activity { public int Id { get; set; } public string Description { get; set; } diff --git a/Models/AppUser.cs b/Models/AppUser.cs index 63f2a4d..41b08c6 100644 --- a/Models/AppUser.cs +++ b/Models/AppUser.cs @@ -42,7 +42,7 @@ namespace TicketManager.Models public List Assignments { get; set; } = new List(); [Display(Name = "Activity")] - public List Edits { get; set; } = new List(); + public List Activities { get; set; } = new List(); // Methods public List GetProjects() diff --git a/Models/Interfaces/ITask.cs b/Models/Interfaces/ITask.cs index 124b8c0..8f83813 100644 --- a/Models/Interfaces/ITask.cs +++ b/Models/Interfaces/ITask.cs @@ -11,18 +11,18 @@ namespace TicketManager.Models string Description { get; set; } DateTime CreatedAt { get; } DateTime PlannedEnding { get; set; } - List Edits { get; set; } + List Activities { get; set; } public virtual void AddLogEntry(string description)//, User user) { - History Edit = new History() + Activity Activity = new Activity() { Description = description, ActivityType = ActivityType.Undefined, // User = user, UpdateDate = DateTime.Now }; - Edits.Add(Edit); + Activities.Add(Activity); } } } diff --git a/Models/Project.cs b/Models/Project.cs index 372cd35..fceedcf 100644 --- a/Models/Project.cs +++ b/Models/Project.cs @@ -26,7 +26,6 @@ namespace TicketManager.Models [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)] public DateTime PlannedEnding { get; set; } - // private decimal _progression; [Display(Name = "Progress")] public decimal Progression { @@ -67,7 +66,7 @@ namespace TicketManager.Models public List Tickets { get; set; } = new List(); - public List Edits { get; set; } = new List(); + public List Activities { get; set; } = new List(); public List Files { get; set; } = new List(); diff --git a/Models/Ticket.cs b/Models/Ticket.cs index 24ec37a..5b28ded 100644 --- a/Models/Ticket.cs +++ b/Models/Ticket.cs @@ -38,7 +38,7 @@ namespace TicketManager.Models // public int ProjectId { get; set; } public List Notes = new List(); - public List Edits = new List(); + public List Activities = new List(); public List Files = new List(); diff --git a/client/src/types/Activity.ts b/client/src/types/Activity.ts new file mode 100644 index 0000000..104c50a --- /dev/null +++ b/client/src/types/Activity.ts @@ -0,0 +1,3 @@ +export interface Activity { + Id: number; +} diff --git a/client/src/types/History.ts b/client/src/types/History.ts deleted file mode 100644 index 9f3fbf3..0000000 --- a/client/src/types/History.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface History { - Id: number; -} diff --git a/client/src/types/Project.ts b/client/src/types/Project.ts index 9b41fcc..6bec951 100644 --- a/client/src/types/Project.ts +++ b/client/src/types/Project.ts @@ -1,12 +1,18 @@ import { Ticket } from "./Ticket"; import { User } from "./User"; +import { Activity } from "./Activity"; export interface Project { id: number; title: string; description: string; - progression: number; - tickets: Ticket[]; - users: User[]; + createdAt: string; plannedEnding: string; + progression: number; + status: string; + manager: User; + users: User[]; + tickets: Ticket[]; + activities: Activity[]; + files: File[]; }