This commit is contained in:
Ruidy Nemausat 2020-02-11 23:36:39 +01:00
parent 0fa327ee7c
commit a46c9aaa0b
4 changed files with 57 additions and 8 deletions

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Mime;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -11,6 +12,7 @@ using TicketManager.Models;
namespace TicketManager.Controllers namespace TicketManager.Controllers
{ {
[Produces("application/json")]
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController] [ApiController]
public class ProjectsController : ControllerBase public class ProjectsController : ControllerBase
@ -22,15 +24,37 @@ namespace TicketManager.Controllers
_context = context; _context = context;
} }
// GET: api/Projects /// <summary>
/// Returns all existing projects.
/// </summary>
/// <remarks>
/// Sample request:
///
/// GET: api/Projects
///
/// </remarks>
/// <response code="200">Returns all existing projects</response>
[HttpGet] [HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<IEnumerable<Project>>> GetProjects() public async Task<ActionResult<IEnumerable<Project>>> GetProjects()
{ {
return await GetAllProjectsAsync(); return await GetAllProjectsAsync();
} }
// GET: api/Projects/5 /// <summary>
/// Returns a specific project.
/// </summary>
/// <remarks>
/// Sample request:
///
/// GET: api/Projects/2
///
/// </remarks>
/// <response code="200">Returns a specific project</response>
/// <response code="404">If the required project is null</response>
[HttpGet("{id}")] [HttpGet("{id}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<Project>> GetProject(int id) public async Task<ActionResult<Project>> GetProject(int id)
{ {
Project project = await GetProjectByIdAsync(id); Project project = await GetProjectByIdAsync(id);
@ -41,10 +65,30 @@ namespace TicketManager.Controllers
return project; return project;
} }
// PUT: api/Projects/5 /// <summary>
// To protect from overposting attacks, please enable the specific properties you want to bind to, for /// Updates a specific project.
// more details see https://aka.ms/RazorPagesCRUD. /// </summary>
/// <remarks>
/// Sample request:
///
/// PUT: api/Projects/3
/// {
/// "id": "357727fd-5262-4522-b8a3-38271d43de84",
/// "firstName": "Thomas",
/// "lastName": "Price",
/// "presentation": "New Team?!",
/// "email": "tp@mail.com",
/// "phone": "0198237645"
/// }
///
/// </remarks>
/// <response code="200">Returns the modified project</response>
/// <response code="204">Request was succesful but no content is changed</response>
/// <response code="404">If the required project is null</response>
[HttpPut("{id}")] [HttpPut("{id}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> PutProject(int id, Project project) public async Task<IActionResult> PutProject(int id, Project project)
{ {
if (id != project.Id) if (id != project.Id)

View file

@ -18,6 +18,12 @@ namespace TicketManager.Models
[Display(Name = "Short Description")] [Display(Name = "Short Description")]
public string Description { get; set; } public string Description { get; set; }
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
[DataType(DataType.PhoneNumber)]
public string Phone { get; set; }
[DataType(DataType.Date)] [DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = false)] [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = false)]
public DateTime CreatedAt { get; private set; } = DateTime.Now; public DateTime CreatedAt { get; private set; } = DateTime.Now;
@ -47,13 +53,10 @@ namespace TicketManager.Models
public List<Assignment> Assignments { get; set; } = new List<Assignment>(); public List<Assignment> Assignments { get; set; } = new List<Assignment>();
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<History> Edits { get; set; } = new List<History>();
public List<File> Files { get; set; } = new List<File>(); public List<File> Files { get; set; } = new List<File>();
// Methods // Methods

View file

@ -38,3 +38,4 @@
- Ensure Tickets Edits belong to Project Edits - Ensure Tickets Edits belong to Project Edits
- Ensure Tickets Files belong to Project Files - Ensure Tickets Files belong to Project Files
- Write a query class to refactor code and optimize perf on get queries (AsNoTracking) - Write a query class to refactor code and optimize perf on get queries (AsNoTracking)
- Async model methods ?

View file

@ -20,6 +20,7 @@ using TicketManager.Models;
using Microsoft.AspNetCore.Mvc.NewtonsoftJson; using Microsoft.AspNetCore.Mvc.NewtonsoftJson;
using Newtonsoft.Json; using Newtonsoft.Json;
[assembly: ApiController]
namespace TicketManager namespace TicketManager
{ {
public class Startup public class Startup