projectDTO created. Changed entity name History to Activity

This commit is contained in:
Ruidy Nemausat 2020-02-21 13:57:03 +01:00
parent 112ccbefee
commit 2343747b1c
13 changed files with 78 additions and 131 deletions

View file

@ -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);
}
}
}

View file

@ -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<IEnumerable<Project>> GetProjects()
{
return await _projects.List();
}
@ -53,11 +56,14 @@ namespace TicketManager.Controllers
[HttpGet("{id}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[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);
if (project == null) { return NotFound(); }
return project;
if (project == null)
{
return NotFound();
}
return new ProjectDTO(project);
}
/// <summary>

View file

@ -12,7 +12,7 @@ namespace TicketManager.Data
public DbSet<AppUser> AppUsers { get; set; }
public DbSet<Ticket> Tickets { 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<File> Files { get; set; }

View file

@ -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<AppUser> GetUser(Guid id)

View 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>();
}
}

View file

@ -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; }

View file

@ -42,7 +42,7 @@ namespace TicketManager.Models
public List<Assignment> Assignments { get; set; } = new List<Assignment>();
[Display(Name = "Activity")]
public List<History> Edits { get; set; } = new List<History>();
public List<Activity> Activities { get; set; } = new List<Activity>();
// Methods
public List<Project> GetProjects()

View file

@ -11,18 +11,18 @@ namespace TicketManager.Models
string Description { get; set; }
DateTime CreatedAt { get; }
DateTime PlannedEnding { get; set; }
List<History> Edits { get; set; }
List<Activity> 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);
}
}
}

View file

@ -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<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>();

View file

@ -38,7 +38,7 @@ namespace TicketManager.Models
// public int ProjectId { get; set; }
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>();

View file

@ -0,0 +1,3 @@
export interface Activity {
Id: number;
}

View file

@ -1,3 +0,0 @@
export interface History {
Id: number;
}

View file

@ -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[];
}