Changed the method for all the filters to stomething more standardized and .net compliant (also easier built into openapi v3)

This commit is contained in:
2020-06-18 16:38:14 +02:00
parent 00d5cea156
commit ec7f4c940c
7 changed files with 55 additions and 59 deletions

View File

@@ -20,25 +20,25 @@ namespace ScrumTaskboard.Controllers
// GET: api/sprint
[HttpGet]
public async Task<ActionResult<IEnumerable<ScrumSprint>>> GetSprint()
public async Task<ActionResult<IEnumerable<ScrumSprint>>> GetSprint([FromQuery]string? title, [FromQuery]int? projectid, [FromQuery]DateTime? startDate, [FromQuery]DateTime? endDate)
{
var filtered = _context.Sprints.AsQueryable();
if (HttpContext.Request.Query["title"].ToString() != "")
if (title != null)
{
filtered = filtered.Where<ScrumSprint>(s => s.title.Contains(HttpContext.Request.Query["title"].ToString()));
filtered = filtered.Where<ScrumSprint>(s => s.title.Contains(title));
}
if (Convert.ToInt32(HttpContext.Request.Query["projectid"]) != 0)
if (projectid != null)
{
filtered = filtered.Where<ScrumSprint>(s => s.projectid == Convert.ToInt32(HttpContext.Request.Query["projectid"]));
filtered = filtered.Where<ScrumSprint>(s => s.projectid == projectid);
}
if (HttpContext.Request.Query["startDate"].ToString() != "")
if (startDate != null)
{
filtered = filtered.Where<ScrumSprint>(s => s.startDate == DateTime.Parse(HttpContext.Request.Query["startDate"].ToString()));
filtered = filtered.Where<ScrumSprint>(s => s.startDate == startDate);
}
if (HttpContext.Request.Query["endDate"].ToString() != "")
if (endDate != null)
{
filtered = filtered.Where<ScrumSprint>(s => s.endDate == DateTime.Parse(HttpContext.Request.Query["startDate"].ToString()));
filtered = filtered.Where<ScrumSprint>(s => s.endDate == endDate);
}
return await filtered.ToListAsync();