using FozFc.Api.Application.Common; using FozFc.Api.Infrastructure.Mongo; using MongoDB.Bson; namespace FozFc.Api.Api.Extensions; public static class HttpRequestExtensions { /// Reads the request body as a BSON document, throwing 400 on invalid JSON. public static async Task ReadBsonBodyAsync(this HttpRequest request, CancellationToken ct = default) { using var reader = new StreamReader(request.Body); var raw = await reader.ReadToEndAsync(ct); return BsonJson.TryParse(raw) ?? throw ApiException.BadRequest("Invalid JSON body."); } }