add coupon endpoint and custom health check service collection extension
This commit is contained in:
parent
0abcc5b688
commit
4e27c34446
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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…
x
Reference in New Issue
Block a user