update new controller (#64)
parent
05aa9ab952
commit
8dd4ff3147
|
@ -46,8 +46,7 @@ public class ValuesController : ControllerBase
|
||||||
{
|
{
|
||||||
var errorType = new MathErrorFeature
|
var errorType = new MathErrorFeature
|
||||||
{
|
{
|
||||||
MathError =
|
MathError = MathErrorType.DivisionByZeroError
|
||||||
MathErrorType.DivisionByZeroError
|
|
||||||
};
|
};
|
||||||
HttpContext.Features.Set(errorType);
|
HttpContext.Features.Set(errorType);
|
||||||
return BadRequest();
|
return BadRequest();
|
||||||
|
@ -65,8 +64,7 @@ public class ValuesController : ControllerBase
|
||||||
{
|
{
|
||||||
var errorType = new MathErrorFeature
|
var errorType = new MathErrorFeature
|
||||||
{
|
{
|
||||||
MathError =
|
MathError = MathErrorType.NegativeRadicandError
|
||||||
MathErrorType.NegativeRadicandError
|
|
||||||
};
|
};
|
||||||
HttpContext.Features.Set(errorType);
|
HttpContext.Features.Set(errorType);
|
||||||
return BadRequest();
|
return BadRequest();
|
||||||
|
@ -79,12 +77,12 @@ public class ValuesController : ControllerBase
|
||||||
}
|
}
|
||||||
// </snippet>
|
// </snippet>
|
||||||
|
|
||||||
// <snippet>
|
// <snippet3>
|
||||||
[Route("api/[controller]/[action]")]
|
[Route("api/[controller]/[action]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class Values3Controller : ControllerBase
|
public class Values3Controller : ControllerBase
|
||||||
{
|
{
|
||||||
// /api/values/divide/1/2
|
// /api/values3/divide/1/2
|
||||||
[HttpGet("{Numerator}/{Denominator}")]
|
[HttpGet("{Numerator}/{Denominator}")]
|
||||||
public IActionResult Divide(double Numerator, double Denominator)
|
public IActionResult Divide(double Numerator, double Denominator)
|
||||||
{
|
{
|
||||||
|
@ -92,12 +90,11 @@ public class Values3Controller : ControllerBase
|
||||||
{
|
{
|
||||||
var errorType = new MathErrorFeature
|
var errorType = new MathErrorFeature
|
||||||
{
|
{
|
||||||
MathError =
|
MathError = MathErrorType.DivisionByZeroError
|
||||||
MathErrorType.DivisionByZeroError
|
|
||||||
};
|
};
|
||||||
HttpContext.Features.Set(errorType);
|
HttpContext.Features.Set(errorType);
|
||||||
return Problem(
|
return Problem(
|
||||||
title: "Wrong Input",
|
title: "Bad Input",
|
||||||
detail: "The number you inputed is zero",
|
detail: "The number you inputed is zero",
|
||||||
type: "https://en.wikipedia.org/wiki/Division_by_zero",
|
type: "https://en.wikipedia.org/wiki/Division_by_zero",
|
||||||
statusCode: StatusCodes.Status400BadRequest
|
statusCode: StatusCodes.Status400BadRequest
|
||||||
|
@ -108,7 +105,7 @@ public class Values3Controller : ControllerBase
|
||||||
return Ok(calculation);
|
return Ok(calculation);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /api/values/squareroot/4
|
// /api/values3/squareroot/4
|
||||||
[HttpGet("{radicand}")]
|
[HttpGet("{radicand}")]
|
||||||
public IActionResult Squareroot(double radicand)
|
public IActionResult Squareroot(double radicand)
|
||||||
{
|
{
|
||||||
|
@ -116,12 +113,11 @@ public class Values3Controller : ControllerBase
|
||||||
{
|
{
|
||||||
var errorType = new MathErrorFeature
|
var errorType = new MathErrorFeature
|
||||||
{
|
{
|
||||||
MathError =
|
MathError = MathErrorType.NegativeRadicandError
|
||||||
MathErrorType.NegativeRadicandError
|
|
||||||
};
|
};
|
||||||
HttpContext.Features.Set(errorType);
|
HttpContext.Features.Set(errorType);
|
||||||
return Problem(
|
return Problem(
|
||||||
title: "Wrong Input",
|
title: "Bad Input",
|
||||||
detail: "Negative or complex numbers are not handled",
|
detail: "Negative or complex numbers are not handled",
|
||||||
type: "https://en.wikipedia.org/wiki/Square_root",
|
type: "https://en.wikipedia.org/wiki/Square_root",
|
||||||
statusCode: StatusCodes.Status400BadRequest
|
statusCode: StatusCodes.Status400BadRequest
|
||||||
|
@ -133,4 +129,4 @@ public class Values3Controller : ControllerBase
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// </snippet>
|
// </snippet3>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#define API_CONTROLLER // MIDDLEWARE API_CONTROLLER API_CONT_SHORT
|
#define MIDDLEWARE // MIDDLEWARE API_CONTROLLER API_CONT_SHORT
|
||||||
#if NEVER
|
#if NEVER
|
||||||
#elif MIDDLEWARE
|
#elif MIDDLEWARE
|
||||||
// <snippet_middleware>
|
// <snippet_middleware>
|
||||||
|
@ -42,7 +42,7 @@ app.Use(async (context, next) =>
|
||||||
HttpContext = context,
|
HttpContext = context,
|
||||||
ProblemDetails =
|
ProblemDetails =
|
||||||
{
|
{
|
||||||
Title = "Wrong Input",
|
Title = "Bad Input",
|
||||||
Detail = details.Detail,
|
Detail = details.Detail,
|
||||||
Type = details.Type
|
Type = details.Type
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ builder.Services.AddProblemDetails(options =>
|
||||||
};
|
};
|
||||||
|
|
||||||
context.ProblemDetails.Type = details.Type;
|
context.ProblemDetails.Type = details.Type;
|
||||||
context.ProblemDetails.Title = "Wrong Input";
|
context.ProblemDetails.Title = "Bad Input";
|
||||||
context.ProblemDetails.Detail = details.Detail;
|
context.ProblemDetails.Detail = details.Detail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue