From 8dd4ff3147b18508a8b831d82483043f6d900e0e Mon Sep 17 00:00:00 2001 From: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> Date: Wed, 21 Sep 2022 11:50:56 -1000 Subject: [PATCH] update new controller (#64) --- .../Controllers/ValuesController.cs | 24 ++++++++----------- .../problem-details-service/Program.cs | 6 ++--- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/fundamentals/middleware/problem-details-service/Controllers/ValuesController.cs b/fundamentals/middleware/problem-details-service/Controllers/ValuesController.cs index 3a4472c..7d443b5 100644 --- a/fundamentals/middleware/problem-details-service/Controllers/ValuesController.cs +++ b/fundamentals/middleware/problem-details-service/Controllers/ValuesController.cs @@ -46,8 +46,7 @@ public class ValuesController : ControllerBase { var errorType = new MathErrorFeature { - MathError = - MathErrorType.DivisionByZeroError + MathError = MathErrorType.DivisionByZeroError }; HttpContext.Features.Set(errorType); return BadRequest(); @@ -65,8 +64,7 @@ public class ValuesController : ControllerBase { var errorType = new MathErrorFeature { - MathError = - MathErrorType.NegativeRadicandError + MathError = MathErrorType.NegativeRadicandError }; HttpContext.Features.Set(errorType); return BadRequest(); @@ -79,12 +77,12 @@ public class ValuesController : ControllerBase } // -// +// [Route("api/[controller]/[action]")] [ApiController] public class Values3Controller : ControllerBase { - // /api/values/divide/1/2 + // /api/values3/divide/1/2 [HttpGet("{Numerator}/{Denominator}")] public IActionResult Divide(double Numerator, double Denominator) { @@ -92,12 +90,11 @@ public class Values3Controller : ControllerBase { var errorType = new MathErrorFeature { - MathError = - MathErrorType.DivisionByZeroError + MathError = MathErrorType.DivisionByZeroError }; HttpContext.Features.Set(errorType); return Problem( - title: "Wrong Input", + title: "Bad Input", detail: "The number you inputed is zero", type: "https://en.wikipedia.org/wiki/Division_by_zero", statusCode: StatusCodes.Status400BadRequest @@ -108,7 +105,7 @@ public class Values3Controller : ControllerBase return Ok(calculation); } - // /api/values/squareroot/4 + // /api/values3/squareroot/4 [HttpGet("{radicand}")] public IActionResult Squareroot(double radicand) { @@ -116,12 +113,11 @@ public class Values3Controller : ControllerBase { var errorType = new MathErrorFeature { - MathError = - MathErrorType.NegativeRadicandError + MathError = MathErrorType.NegativeRadicandError }; HttpContext.Features.Set(errorType); return Problem( - title: "Wrong Input", + title: "Bad Input", detail: "Negative or complex numbers are not handled", type: "https://en.wikipedia.org/wiki/Square_root", statusCode: StatusCodes.Status400BadRequest @@ -133,4 +129,4 @@ public class Values3Controller : ControllerBase } } -// +// diff --git a/fundamentals/middleware/problem-details-service/Program.cs b/fundamentals/middleware/problem-details-service/Program.cs index 7f69089..3b56a73 100644 --- a/fundamentals/middleware/problem-details-service/Program.cs +++ b/fundamentals/middleware/problem-details-service/Program.cs @@ -1,4 +1,4 @@ -#define API_CONTROLLER // MIDDLEWARE API_CONTROLLER API_CONT_SHORT +#define MIDDLEWARE // MIDDLEWARE API_CONTROLLER API_CONT_SHORT #if NEVER #elif MIDDLEWARE // @@ -42,7 +42,7 @@ app.Use(async (context, next) => HttpContext = context, ProblemDetails = { - Title = "Wrong Input", + Title = "Bad Input", Detail = details.Detail, Type = details.Type } @@ -109,7 +109,7 @@ builder.Services.AddProblemDetails(options => }; context.ProblemDetails.Type = details.Type; - context.ProblemDetails.Title = "Wrong Input"; + context.ProblemDetails.Title = "Bad Input"; context.ProblemDetails.Detail = details.Detail; } }