mirror of
https://github.com/rjNemo/ticket_manager
synced 2026-06-06 00:36:39 +00:00
preparation to api testing with postman
This commit is contained in:
parent
f40470035d
commit
0ca71cfcf9
7 changed files with 77 additions and 33 deletions
|
|
@ -119,13 +119,28 @@ namespace TicketManager.Controllers
|
|||
return project;
|
||||
}
|
||||
|
||||
[HttpPost("{id}/addMembers")]
|
||||
[HttpPut("{id}/addMembers")]
|
||||
public async Task<ActionResult<Project>> AddMembersToProject(int id, List<User> usersToAdd)
|
||||
{
|
||||
if (usersToAdd == null)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
Project project = await GetProjectByIdAsync(id);
|
||||
|
||||
project.AddMembers(usersToAdd);
|
||||
await _context.SaveChangesAsync();
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateException /* ex */)
|
||||
{
|
||||
//Log the error (uncomment ex variable name and write a log.)
|
||||
ModelState.AddModelError("", "Unable to save changes. " +
|
||||
"Try again, and if the problem persists, " +
|
||||
"see your system administrator.");
|
||||
}
|
||||
|
||||
|
||||
return project;
|
||||
}
|
||||
|
|
@ -147,23 +162,25 @@ namespace TicketManager.Controllers
|
|||
}
|
||||
private async Task<ActionResult<IEnumerable<Project>>> GetAllProjectsAsync()
|
||||
{
|
||||
return await _context.Projects
|
||||
.Include(p => p.Assignments)
|
||||
.Include(p => p.Tickets)
|
||||
.Include(p => p.Manager)
|
||||
.Include(p => p.Files)
|
||||
.AsNoTracking()
|
||||
return await makeProjectsQueryAsync()
|
||||
.ToListAsync();
|
||||
}
|
||||
private async Task<Project> GetProjectByIdAsync(int id)
|
||||
{
|
||||
return await _context.Projects
|
||||
return await makeProjectsQueryAsync()
|
||||
.FirstOrDefaultAsync(p => p.Id == id);
|
||||
}
|
||||
|
||||
private IQueryable<TicketManager.Models.Project> makeProjectsQueryAsync()
|
||||
{
|
||||
return _context.Projects
|
||||
.Include(p => p.Assignments)
|
||||
.ThenInclude(a => a.User)
|
||||
.Include(p => p.Tickets)
|
||||
.Include(p => p.Manager)
|
||||
.Include(p => p.Files)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(p => p.Id == id);
|
||||
.AsNoTracking();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +1,62 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace TicketManager.Models
|
||||
{
|
||||
public class Project : ITask
|
||||
{
|
||||
public Project()
|
||||
{
|
||||
|
||||
}
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(50)]
|
||||
[Display(Name = "Title")]
|
||||
public string Title { get; set; }
|
||||
|
||||
[StringLength(200)]
|
||||
[Display(Name = "Short Description")]
|
||||
public string Description { get; set; }
|
||||
public DateTime CreatedAt { get; set; } = DateTime.Now;
|
||||
|
||||
[DataType(DataType.Date)]
|
||||
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = false)]
|
||||
public DateTime CreatedAt { get; private set; } = DateTime.Now;
|
||||
|
||||
[DataType(DataType.Date)]
|
||||
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
|
||||
public DateTime PlannedEnding { get; set; }
|
||||
|
||||
[Display(Name = "Progress")]
|
||||
public float Progression
|
||||
{
|
||||
get
|
||||
{
|
||||
return Tickets.Count() == 0 ? 0 : (float)this.Tickets.
|
||||
return Tickets.Count() == 0 ? 0 :
|
||||
(float)this.Tickets.
|
||||
Where(t => t.Status == Status.Done).Count()
|
||||
/ this.Tickets.Count()
|
||||
* 100;
|
||||
}
|
||||
}
|
||||
|
||||
[Display(Name = "Project Status")]
|
||||
public Status Status { get; set; } = Status.ToDo;
|
||||
|
||||
[Display(Name = "Project Manager")]
|
||||
public User Manager { get; set; }
|
||||
public Guid ManagerId { get; set; }
|
||||
private List<Assignment> _assignments;
|
||||
public List<Assignment> Assignments
|
||||
{
|
||||
get
|
||||
{ return _assignments ?? new List<Assignment>(); }
|
||||
set
|
||||
{ _assignments = value; }
|
||||
}
|
||||
public List<Assignment> Assignments { get; set; } = new List<Assignment>();
|
||||
// {
|
||||
// get
|
||||
// { return _assignments ?? new List<Assignment>(); }
|
||||
// set
|
||||
// { _assignments = value; }
|
||||
// }
|
||||
private List<Ticket> _tickets;
|
||||
public List<Ticket> Tickets
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using Microsoft.Extensions.Logging;
|
|||
|
||||
namespace TicketManager
|
||||
{
|
||||
#pragma warning disable CS1591
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
|
|
@ -23,4 +24,5 @@ namespace TicketManager
|
|||
webBuilder.UseStartup<Startup>();
|
||||
});
|
||||
}
|
||||
#pragma warning restore CS1591
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@
|
|||
|
||||
## TO DO
|
||||
|
||||
- Write API tests using Postman: request + test, environment variables, mock server
|
||||
- Annotate API request in controllers
|
||||
- Annotate Properties in Models
|
||||
- Write backend tests
|
||||
- Reinitialize db
|
||||
- Write Project SetMembers Method and related API endpoint code
|
||||
- Write Project GetMembers Method and related API endpoint code
|
||||
- Ensure Tickets Edits belong to Project Edits
|
||||
- Ensure Tickets Files belong to Project Files
|
||||
|
|
|
|||
12
Startup.cs
12
Startup.cs
|
|
@ -60,12 +60,12 @@ namespace TicketManager
|
|||
Url = new Uri("https://ruidywebsite.herokuapp.com/"),
|
||||
}
|
||||
});
|
||||
|
||||
// Set the comments path for the Swagger JSON and UI.
|
||||
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
||||
c.IncludeXmlComments(xmlPath);
|
||||
});
|
||||
services.AddSwaggerGenNewtonsoftSupport(); // explicit opt-in - needs to be placed after AddSwaggerGen()
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -77,10 +77,14 @@ namespace TicketManager
|
|||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseDefaultFiles();
|
||||
app.UseStaticFiles();
|
||||
|
||||
|
||||
app.UseSwagger();
|
||||
|
||||
|
|
@ -89,7 +93,7 @@ namespace TicketManager
|
|||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Ticket Manager API V1");
|
||||
});
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
|
||||
app.UseSpaStaticFiles();
|
||||
app.UseRouting();
|
||||
|
|
|
|||
|
|
@ -28,14 +28,10 @@
|
|||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.OpenApi" Version="1.1.4" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc5" />
|
||||
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="client\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Remove="WeatherForecast.cs" />
|
||||
<Compile Remove="Controllers\WeatherForecastController.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"https_port": 443,
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
|
|
|
|||
Loading…
Reference in a new issue