diff --git a/Controllers/ProjectsController.cs b/Controllers/ProjectsController.cs index f5ac843..a6b7971 100644 --- a/Controllers/ProjectsController.cs +++ b/Controllers/ProjectsController.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Mime; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -11,6 +12,7 @@ using TicketManager.Models; namespace TicketManager.Controllers { + [Produces("application/json")] [Route("api/[controller]")] [ApiController] public class ProjectsController : ControllerBase @@ -22,15 +24,37 @@ namespace TicketManager.Controllers _context = context; } - // GET: api/Projects + /// + /// Returns all existing projects. + /// + /// + /// Sample request: + /// + /// GET: api/Projects + /// + /// + /// Returns all existing projects [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] public async Task>> GetProjects() { return await GetAllProjectsAsync(); } - // GET: api/Projects/5 + /// + /// Returns a specific project. + /// + /// + /// Sample request: + /// + /// GET: api/Projects/2 + /// + /// + /// Returns a specific project + /// If the required project is null [HttpGet("{id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task> GetProject(int id) { Project project = await GetProjectByIdAsync(id); @@ -41,10 +65,30 @@ namespace TicketManager.Controllers return project; } - // PUT: api/Projects/5 - // To protect from overposting attacks, please enable the specific properties you want to bind to, for - // more details see https://aka.ms/RazorPagesCRUD. + /// + /// Updates a specific project. + /// + /// + /// 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" + /// } + /// + /// + /// Returns the modified project + /// Request was succesful but no content is changed + /// If the required project is null [HttpPut("{id}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task PutProject(int id, Project project) { if (id != project.Id) diff --git a/Models/Project.cs b/Models/Project.cs index ca9d38d..628c740 100644 --- a/Models/Project.cs +++ b/Models/Project.cs @@ -18,6 +18,12 @@ namespace TicketManager.Models [Display(Name = "Short Description")] public string Description { get; set; } + [DataType(DataType.EmailAddress)] + public string Email { get; set; } + + [DataType(DataType.PhoneNumber)] + public string Phone { get; set; } + [DataType(DataType.Date)] [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = false)] public DateTime CreatedAt { get; private set; } = DateTime.Now; @@ -47,13 +53,10 @@ namespace TicketManager.Models public List Assignments { get; set; } = new List(); - public List Tickets { get; set; } = new List(); - public List Edits { get; set; } = new List(); - public List Files { get; set; } = new List(); // Methods diff --git a/README.md b/README.md index 26d4bde..f8613bc 100644 --- a/README.md +++ b/README.md @@ -38,3 +38,4 @@ - Ensure Tickets Edits belong to Project Edits - Ensure Tickets Files belong to Project Files - Write a query class to refactor code and optimize perf on get queries (AsNoTracking) +- Async model methods ? diff --git a/Startup.cs b/Startup.cs index 37ce7c0..0a40edf 100644 --- a/Startup.cs +++ b/Startup.cs @@ -20,6 +20,7 @@ using TicketManager.Models; using Microsoft.AspNetCore.Mvc.NewtonsoftJson; using Newtonsoft.Json; +[assembly: ApiController] namespace TicketManager { public class Startup