mirror of
https://github.com/rjNemo/ticket_manager
synced 2026-06-06 00:36:39 +00:00
projectDTO created. Changed entity name History to Activity
This commit is contained in:
parent
112ccbefee
commit
2343747b1c
13 changed files with 78 additions and 131 deletions
|
|
@ -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<ActionResult<IEnumerable<History>>> GetEdits()
|
|
||||||
{
|
|
||||||
return await _context.Edits.ToListAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: api/Histories/5
|
|
||||||
[HttpGet("{id}")]
|
|
||||||
public async Task<ActionResult<History>> 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<IActionResult> 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<ActionResult<History>> 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<ActionResult<History>> 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +1,18 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Linq;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using TicketManager.Data;
|
using TicketManager.Data;
|
||||||
using TicketManager.Models;
|
using TicketManager.Models;
|
||||||
|
using TicketManager.DTO;
|
||||||
|
|
||||||
namespace TicketManager.Controllers
|
namespace TicketManager.Controllers
|
||||||
{
|
{
|
||||||
// [Authorize(Roles = "Admin")]
|
// [Authorize(Roles = "Admin")]
|
||||||
[Authorize]
|
// [Authorize]
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
[Route("api/v1/[controller]")]
|
[Route("api/v1/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
|
@ -36,6 +38,7 @@ namespace TicketManager.Controllers
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
public async Task<IEnumerable<Project>> GetProjects()
|
public async Task<IEnumerable<Project>> GetProjects()
|
||||||
{
|
{
|
||||||
|
|
||||||
return await _projects.List();
|
return await _projects.List();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,11 +56,14 @@ namespace TicketManager.Controllers
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
public async Task<ActionResult<Project>> GetProject(int id)
|
public async Task<ActionResult<ProjectDTO>> GetProject(int id)
|
||||||
{
|
{
|
||||||
Project project = await _projects.Get(id);
|
Project project = await _projects.Get(id);
|
||||||
if (project == null) { return NotFound(); }
|
if (project == null)
|
||||||
return project;
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
return new ProjectDTO(project);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace TicketManager.Data
|
||||||
public DbSet<AppUser> AppUsers { get; set; }
|
public DbSet<AppUser> AppUsers { get; set; }
|
||||||
public DbSet<Ticket> Tickets { get; set; }
|
public DbSet<Ticket> Tickets { get; set; }
|
||||||
public DbSet<Assignment> Assignments { get; set; }
|
public DbSet<Assignment> Assignments { get; set; }
|
||||||
public DbSet<History> Edits { get; set; }
|
public DbSet<Activity> Activities { get; set; }
|
||||||
public DbSet<Note> Notes { get; set; }
|
public DbSet<Note> Notes { get; set; }
|
||||||
public DbSet<File> Files { get; set; }
|
public DbSet<File> Files { get; set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace TicketManager.Data
|
||||||
.Include(p => p.Assignments)
|
.Include(p => p.Assignments)
|
||||||
.ThenInclude(a => a.Project)
|
.ThenInclude(a => a.Project)
|
||||||
.ThenInclude(p => p.Tickets)
|
.ThenInclude(p => p.Tickets)
|
||||||
.Include(p => p.Edits);
|
.Include(p => p.Activities);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<AppUser> GetUser(Guid id)
|
public async Task<AppUser> GetUser(Guid id)
|
||||||
|
|
|
||||||
47
DataTransfertObjects/ProjectDTO.cs
Normal file
47
DataTransfertObjects/ProjectDTO.cs
Normal file
|
|
@ -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<AppUser> AppUsers { get; set; } = new List<AppUser>();
|
||||||
|
|
||||||
|
public List<Ticket> Tickets { get; set; } = new List<Ticket>();
|
||||||
|
|
||||||
|
public List<Activity> Activities { get; set; } = new List<Activity>();
|
||||||
|
|
||||||
|
public List<File> Files { get; set; } = new List<File>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace TicketManager.Models
|
namespace TicketManager.Models
|
||||||
{
|
{
|
||||||
public class History
|
public class Activity
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
|
|
@ -42,7 +42,7 @@ namespace TicketManager.Models
|
||||||
public List<Assignment> Assignments { get; set; } = new List<Assignment>();
|
public List<Assignment> Assignments { get; set; } = new List<Assignment>();
|
||||||
|
|
||||||
[Display(Name = "Activity")]
|
[Display(Name = "Activity")]
|
||||||
public List<History> Edits { get; set; } = new List<History>();
|
public List<Activity> Activities { get; set; } = new List<Activity>();
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
public List<Project> GetProjects()
|
public List<Project> GetProjects()
|
||||||
|
|
|
||||||
|
|
@ -11,18 +11,18 @@ namespace TicketManager.Models
|
||||||
string Description { get; set; }
|
string Description { get; set; }
|
||||||
DateTime CreatedAt { get; }
|
DateTime CreatedAt { get; }
|
||||||
DateTime PlannedEnding { get; set; }
|
DateTime PlannedEnding { get; set; }
|
||||||
List<History> Edits { get; set; }
|
List<Activity> Activities { get; set; }
|
||||||
|
|
||||||
public virtual void AddLogEntry(string description)//, User user)
|
public virtual void AddLogEntry(string description)//, User user)
|
||||||
{
|
{
|
||||||
History Edit = new History()
|
Activity Activity = new Activity()
|
||||||
{
|
{
|
||||||
Description = description,
|
Description = description,
|
||||||
ActivityType = ActivityType.Undefined,
|
ActivityType = ActivityType.Undefined,
|
||||||
// User = user,
|
// User = user,
|
||||||
UpdateDate = DateTime.Now
|
UpdateDate = DateTime.Now
|
||||||
};
|
};
|
||||||
Edits.Add(Edit);
|
Activities.Add(Activity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ namespace TicketManager.Models
|
||||||
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
|
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
|
||||||
public DateTime PlannedEnding { get; set; }
|
public DateTime PlannedEnding { get; set; }
|
||||||
|
|
||||||
// private decimal _progression;
|
|
||||||
[Display(Name = "Progress")]
|
[Display(Name = "Progress")]
|
||||||
public decimal Progression
|
public decimal Progression
|
||||||
{
|
{
|
||||||
|
|
@ -67,7 +66,7 @@ namespace TicketManager.Models
|
||||||
|
|
||||||
public List<Ticket> Tickets { get; set; } = new List<Ticket>();
|
public List<Ticket> Tickets { get; set; } = new List<Ticket>();
|
||||||
|
|
||||||
public List<History> Edits { get; set; } = new List<History>();
|
public List<Activity> Activities { get; set; } = new List<Activity>();
|
||||||
|
|
||||||
public List<File> Files { get; set; } = new List<File>();
|
public List<File> Files { get; set; } = new List<File>();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ namespace TicketManager.Models
|
||||||
// public int ProjectId { get; set; }
|
// public int ProjectId { get; set; }
|
||||||
public List<Note> Notes = new List<Note>();
|
public List<Note> Notes = new List<Note>();
|
||||||
|
|
||||||
public List<History> Edits = new List<History>();
|
public List<Activity> Activities = new List<Activity>();
|
||||||
|
|
||||||
public List<File> Files = new List<File>();
|
public List<File> Files = new List<File>();
|
||||||
|
|
||||||
|
|
|
||||||
3
client/src/types/Activity.ts
Normal file
3
client/src/types/Activity.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
export interface Activity {
|
||||||
|
Id: number;
|
||||||
|
}
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
export interface History {
|
|
||||||
Id: number;
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +1,18 @@
|
||||||
import { Ticket } from "./Ticket";
|
import { Ticket } from "./Ticket";
|
||||||
import { User } from "./User";
|
import { User } from "./User";
|
||||||
|
import { Activity } from "./Activity";
|
||||||
|
|
||||||
export interface Project {
|
export interface Project {
|
||||||
id: number;
|
id: number;
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
progression: number;
|
createdAt: string;
|
||||||
tickets: Ticket[];
|
|
||||||
users: User[];
|
|
||||||
plannedEnding: string;
|
plannedEnding: string;
|
||||||
|
progression: number;
|
||||||
|
status: string;
|
||||||
|
manager: User;
|
||||||
|
users: User[];
|
||||||
|
tickets: Ticket[];
|
||||||
|
activities: Activity[];
|
||||||
|
files: File[];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue