using Asp.Versioning; using Core.Blueprint.DAL.Mongo.Contracts; using Core.Blueprint.DAL.Mongo.Entities.Collections; using Core.Blueprint.DAL.Mongo.Entities.Requests; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Core.Blueprint.DAL.API.Controllers { [ApiVersion("1.0")] [Route("api/v{api-version:apiVersion}/[controller]")] [Produces("application/json")] [ApiController] [AllowAnonymous] public class MongoSampleController(IMongoSampleService service) : ControllerBase { [HttpPost("Create")] public async Task CreateSample([FromBody] SampleRequest entity, CancellationToken cancellationToken) { var result = await service.CreateSample(entity, cancellationToken).ConfigureAwait(false); return Created("CreatedWithIdAsync", result); } [HttpGet("GetAll")] public async Task GetEntities(CancellationToken cancellationToken) { var result = await service.GetAllSamples(cancellationToken).ConfigureAwait(false); return Ok(result); } [HttpGet("{_id}/GetBy_Id")] public async Task GetSample([FromRoute] string _id, CancellationToken cancellationToken) { var result = await service.GetSampleById(_id, cancellationToken).ConfigureAwait(false); if (result == null) { return NotFound("Entity not found"); } return Ok(result); } [HttpPut("{_id}/Update")] public async Task UpdateSample([FromRoute] string _id, [FromBody] SampleCollection entity, CancellationToken cancellationToken) { if (_id != entity._Id?.ToString()) { return BadRequest("Sample ID mismatch"); } var result = await service.UpdateSample(_id, entity, cancellationToken).ConfigureAwait(false); return Ok(result); } [HttpDelete("{_id}/Delete")] public async Task DeleteSample([FromRoute] string _id, CancellationToken cancellationToken) { var result = await service.DeleteSample(_id, cancellationToken).ConfigureAwait(false); if (result is null) return NotFound(); return Ok(result); } } }