68 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			68 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| 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 MongoBlueprintController(IBlueprintService service) : ControllerBase
 | |
|     {
 | |
|         [HttpPost("Create")]
 | |
|         public async Task<IActionResult> CreateBlueprint([FromBody] BlueprintRequest entity, CancellationToken cancellationToken)
 | |
|         {
 | |
|             var result = await service.CreateBlueprint(entity, cancellationToken).ConfigureAwait(false);
 | |
|             return Created("CreatedWithIdAsync", result);
 | |
|         }
 | |
| 
 | |
|         [HttpGet("GetAll")]
 | |
|         public async Task<IActionResult> GetEntities(CancellationToken cancellationToken)
 | |
|         {
 | |
|             var result = await service.GetAllBlueprints(cancellationToken).ConfigureAwait(false);
 | |
|             return Ok(result);
 | |
|         }
 | |
| 
 | |
|         [HttpGet("{_id}/GetBy_Id")]
 | |
|         public async Task<IActionResult> GetBlueprint([FromRoute] string _id, CancellationToken cancellationToken)
 | |
|         {
 | |
|             var result = await service.GetBlueprintById(_id, cancellationToken).ConfigureAwait(false);
 | |
| 
 | |
|             if (result == null)
 | |
|             {
 | |
|                 return NotFound("Entity not found");
 | |
|             }
 | |
| 
 | |
|             return Ok(result);
 | |
|         }
 | |
| 
 | |
|         [HttpPut("{_id}/Update")]
 | |
|         public async Task<IActionResult> UpdateBlueprint([FromRoute] string _id, [FromBody] BlueprintCollection entity, CancellationToken cancellationToken)
 | |
|         {
 | |
|             if (_id != entity._Id?.ToString())
 | |
|             {
 | |
|                 return BadRequest("Blueprint ID mismatch");
 | |
|             }
 | |
| 
 | |
|             var result = await service.UpdateBlueprint(_id, entity, cancellationToken).ConfigureAwait(false);
 | |
| 
 | |
|             return Ok(result);
 | |
|         }
 | |
| 
 | |
|         [HttpDelete("{_id}/Delete")]
 | |
|         public async Task<IActionResult> DeleteBlueprint([FromRoute] string _id, CancellationToken cancellationToken)
 | |
|         {
 | |
|             var result = await service.DeleteBlueprint(_id, cancellationToken).ConfigureAwait(false);
 | |
| 
 | |
|             if (result is null) return NotFound();
 | |
| 
 | |
|             return Ok(result);
 | |
|         }
 | |
|     }
 | |
| }
 | 
