diff --git a/src/Services/Coupon/Coupon.API/Controllers/CouponController.cs b/src/Services/Coupon/Coupon.API/Controllers/CouponController.cs index d4db1625f..66b5d8571 100644 --- a/src/Services/Coupon/Coupon.API/Controllers/CouponController.cs +++ b/src/Services/Coupon/Coupon.API/Controllers/CouponController.cs @@ -23,6 +23,22 @@ _mapper = mapper; } - // Add the GetCouponByCodeAsync method + [HttpGet("{code}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task> GetCouponByCodeAsync(string code) + { + var coupon = await _couponRepository.FindCouponByCodeAsync(code); + + if (coupon is null || coupon.Consumed) + { + return NotFound(); + } + + var couponDto = _mapper.Translate(coupon); + + return couponDto; + } } } diff --git a/src/Services/Coupon/Coupon.API/Startup.cs b/src/Services/Coupon/Coupon.API/Startup.cs index ae3daabb5..1600e1426 100644 --- a/src/Services/Coupon/Coupon.API/Startup.cs +++ b/src/Services/Coupon/Coupon.API/Startup.cs @@ -34,7 +34,8 @@ namespace Coupon.API .AddEventBus(Configuration) .AddCustomAuthentication(Configuration) .AddCustomAuthorization() - .AddSwagger(Configuration); + .AddSwagger(Configuration) + .AddCustomHealthCheck(Configuration); services.AddTransient, OrderStatusChangedToAwaitingCouponValidationIntegrationEventHandler>(); services.AddTransient, OrderStatusChangedToCancelledIntegrationEventHandler>(); @@ -68,7 +69,15 @@ namespace Coupon.API .UseEndpoints(endpoints => { endpoints.MapControllers(); - // Add the endpoints.MapHealthChecks code + endpoints.MapHealthChecks("/hc", new HealthCheckOptions + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse + }); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions + { + Predicate = r => r.Name.Contains("self") + }); }); ConfigureEventBus(app);