Browse Source

add coupon endpoint and custom health check service collection extension

pull/2021/head
Zhuk, Anton 2 years ago
parent
commit
4e27c34446
2 changed files with 28 additions and 3 deletions
  1. +17
    -1
      src/Services/Coupon/Coupon.API/Controllers/CouponController.cs
  2. +11
    -2
      src/Services/Coupon/Coupon.API/Startup.cs

+ 17
- 1
src/Services/Coupon/Coupon.API/Controllers/CouponController.cs View File

@ -23,6 +23,22 @@
_mapper = mapper;
}
// Add the GetCouponByCodeAsync method
[HttpGet("{code}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<CouponDto>> GetCouponByCodeAsync(string code)
{
var coupon = await _couponRepository.FindCouponByCodeAsync(code);
if (coupon is null || coupon.Consumed)
{
return NotFound();
}
var couponDto = _mapper.Translate(coupon);
return couponDto;
}
}
}

+ 11
- 2
src/Services/Coupon/Coupon.API/Startup.cs View File

@ -34,7 +34,8 @@ namespace Coupon.API
.AddEventBus(Configuration)
.AddCustomAuthentication(Configuration)
.AddCustomAuthorization()
.AddSwagger(Configuration);
.AddSwagger(Configuration)
.AddCustomHealthCheck(Configuration);
services.AddTransient<IIntegrationEventHandler<OrderStatusChangedToAwaitingCouponValidationIntegrationEvent>, OrderStatusChangedToAwaitingCouponValidationIntegrationEventHandler>();
services.AddTransient<IIntegrationEventHandler<OrderStatusChangedToCancelledIntegrationEvent>, 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);


Loading…
Cancel
Save