Compare commits
	
		
			7 Commits
		
	
	
		
			main
			...
			11d1d21f3a
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 11d1d21f3a | |||
|   | b9a38fbdcb | ||
| 07a521ac17 | |||
|   | 93d15861a1 | ||
| 977aa577cc | |||
| 15d0d24313 | |||
| 3e8100e1c5 | 
							
								
								
									
										49
									
								
								Core.Inventory.BFF.API/Controllers/BaseController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								Core.Inventory.BFF.API/Controllers/BaseController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | |||||||
|  |  | ||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  | using Microsoft.AspNetCore.Mvc; | ||||||
|  | using Newtonsoft.Json; | ||||||
|  | using Refit; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.BFF.API.Controllers | ||||||
|  | { | ||||||
|  |     [Route("api/[controller]")] | ||||||
|  |     [ApiController] | ||||||
|  |     public class BaseController(ILogger<BaseController> logger) : ControllerBase | ||||||
|  |     { | ||||||
|  |         private readonly ILogger<BaseController> _logger = logger; | ||||||
|  |  | ||||||
|  |         protected Guid TrackingId => (Guid)(HttpContext.Items["TrackingId"] ?? Guid.NewGuid()); | ||||||
|  |  | ||||||
|  |         protected async Task<IActionResult> Handle<T>(Func<Task<ApiResponse<T>>> apiCall) where T : class | ||||||
|  |         { | ||||||
|  |             var response = await apiCall().ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             _logger.LogInformation($"{TrackingId} - {response.RequestMessage?.Method} {response.RequestMessage?.RequestUri} - Status: {response.StatusCode}"); | ||||||
|  |  | ||||||
|  |             return FromAPIResponse(response); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         private IActionResult FromAPIResponse<T>(ApiResponse<T> response) where T : class | ||||||
|  |         { | ||||||
|  |             if (response.IsSuccessful) | ||||||
|  |                 return StatusCode((int)response.StatusCode, response.Content); | ||||||
|  |             else | ||||||
|  |             { | ||||||
|  |                 dynamic errorContent = string.Empty; | ||||||
|  |  | ||||||
|  |                 try | ||||||
|  |                 { | ||||||
|  |                     errorContent = JsonConvert.DeserializeObject<string>(response.Error?.Content ?? string.Empty) ?? string.Empty; | ||||||
|  |                 } | ||||||
|  |                 catch (Exception) | ||||||
|  |                 { | ||||||
|  |                     errorContent = JsonConvert.DeserializeObject<HttpError>(response.Error?.Content); | ||||||
|  |                     if (errorContent?.Error?.ErrorCode is null && errorContent?.Error?.Message is null && errorContent?.Error?.Target is null) | ||||||
|  |                         errorContent = JsonConvert.DeserializeObject<GenericErrorResponse>(response.Error?.Content); | ||||||
|  |  | ||||||
|  |                 } | ||||||
|  |                 return StatusCode((int)response.StatusCode, errorContent); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										142
									
								
								Core.Inventory.BFF.API/Controllers/FurnitureBaseController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										142
									
								
								Core.Inventory.BFF.API/Controllers/FurnitureBaseController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,142 @@ | |||||||
|  | using Asp.Versioning; | ||||||
|  | using Core.Adapters.Lib; | ||||||
|  | using Core.Inventory.External.Clients.Inventory; | ||||||
|  | using Core.Inventory.External.Clients.Inventory.Requests.Base; | ||||||
|  | using Microsoft.AspNetCore.Mvc; | ||||||
|  | using System.Text.Json; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.BFF.API.Controllers | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all requests for furniture base operations. | ||||||
|  |     /// </summary> | ||||||
|  |     [ApiVersion("1.0")] | ||||||
|  |     [Route("api/v{version:apiVersion}/[controller]")] | ||||||
|  |     [ApiController] | ||||||
|  |     [Consumes("application/json")] | ||||||
|  |     [Produces("application/json")] | ||||||
|  |     public class FurnitureBaseController(IInventoryServiceClient inventoryClient, ILogger<FurnitureBaseController> logger) : BaseController(logger) | ||||||
|  |     { | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all furniture base records. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpGet("GetAll")] | ||||||
|  |         [ProducesResponseType(typeof(IEnumerable<FurnitureBase>), StatusCodes.Status200OK)] | ||||||
|  |         public async Task<IActionResult> GetAllBaseAsync(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(GetAllBaseAsync)} - Request received."); | ||||||
|  |                 return await Handle(() => inventoryClient.GetAllBaseAsync(TrackingId.ToString(), cancellationToken)); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError(ex, $"{nameof(GetAllBaseAsync)} - An error occurred."); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets a furniture base by its identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPost("GetById")] | ||||||
|  |         [ProducesResponseType(typeof(FurnitureBase), StatusCodes.Status200OK)] | ||||||
|  |         public async Task<IActionResult> GetByIdAsync([FromBody] GetFurnitureBaseByIdRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(GetByIdAsync)} - Request received. Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrWhiteSpace(request.MongoId)) | ||||||
|  |                     return BadRequest("FurnitureBase MongoId is required."); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryClient.GetByIdAsync(TrackingId.ToString(), request, cancellationToken)); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError(ex, $"{nameof(GetByIdAsync)} - An error occurred. Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new furniture base record. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPost("Create")] | ||||||
|  |         [ProducesResponseType(typeof(FurnitureBase), StatusCodes.Status201Created)] | ||||||
|  |         public async Task<IActionResult> CreateAsync([FromBody] CreateFurnitureBaseRequest newFurniture, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(CreateAsync)} - Request received. Payload: {JsonSerializer.Serialize(newFurniture)}"); | ||||||
|  |  | ||||||
|  |                 if (newFurniture == null) return BadRequest("Invalid furniture object"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(newFurniture.ModelName)) return BadRequest("Invalid furniture name"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(newFurniture.Material)) return BadRequest("Invalid furniture material"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(newFurniture.Condition)) return BadRequest("Invalid furniture condition"); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryClient.CreateAsync(TrackingId.ToString(), newFurniture, cancellationToken)); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError(ex, $"{nameof(CreateAsync)} - An error occurred. Payload: {JsonSerializer.Serialize(newFurniture)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a furniture base record. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPut("Update")] | ||||||
|  |         [ProducesResponseType(typeof(FurnitureBase), StatusCodes.Status200OK)] | ||||||
|  |         public async Task<IActionResult> UpdateAsync([FromBody] UpdateFurnitureBaseRequest newFurniture, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(UpdateAsync)} - Request received. Payload: {JsonSerializer.Serialize(newFurniture)}"); | ||||||
|  |  | ||||||
|  |                 if (newFurniture == null) return BadRequest("Invalid furniture object"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(newFurniture.ModelName)) return BadRequest("Invalid furniture model name"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(newFurniture.Material)) return BadRequest("Invalid furniture material"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(newFurniture.Condition)) return BadRequest("Invalid furniture condition"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrWhiteSpace(newFurniture.Id)) return BadRequest("Id is required."); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryClient.UpdateFurnitureBaseAsync(TrackingId.ToString(), newFurniture, cancellationToken)); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError(ex, $"{nameof(UpdateAsync)} - An error occurred. Payload: {JsonSerializer.Serialize(newFurniture)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of a furniture base. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPatch("ChangeStatus")] | ||||||
|  |         [ProducesResponseType(typeof(FurnitureBase), StatusCodes.Status200OK)] | ||||||
|  |         public async Task<IActionResult> ChangeStatusAsync([FromBody] ChangeFurnitureBaseStatusRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(ChangeStatusAsync)} - Request received. Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrWhiteSpace(request.MongoId)) return BadRequest("Id is required."); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryClient.ChangeFurnitureBaseStatusAsync(TrackingId.ToString(), request, cancellationToken)); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError(ex, $"{nameof(ChangeStatusAsync)} - An error occurred. Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										186
									
								
								Core.Inventory.BFF.API/Controllers/FurnitureVariantController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										186
									
								
								Core.Inventory.BFF.API/Controllers/FurnitureVariantController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,186 @@ | |||||||
|  | using Asp.Versioning; | ||||||
|  | using Core.Adapters.Lib; | ||||||
|  | using Core.Inventory.External.Clients.Inventory; | ||||||
|  | using Core.Inventory.External.Clients.Inventory.Requests.Variant; | ||||||
|  | using Microsoft.AspNetCore.Mvc; | ||||||
|  | using System.Text.Json; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.BFF.API.Controllers | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all requests for furniture variant operations. | ||||||
|  |     /// </summary> | ||||||
|  |     [ApiVersion("1.0")] | ||||||
|  |     [Route("api/v{version:apiVersion}/[controller]")] | ||||||
|  |     [ApiController] | ||||||
|  |     [Consumes("application/json")] | ||||||
|  |     [Produces("application/json")] | ||||||
|  |     public class FurnitureVariantController(IInventoryServiceClient inventoryClient, ILogger<FurnitureVariantController> logger) : BaseController(logger) | ||||||
|  |     { | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all furniture base records. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpGet("GetAll")] | ||||||
|  |         [ProducesResponseType(typeof(IEnumerable<FurnitureVariant>), StatusCodes.Status200OK)] | ||||||
|  |         public async Task<IActionResult> GetAllVariantsAsync(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(GetAllVariantsAsync)} - Request received."); | ||||||
|  |                 return await Handle(() => inventoryClient.GetAllVariantsAsync(TrackingId.ToString(), cancellationToken)); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError(ex, $"{nameof(GetAllVariantsAsync)} - An error occurred."); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets furniture variants by model ID. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPost("GetAllByModelId")] | ||||||
|  |         [ProducesResponseType(typeof(IEnumerable<FurnitureVariant>), StatusCodes.Status200OK)] | ||||||
|  |         public async Task<IActionResult> GetAllByModelIdAsync([FromBody] GetAllFurnitureVariantsByModelIdRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(GetAllByModelIdAsync)} - Request received. Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrWhiteSpace(request.ModelId)) return BadRequest("ModelId is required."); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryClient.GetAllVariantsByModelIdAsync(TrackingId.ToString(), request, cancellationToken)); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError(ex, $"{nameof(GetAllByModelIdAsync)} - An error occurred. Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets a furniture variant by its MongoId. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPost("GetById")] | ||||||
|  |         [ProducesResponseType(typeof(FurnitureVariant), StatusCodes.Status200OK)] | ||||||
|  |         public async Task<IActionResult> GetByIdAsync([FromBody] GetFurnitureVariantByIdRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(GetByIdAsync)} - Request received. Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrWhiteSpace(request.MongoId)) return BadRequest("MongoId is required."); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryClient.GetFurnitureVariantByIdAsync(TrackingId.ToString(), request, cancellationToken)); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError(ex, $"{nameof(GetByIdAsync)} - An error occurred. Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets furniture variants by a list of IDs. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPost("GetByIds")] | ||||||
|  |         [ProducesResponseType(typeof(IEnumerable<FurnitureVariant>), StatusCodes.Status200OK)] | ||||||
|  |         public async Task<IActionResult> GetByIdsAsync([FromBody] GetFurnitureVariantsByIdsRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(GetByIdsAsync)} - Request received. Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |  | ||||||
|  |                 if (request?.Ids == null || request.Ids.Count == 0) | ||||||
|  |                     return BadRequest("At least one Id is required."); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryClient.GetFurnitureVariantsByIdsAsync(TrackingId.ToString(), request, cancellationToken)); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError(ex, $"{nameof(GetByIdsAsync)} - An error occurred. Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new furniture variant. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPost("Create")] | ||||||
|  |         [ProducesResponseType(typeof(FurnitureVariant), StatusCodes.Status201Created)] | ||||||
|  |         public async Task<IActionResult> CreateAsync([FromBody] CreateFurnitureVariantRequest newVariant, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(CreateAsync)} - Request received. Payload: {JsonSerializer.Serialize(newVariant)}"); | ||||||
|  |  | ||||||
|  |                 if (newVariant == null) return BadRequest("Invalid furniture object"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(newVariant.ModelId)) return BadRequest("Invalid furniture modelId"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(newVariant.Name)) return BadRequest("Invalid furniture name"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(newVariant.Color)) return BadRequest("Invalid furniture color"); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryClient.CreateFurnitureVariantAsync(TrackingId.ToString(), newVariant, cancellationToken)); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError(ex, $"{nameof(CreateAsync)} - An error occurred. Payload: {JsonSerializer.Serialize(newVariant)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a furniture variant. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPut("Update")] | ||||||
|  |         [ProducesResponseType(typeof(FurnitureVariant), StatusCodes.Status200OK)] | ||||||
|  |         public async Task<IActionResult> UpdateAsync([FromBody] UpdateFurnitureVariantRequest newVariant, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(UpdateAsync)} - Request received. Payload: {JsonSerializer.Serialize(newVariant)}"); | ||||||
|  |  | ||||||
|  |                 if (newVariant == null) return BadRequest("Invalid furniture object"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(newVariant.ModelId)) return BadRequest("Invalid furniture modelId"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(newVariant.Name)) return BadRequest("Invalid furniture name"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(newVariant.Color)) return BadRequest("Invalid furniture color"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrWhiteSpace(newVariant.Id)) return BadRequest("Id is required."); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryClient.UpdateFurnitureVariantAsync(TrackingId.ToString(), newVariant.Id, newVariant, cancellationToken)); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError(ex, $"{nameof(UpdateAsync)} - An error occurred. Payload: {JsonSerializer.Serialize(newVariant)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of a furniture variant. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPatch("ChangeStatus")] | ||||||
|  |         [ProducesResponseType(typeof(FurnitureVariant), StatusCodes.Status200OK)] | ||||||
|  |         public async Task<IActionResult> ChangeStatusAsync([FromBody] ChangeFurnitureVariantStatusRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(ChangeStatusAsync)} - Request received. Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrWhiteSpace(request.MongoId)) return BadRequest("Id is required."); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryClient.ChangeFurnitureVariantStatusAsync(TrackingId.ToString(), request, cancellationToken)); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError(ex, $"{nameof(ChangeStatusAsync)} - An error occurred. Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										261
									
								
								Core.Inventory.BFF.API/Controllers/TagController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										261
									
								
								Core.Inventory.BFF.API/Controllers/TagController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,261 @@ | |||||||
|  | using Asp.Versioning; | ||||||
|  | using Core.Adapters.Lib; | ||||||
|  | using Core.Inventory.External.Clients.Inventory; | ||||||
|  | using Core.Inventory.External.Clients.Inventory.Requests.Tag; | ||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  | using Microsoft.AspNetCore.Authorization; | ||||||
|  | using Microsoft.AspNetCore.Mvc; | ||||||
|  | using System.Text.Json; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.BFF.API.Controllers | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all requests for Tag authentication. | ||||||
|  |     /// </summary> | ||||||
|  |     [ApiVersion("1.0")] | ||||||
|  |     [Route("api/v{version:apiVersion}/[controller]")] | ||||||
|  |     [Consumes("application/json")] | ||||||
|  |     [Produces("application/json")] | ||||||
|  |     [ApiController] | ||||||
|  |     [AllowAnonymous] | ||||||
|  |     public class TagController(IInventoryServiceClient inventoryServiceClient, ILogger<TagController> logger) : BaseController(logger) | ||||||
|  |     { | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the Tags. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpGet("GetAll")] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||||
|  |         public async Task<IActionResult> GetAllTagsService(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(GetAllTagsService)} - Request received - Payload: "); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryServiceClient.GetAllTagsService(new GetAllTagsRequest { }, cancellationToken)).ConfigureAwait(false); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError($"{nameof(GetAllTagsService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the Tags by Tag identifiers. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="request">The request containing the list of Tag identifiers.</param> | ||||||
|  |         /// <param name="cancellationToken">Cancellation token for the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="IActionResult"/> representing the result of the service call.</returns> | ||||||
|  |         /// <response code="200">The Tags found.</response> | ||||||
|  |         /// <response code="204">No content if no Tags are found.</response> | ||||||
|  |         /// <response code="400">Bad request if the Tag identifiers are missing or invalid.</response> | ||||||
|  |         /// <response code="401">Unauthorized if the user is not authenticated.</response> | ||||||
|  |         /// <response code="500">Internal server error if an unexpected error occurs.</response> | ||||||
|  |         [HttpPost("GetAllByList")] | ||||||
|  |         [ProducesResponseType(typeof(IEnumerable<TagAdapter>), StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||||
|  |         public async Task<IActionResult> GetAllTagsByListAsync([FromBody] GetAllTagsByListRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(GetAllTagsByListAsync)} - Request received - Payload: {request}"); | ||||||
|  |  | ||||||
|  |                 if (request == null || request.Tags == null || !request.Tags.Any()) | ||||||
|  |                 { | ||||||
|  |                     return BadRequest("Tag identifiers are required."); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryServiceClient.GetAllTagsByListService(request, cancellationToken)).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError(ex, $"{nameof(GetAllTagsByListAsync)} - An error occurred - {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload: {request}"); | ||||||
|  |                 return StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new Tag. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPost("Create")] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||||
|  |         public async Task<IActionResult> CreateTagService(CreateTagRequest newTag, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(CreateTagService)} - Request received - Payload: {JsonSerializer.Serialize(newTag)}"); | ||||||
|  |  | ||||||
|  |                 if (newTag == null) return BadRequest("Invalid Tag object"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(newTag.TagName)) return BadRequest("Invalid Tag name"); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryServiceClient.CreateTagService(newTag, cancellationToken)).ConfigureAwait(false); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError($"{nameof(CreateTagService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newTag)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets the Tag by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPost("GetById")] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||||
|  |         public async Task<IActionResult> GetTagByIdService(GetTagRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(GetTagByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid Tag identifier"); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryServiceClient.GetTagByIdService(request, cancellationToken)).ConfigureAwait(false); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError($"{nameof(GetTagByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a full Tag by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPut("Update")] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||||
|  |         public async Task<IActionResult> UpdateTagService(UpdateTagRequest newTag, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(UpdateTagService)} - Request received - Payload: {JsonSerializer.Serialize(newTag)}"); | ||||||
|  |  | ||||||
|  |                 if (newTag == null) return BadRequest("Invalid Tag object"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(newTag.TagName)) return BadRequest("Invalid Tag name"); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryServiceClient.UpdateTagService(newTag, cancellationToken)).ConfigureAwait(false); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError($"{nameof(UpdateTagService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newTag)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of the Tag. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPatch] | ||||||
|  |         [Route("ChangeStatus")] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||||
|  |         public async Task<IActionResult> ChangeTagStatusService([FromBody] ChangeTagStatusRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(ChangeTagStatusService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid Tag identifier"); } | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryServiceClient.ChangeTagStatusService(request, cancellationToken)).ConfigureAwait(false); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError($"{nameof(ChangeTagStatusService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Adds a parentTag to the tag. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPost] | ||||||
|  |         [Route("AddParentTag")] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||||
|  |         public async Task<IActionResult> AddParentTagAsync([FromBody] AddParentTagToTagRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(AddParentTagAsync)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(request.TagId)) { return BadRequest("Invalid tag identifier"); } | ||||||
|  |                 if (string.IsNullOrEmpty(request.ParentTagId)) { return BadRequest("Invalid parentTag identifier"); } | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryServiceClient.AddParentTagAsync(request, cancellationToken)).ConfigureAwait(false); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError($"{nameof(AddParentTagAsync)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Remove a parentTag to the tag. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpDelete] | ||||||
|  |         [Route("RemoveParentTag")] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||||
|  |         public async Task<IActionResult> RemoveParentTagAsync([FromBody] RemoveParentTagFromTag request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(RemoveParentTagAsync)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(request.TagId)) { return BadRequest("Invalid tag identifier"); } | ||||||
|  |                 if (string.IsNullOrEmpty(request.ParentTagId)) { return BadRequest("Invalid parentTag identifier"); } | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryServiceClient.RemoveParentTagAsync(request, cancellationToken)).ConfigureAwait(false); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError($"{nameof(RemoveParentTagAsync)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										203
									
								
								Core.Inventory.BFF.API/Controllers/TagTypeController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										203
									
								
								Core.Inventory.BFF.API/Controllers/TagTypeController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,203 @@ | |||||||
|  | using Asp.Versioning; | ||||||
|  | using Core.Adapters.Lib; | ||||||
|  | using Core.Inventory.External.Clients.Inventory; | ||||||
|  | using Core.Inventory.External.Clients.Inventory.Requests.TagType; | ||||||
|  | using Lib.Architecture.BuildingBlocks; | ||||||
|  | using Microsoft.AspNetCore.Authorization; | ||||||
|  | using Microsoft.AspNetCore.Mvc; | ||||||
|  | using System.Text.Json; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.BFF.API.Controllers | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all requests for TagType authentication. | ||||||
|  |     /// </summary> | ||||||
|  |     [ApiVersion("1.0")] | ||||||
|  |     [Route("api/v{version:apiVersion}/[controller]")] | ||||||
|  |     [Consumes("application/json")] | ||||||
|  |     [Produces("application/json")] | ||||||
|  |     [ApiController] | ||||||
|  |     [AllowAnonymous] | ||||||
|  |     public class TagTypeController(IInventoryServiceClient inventoryServiceClient, ILogger<TagTypeController> logger) : BaseController(logger) | ||||||
|  |     { | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the TagTypes. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpGet("GetAll")] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||||
|  |         public async Task<IActionResult> GetAllTagTypesService(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(GetAllTagTypesService)} - Request received - Payload: "); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryServiceClient.GetAllTagTypesService(new GetAllTagTypesRequest { }, cancellationToken)).ConfigureAwait(false); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError($"{nameof(GetAllTagTypesService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the TagTypes by TagType identifiers. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="request">The request containing the list of TagType identifiers.</param> | ||||||
|  |         /// <param name="cancellationToken">Cancellation token for the asynchronous operation.</param> | ||||||
|  |         /// <returns>The <see cref="IActionResult"/> representing the result of the service call.</returns> | ||||||
|  |         /// <response code="200">The TagTypes found.</response> | ||||||
|  |         /// <response code="204">No content if no TagTypes are found.</response> | ||||||
|  |         /// <response code="400">Bad request if the TagType identifiers are missing or invalid.</response> | ||||||
|  |         /// <response code="401">Unauthorized if the user is not authenticated.</response> | ||||||
|  |         /// <response code="500">Internal server error if an unexpected error occurs.</response> | ||||||
|  |         [HttpPost("GetAllByList")] | ||||||
|  |         [ProducesResponseType(typeof(IEnumerable<TagTypeAdapter>), StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||||
|  |         public async Task<IActionResult> GetAllTagTypesByListAsync([FromBody] GetAllTagTypesByListRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(GetAllTagTypesByListAsync)} - Request received - Payload: {request}"); | ||||||
|  |  | ||||||
|  |                 if (request == null || request.TagTypes == null || !request.TagTypes.Any()) | ||||||
|  |                 { | ||||||
|  |                     return BadRequest("TagType identifiers are required."); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryServiceClient.GetAllTagTypesByListService(request, cancellationToken)).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError(ex, $"{nameof(GetAllTagTypesByListAsync)} - An error occurred - {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload: {request}"); | ||||||
|  |                 return StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new TagType. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPost("Create")] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||||
|  |         public async Task<IActionResult> CreateTagTypeService(CreateTagTypeRequest newTagType, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(CreateTagTypeService)} - Request received - Payload: {JsonSerializer.Serialize(newTagType)}"); | ||||||
|  |  | ||||||
|  |                 if (newTagType == null) return BadRequest("Invalid TagType object"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(newTagType.TypeName)) return BadRequest("Invalid TagType name"); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryServiceClient.CreateTagTypeService(newTagType, cancellationToken)).ConfigureAwait(false); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError($"{nameof(CreateTagTypeService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newTagType)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets the TagType by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPost("GetById")] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||||
|  |         public async Task<IActionResult> GetTagTypeByIdService(GetTagTypeRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(GetTagTypeByIdService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(request.Id)) return BadRequest("Invalid TagType identifier"); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryServiceClient.GetTagTypeByIdService(request, cancellationToken)).ConfigureAwait(false); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError($"{nameof(GetTagTypeByIdService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a full TagType by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPut("Update")] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||||
|  |         public async Task<IActionResult> UpdateTagTypeService(UpdateTagTypeRequest newTagType, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(UpdateTagTypeService)} - Request received - Payload: {JsonSerializer.Serialize(newTagType)}"); | ||||||
|  |  | ||||||
|  |                 if (newTagType == null) return BadRequest("Invalid TagType object"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(newTagType.TypeName)) return BadRequest("Invalid TagType name"); | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryServiceClient.UpdateTagTypeService(newTagType, cancellationToken)).ConfigureAwait(false); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError($"{nameof(UpdateTagTypeService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(newTagType)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of the TagType. | ||||||
|  |         /// </summary> | ||||||
|  |         [HttpPatch] | ||||||
|  |         [Route("ChangeStatus")] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status200OK)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status400BadRequest)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status401Unauthorized)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status412PreconditionFailed)] | ||||||
|  |         [ProducesResponseType(typeof(Notification), StatusCodes.Status422UnprocessableEntity)] | ||||||
|  |         [ProducesResponseType(StatusCodes.Status500InternalServerError)] | ||||||
|  |         public async Task<IActionResult> ChangeTagTypeStatusService([FromBody] ChangeTagTypeStatusRequest request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 logger.LogInformation($"{nameof(ChangeTagTypeStatusService)} - Request received - Payload: {JsonSerializer.Serialize(request)}"); | ||||||
|  |  | ||||||
|  |                 if (string.IsNullOrEmpty(request.Id)) { return BadRequest("Invalid TagType identifier"); } | ||||||
|  |  | ||||||
|  |                 return await Handle(() => inventoryServiceClient.ChangeTagTypeStatusService(request, cancellationToken)).ConfigureAwait(false); | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 logger.LogError($"{nameof(ChangeTagTypeStatusService)} - An Error Occurred- {ex.Message} - {ex.InnerException} - {ex.StackTrace} - with payload {JsonSerializer.Serialize(request)}"); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -1,33 +0,0 @@ | |||||||
| using Microsoft.AspNetCore.Mvc; |  | ||||||
|  |  | ||||||
| namespace Core.Inventory.BFF.API.Controllers |  | ||||||
| { |  | ||||||
|     [ApiController] |  | ||||||
|     [Route("[controller]")] |  | ||||||
|     public class WeatherForecastController : ControllerBase |  | ||||||
|     { |  | ||||||
|         private static readonly string[] Summaries = new[] |  | ||||||
|         { |  | ||||||
|             "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" |  | ||||||
|         }; |  | ||||||
|  |  | ||||||
|         private readonly ILogger<WeatherForecastController> _logger; |  | ||||||
|  |  | ||||||
|         public WeatherForecastController(ILogger<WeatherForecastController> logger) |  | ||||||
|         { |  | ||||||
|             _logger = logger; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         [HttpGet(Name = "GetWeatherForecast")] |  | ||||||
|         public IEnumerable<WeatherForecast> Get() |  | ||||||
|         { |  | ||||||
|             return Enumerable.Range(1, 5).Select(index => new WeatherForecast |  | ||||||
|             { |  | ||||||
|                 Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), |  | ||||||
|                 TemperatureC = Random.Shared.Next(-20, 55), |  | ||||||
|                 Summary = Summaries[Random.Shared.Next(Summaries.Length)] |  | ||||||
|             }) |  | ||||||
|             .ToArray(); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -7,7 +7,15 @@ | |||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" /> |     <PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" /> | ||||||
|  |     <PackageReference Include="Core.Blueprint.Logging" Version="1.0.1" /> | ||||||
|  |     <PackageReference Include="OpenTelemetry" Version="1.12.0" /> | ||||||
|  |     <PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.12.0" /> | ||||||
|  |     <PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.4" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |  | ||||||
|  |   <ItemGroup> | ||||||
|  |     <ProjectReference Include="..\Core.Inventory.External\Core.Inventory.External.csproj" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
| </Project> | </Project> | ||||||
|   | |||||||
| @@ -1,25 +1,133 @@ | |||||||
|  | using Core.Blueprint.Logging.Configuration; | ||||||
|  | using Core.Inventory.External; | ||||||
|  | using Core.Inventory.External.ClientConfiguration; | ||||||
|  | using Microsoft.AspNetCore.ResponseCompression; | ||||||
|  | using OpenTelemetry.Logs; | ||||||
|  | using OpenTelemetry.Resources; | ||||||
|  | using Swashbuckle.AspNetCore.SwaggerUI; | ||||||
|  | using System.IO.Compression; | ||||||
|  | using System.Reflection; | ||||||
|  |  | ||||||
| var builder = WebApplication.CreateBuilder(args); | var builder = WebApplication.CreateBuilder(args); | ||||||
|  |  | ||||||
| // Add services to the container. |  | ||||||
|  |  | ||||||
| builder.Services.AddControllers(); |  | ||||||
| // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle |  | ||||||
| builder.Services.AddEndpointsApiExplorer(); | builder.Services.AddEndpointsApiExplorer(); | ||||||
| builder.Services.AddSwaggerGen(); | builder.Configuration | ||||||
|  |     .AddUserSecrets(Assembly.GetExecutingAssembly()) | ||||||
|  |     .AddEnvironmentVariables(); | ||||||
|  |  | ||||||
|  | builder.Services.AddResponseCompression(); | ||||||
|  | builder.Services.AddProblemDetails(); | ||||||
|  | builder.Services.AddLogs(builder); | ||||||
|  | builder.Services.AddMemoryCache(); | ||||||
|  | builder.Services.AddResponseCaching(configureOptions => { configureOptions.UseCaseSensitivePaths = true; }); | ||||||
|  | builder.Logging.AddOpenTelemetry(options => | ||||||
|  | { | ||||||
|  |     options.IncludeScopes = true; | ||||||
|  |     options.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("core.inventory.bff.api")).AddConsoleExporter(); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | builder.Host.ConfigureServices((context, services) => | ||||||
|  | { | ||||||
|  |     builder.Services.AddHsts(options => | ||||||
|  |     { | ||||||
|  |         options.Preload = true; | ||||||
|  |         options.IncludeSubDomains = true; | ||||||
|  |         options.MaxAge = TimeSpan.FromDays(60); | ||||||
|  |     }); | ||||||
|  |     builder.Services.AddResponseCaching(configureOptions => | ||||||
|  |     { | ||||||
|  |         configureOptions.UseCaseSensitivePaths = true; | ||||||
|  |         configureOptions.MaximumBodySize = 2048; | ||||||
|  |     }); | ||||||
|  |     builder.Services.AddHttpsRedirection(options => | ||||||
|  |     { | ||||||
|  |         options.RedirectStatusCode = 308; | ||||||
|  |     }); | ||||||
|  |  | ||||||
|  |     services.AddHttpLogging(http => | ||||||
|  |     { | ||||||
|  |         http.CombineLogs = true; | ||||||
|  |     }); | ||||||
|  |     services.AddAntiforgery(); | ||||||
|  |  | ||||||
|  |     services.AddCors(options => | ||||||
|  |     { | ||||||
|  |         options.AddPolicy("AllowAll", policyBuilder => | ||||||
|  |             policyBuilder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()); | ||||||
|  |     }); | ||||||
|  |     services.AddMvc().AddJsonOptions(options => | ||||||
|  |     { | ||||||
|  |         options.JsonSerializerOptions.WriteIndented = true; | ||||||
|  |         options.JsonSerializerOptions.MaxDepth = 20; | ||||||
|  |         options.JsonSerializerOptions.NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals; | ||||||
|  |     }); | ||||||
|  |     services.Configure<BrotliCompressionProviderOptions>(options => | ||||||
|  |     { | ||||||
|  |         options.Level = CompressionLevel.SmallestSize; | ||||||
|  |     }); | ||||||
|  |     services.Configure<GzipCompressionProviderOptions>(options => | ||||||
|  |     { | ||||||
|  |         options.Level = CompressionLevel.SmallestSize; | ||||||
|  |     }); | ||||||
|  |     services.AddResponseCompression(options => | ||||||
|  |     { | ||||||
|  |         options.EnableForHttps = true; | ||||||
|  |         options.Providers.Add<BrotliCompressionProvider>(); | ||||||
|  |         options.Providers.Add<GzipCompressionProvider>(); | ||||||
|  |     }); | ||||||
|  |     services.AddResponseCaching(); | ||||||
|  |     services.AddControllers(); | ||||||
|  |     services.AddEndpointsApiExplorer(); | ||||||
|  |     services.AddSwaggerGen(); | ||||||
|  |     services.AddLogging(); | ||||||
|  |     services.AddProblemDetails(); | ||||||
|  |     services.AddHttpContextAccessor(); | ||||||
|  |     services.AddTransient<TrackingMechanismExtension>(); // Register the TrackingIdHandler | ||||||
|  |     services.RegisterExternalLayer(builder.Configuration); | ||||||
|  |  | ||||||
|  |     services.AddApiVersioning(options => options.ReportApiVersions = true) | ||||||
|  |                    .AddApiExplorer(options => | ||||||
|  |                    { | ||||||
|  |                        options.GroupNameFormat = "'v'VVV"; | ||||||
|  |                        options.SubstituteApiVersionInUrl = true; | ||||||
|  |                    }); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | builder.Services.AddCors(options => | ||||||
|  | { | ||||||
|  |     options.AddDefaultPolicy( | ||||||
|  |         builder => | ||||||
|  |         { | ||||||
|  |             builder.AllowAnyOrigin() | ||||||
|  |                                 .AllowAnyHeader() | ||||||
|  |                                 .AllowAnyMethod(); | ||||||
|  |         }); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | //*************************************************************************// | ||||||
|  |  | ||||||
| var app = builder.Build(); | var app = builder.Build(); | ||||||
|  |  | ||||||
| // Configure the HTTP request pipeline. | app.UseCors(options => options.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()); | ||||||
| if (app.Environment.IsDevelopment()) | app.UseSwagger(); | ||||||
|  | app.UseSwaggerUI(options => | ||||||
| { | { | ||||||
|     app.UseSwagger(); |     foreach (var version in app.DescribeApiVersions().Select(version => version.GroupName)) | ||||||
|     app.UseSwaggerUI(); |         options.SwaggerEndpoint($"/swagger/{version}/swagger.json", version); | ||||||
| } |  | ||||||
|  |  | ||||||
|  |     options.DisplayRequestDuration(); | ||||||
|  |     options.EnableTryItOutByDefault(); | ||||||
|  |     options.DocExpansion(DocExpansion.None); | ||||||
|  | }); | ||||||
|  | app.UseResponseCompression(); | ||||||
|  | app.UseResponseCaching(); | ||||||
| app.UseHttpsRedirection(); | app.UseHttpsRedirection(); | ||||||
|  |  | ||||||
|  | app.UseAuthentication(); | ||||||
| app.UseAuthorization(); | app.UseAuthorization(); | ||||||
|  |  | ||||||
| app.MapControllers(); | app.MapControllers(); | ||||||
|  | app.UseHsts(); | ||||||
|  | app.UseAntiforgery(); | ||||||
|  | app.UseLogging(builder.Configuration); | ||||||
|  |  | ||||||
| app.Run(); | app.Run(); | ||||||
|   | |||||||
| @@ -16,7 +16,7 @@ | |||||||
|       "launchUrl": "swagger", |       "launchUrl": "swagger", | ||||||
|       "applicationUrl": "http://localhost:5101", |       "applicationUrl": "http://localhost:5101", | ||||||
|       "environmentVariables": { |       "environmentVariables": { | ||||||
|         "ASPNETCORE_ENVIRONMENT": "Development" |         "ASPNETCORE_ENVIRONMENT": "Local" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "https": { |     "https": { | ||||||
| @@ -26,7 +26,7 @@ | |||||||
|       "launchUrl": "swagger", |       "launchUrl": "swagger", | ||||||
|       "applicationUrl": "https://localhost:7223;http://localhost:5101", |       "applicationUrl": "https://localhost:7223;http://localhost:5101", | ||||||
|       "environmentVariables": { |       "environmentVariables": { | ||||||
|         "ASPNETCORE_ENVIRONMENT": "Development" |         "ASPNETCORE_ENVIRONMENT": "Local" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "IIS Express": { |     "IIS Express": { | ||||||
| @@ -34,7 +34,7 @@ | |||||||
|       "launchBrowser": true, |       "launchBrowser": true, | ||||||
|       "launchUrl": "swagger", |       "launchUrl": "swagger", | ||||||
|       "environmentVariables": { |       "environmentVariables": { | ||||||
|         "ASPNETCORE_ENVIRONMENT": "Development" |         "ASPNETCORE_ENVIRONMENT": "Local" | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -1,13 +0,0 @@ | |||||||
| namespace Core.Inventory.BFF.API |  | ||||||
| { |  | ||||||
|     public class WeatherForecast |  | ||||||
|     { |  | ||||||
|         public DateOnly Date { get; set; } |  | ||||||
|  |  | ||||||
|         public int TemperatureC { get; set; } |  | ||||||
|  |  | ||||||
|         public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); |  | ||||||
|  |  | ||||||
|         public string? Summary { get; set; } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
							
								
								
									
										12
									
								
								Core.Inventory.BFF.API/appsettings.Local.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Core.Inventory.BFF.API/appsettings.Local.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  | { | ||||||
|  |   "Logging": { | ||||||
|  |     "LogLevel": { | ||||||
|  |       "Default": "Information", | ||||||
|  |       "Microsoft.AspNetCore": "Warning" | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  |   "LocalGateways": { | ||||||
|  |     "InventoryService": "https://localhost:7028" | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
| @@ -5,6 +5,10 @@ VisualStudioVersion = 17.14.36212.18 d17.14 | |||||||
| MinimumVisualStudioVersion = 10.0.40219.1 | MinimumVisualStudioVersion = 10.0.40219.1 | ||||||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Inventory.BFF.API", "Core.Inventory.BFF.API\Core.Inventory.BFF.API.csproj", "{A7C30239-BEB4-4DD5-A5C4-AEB4B5154927}" | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Inventory.BFF.API", "Core.Inventory.BFF.API\Core.Inventory.BFF.API.csproj", "{A7C30239-BEB4-4DD5-A5C4-AEB4B5154927}" | ||||||
| EndProject | EndProject | ||||||
|  | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Application", "Application", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}" | ||||||
|  | EndProject | ||||||
|  | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.Inventory.External", "Core.Inventory.External\Core.Inventory.External.csproj", "{AC69431D-D222-4376-BCE3-31C7201B1F01}" | ||||||
|  | EndProject | ||||||
| Global | Global | ||||||
| 	GlobalSection(SolutionConfigurationPlatforms) = preSolution | 	GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||||
| 		Debug|Any CPU = Debug|Any CPU | 		Debug|Any CPU = Debug|Any CPU | ||||||
| @@ -15,10 +19,17 @@ Global | |||||||
| 		{A7C30239-BEB4-4DD5-A5C4-AEB4B5154927}.Debug|Any CPU.Build.0 = Debug|Any CPU | 		{A7C30239-BEB4-4DD5-A5C4-AEB4B5154927}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||||
| 		{A7C30239-BEB4-4DD5-A5C4-AEB4B5154927}.Release|Any CPU.ActiveCfg = Release|Any CPU | 		{A7C30239-BEB4-4DD5-A5C4-AEB4B5154927}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||||
| 		{A7C30239-BEB4-4DD5-A5C4-AEB4B5154927}.Release|Any CPU.Build.0 = Release|Any CPU | 		{A7C30239-BEB4-4DD5-A5C4-AEB4B5154927}.Release|Any CPU.Build.0 = Release|Any CPU | ||||||
|  | 		{AC69431D-D222-4376-BCE3-31C7201B1F01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||||
|  | 		{AC69431D-D222-4376-BCE3-31C7201B1F01}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||||
|  | 		{AC69431D-D222-4376-BCE3-31C7201B1F01}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||||
|  | 		{AC69431D-D222-4376-BCE3-31C7201B1F01}.Release|Any CPU.Build.0 = Release|Any CPU | ||||||
| 	EndGlobalSection | 	EndGlobalSection | ||||||
| 	GlobalSection(SolutionProperties) = preSolution | 	GlobalSection(SolutionProperties) = preSolution | ||||||
| 		HideSolutionNode = FALSE | 		HideSolutionNode = FALSE | ||||||
| 	EndGlobalSection | 	EndGlobalSection | ||||||
|  | 	GlobalSection(NestedProjects) = preSolution | ||||||
|  | 		{AC69431D-D222-4376-BCE3-31C7201B1F01} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} | ||||||
|  | 	EndGlobalSection | ||||||
| 	GlobalSection(ExtensibilityGlobals) = postSolution | 	GlobalSection(ExtensibilityGlobals) = postSolution | ||||||
| 		SolutionGuid = {97B12EA0-3BE9-4A8D-8918-7152ADB153B1} | 		SolutionGuid = {97B12EA0-3BE9-4A8D-8918-7152ADB153B1} | ||||||
| 	EndGlobalSection | 	EndGlobalSection | ||||||
|   | |||||||
| @@ -0,0 +1,65 @@ | |||||||
|  | using Core.Inventory.External.Clients.Inventory; | ||||||
|  | using Core.Inventory.External.GatewayConfigurations; | ||||||
|  | using Lib.Architecture.BuildingBlocks.Helpers.Token; | ||||||
|  | using Microsoft.AspNetCore.Http; | ||||||
|  | using Microsoft.Extensions.Configuration; | ||||||
|  | using Microsoft.Extensions.DependencyInjection; | ||||||
|  | using Refit; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.External.ClientConfiguration | ||||||
|  | { | ||||||
|  |     public static class RegisterClientConfiguration | ||||||
|  |     { | ||||||
|  |         public static IServiceCollection RegisterExternalLayer(this IServiceCollection services, IConfiguration configuration) | ||||||
|  |         { | ||||||
|  |             var gatewayConfiguration = new GatewayConfiguration(); | ||||||
|  |             var gatewaySettingsConfiguration = new GatewaySettingsConfigurations(configuration); | ||||||
|  |  | ||||||
|  |             // Register GatewayConfiguration as a singleton | ||||||
|  |             services.AddSingleton(gatewayConfiguration); | ||||||
|  |  | ||||||
|  |             // Register IHttpContextAccessor | ||||||
|  |             services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); | ||||||
|  |  | ||||||
|  |             // Register ITokenProvider | ||||||
|  |             services.AddSingleton<ITokenProvider, HttpContextTokenProvider>(); | ||||||
|  |  | ||||||
|  |             // Register the custom AuthenticatedHttpClientHandler | ||||||
|  |             services.AddTransient(provider => | ||||||
|  |             { | ||||||
|  |                 var tokenProvider = provider.GetRequiredService<ITokenProvider>(); | ||||||
|  |                 var trackingIdHandler = new TrackingMechanismExtension(provider.GetRequiredService<IHttpContextAccessor>()); | ||||||
|  |  | ||||||
|  |                 var handler = new AuthenticatedHttpClientHandler(tokenProvider) | ||||||
|  |                 { | ||||||
|  |                     InnerHandler = new HttpClientHandler() // Setting the InnerHandler manually | ||||||
|  |                 }; | ||||||
|  |  | ||||||
|  |                 // Attach the TrackingIdHandler as the outermost handler | ||||||
|  |                 trackingIdHandler.InnerHandler = handler; | ||||||
|  |  | ||||||
|  |                 return handler; | ||||||
|  |             }); | ||||||
|  |  | ||||||
|  |             var inventoryServiceApiUrl = GatewaySettingsConfigurations.GetInventoryServiceAPIEndpoint().Endpoint.Url; | ||||||
|  |  | ||||||
|  |             // Register IDashBoardServiceClient with the manually created HttpClient | ||||||
|  |             services.AddScoped(provider => | ||||||
|  |             { | ||||||
|  |                 var handler = provider.GetRequiredService<AuthenticatedHttpClientHandler>(); | ||||||
|  |                 var handlerTrackingId = new TrackingMechanismExtension(provider.GetRequiredService<IHttpContextAccessor>()); // Using the TrackingIdHandler here | ||||||
|  |                                                                                                                              // Chain the handlers | ||||||
|  |                 handlerTrackingId.InnerHandler = handler; //chaining | ||||||
|  |  | ||||||
|  |                 var httpClient = new HttpClient(handlerTrackingId) | ||||||
|  |                 { | ||||||
|  |                     BaseAddress = new Uri(inventoryServiceApiUrl), | ||||||
|  |                     Timeout = TimeSpan.FromMinutes(1) | ||||||
|  |                 }; | ||||||
|  |                 return RestService.For<IInventoryServiceClient>(httpClient); | ||||||
|  |             }); | ||||||
|  |  | ||||||
|  |             return services; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,106 @@ | |||||||
|  | using Core.Adapters.Lib; | ||||||
|  | using Core.Inventory.External.Clients.Inventory.Requests.Base; | ||||||
|  | using Core.Inventory.External.Clients.Inventory.Requests.Tag; | ||||||
|  | using Core.Inventory.External.Clients.Inventory.Requests.TagType; | ||||||
|  | using Core.Inventory.External.Clients.Inventory.Requests.Variant; | ||||||
|  | using Refit; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.External.Clients.Inventory | ||||||
|  | { | ||||||
|  |     public interface IInventoryServiceClient | ||||||
|  |     { | ||||||
|  |         #region Furniture Base | ||||||
|  |  | ||||||
|  |         [Get("/api/v1/FurnitureBase/GetAll")] | ||||||
|  |         Task<ApiResponse<IEnumerable<FurnitureBase>>> GetAllBaseAsync([Header("TrackingId")] string trackingId, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/FurnitureBase/GetById")] | ||||||
|  |         Task<ApiResponse<FurnitureBase>> GetByIdAsync([Header("TrackingId")] string trackingId, [Body] GetFurnitureBaseByIdRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/FurnitureBase/Create")] | ||||||
|  |         Task<ApiResponse<FurnitureBase>> CreateAsync([Header("TrackingId")] string trackingId, [Body] CreateFurnitureBaseRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Put("/api/v1/FurnitureBase/Update")] | ||||||
|  |         Task<ApiResponse<FurnitureBase>> UpdateFurnitureBaseAsync([Header("TrackingId")] string trackingId, [Body] UpdateFurnitureBaseRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Patch("/api/v1/FurnitureBase/ChangeStatus")] | ||||||
|  |         Task<ApiResponse<FurnitureBase>> ChangeFurnitureBaseStatusAsync([Header("TrackingId")] string trackingId, [Body] ChangeFurnitureBaseStatusRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         #endregion | ||||||
|  |  | ||||||
|  |         #region Furniture Variant | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/FurnitureVariant/GetAllByModelId")] | ||||||
|  |         Task<ApiResponse<IEnumerable<FurnitureVariant>>> GetAllVariantsByModelIdAsync([Header("TrackingId")] string trackingId, [Body] GetAllFurnitureVariantsByModelIdRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/FurnitureVariant/GetById")] | ||||||
|  |         Task<ApiResponse<FurnitureVariant>> GetFurnitureVariantByIdAsync([Header("TrackingId")] string trackingId, [Body] GetFurnitureVariantByIdRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/FurnitureVariant/GetByIds")] | ||||||
|  |         Task<ApiResponse<IEnumerable<FurnitureVariant>>> GetFurnitureVariantsByIdsAsync([Header("TrackingId")] string trackingId, [Body] GetFurnitureVariantsByIdsRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/FurnitureVariant/Create")] | ||||||
|  |         Task<ApiResponse<FurnitureVariant>> CreateFurnitureVariantAsync([Header("TrackingId")] string trackingId, [Body] CreateFurnitureVariantRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Put("/api/v1/FurnitureVariant/Update")] | ||||||
|  |         Task<ApiResponse<FurnitureVariant>> UpdateFurnitureVariantAsync([Header("TrackingId")] string trackingId, string id, [Body] UpdateFurnitureVariantRequest entity, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Patch("/api/v1/FurnitureVariant/ChangeStatus")] | ||||||
|  |         Task<ApiResponse<FurnitureVariant>> ChangeFurnitureVariantStatusAsync([Header("TrackingId")] string trackingId, [Body] ChangeFurnitureVariantStatusRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Get("/api/v1/FurnitureVariant/GetAll")] | ||||||
|  |         Task<ApiResponse<IEnumerable<FurnitureVariant>>> GetAllVariantsAsync([Header("TrackingId")] string trackingId, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         #endregion | ||||||
|  |  | ||||||
|  |         #region TagType | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/TagType/Create")] | ||||||
|  |         Task<ApiResponse<TagTypeAdapter>> CreateTagTypeService([Header("TrackingId")][Body] CreateTagTypeRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/TagType/GetById")] | ||||||
|  |         Task<ApiResponse<TagTypeAdapter>> GetTagTypeByIdService([Header("TrackingId")][Body] GetTagTypeRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Get("/api/v1/TagType/GetAll")] | ||||||
|  |         Task<ApiResponse<IEnumerable<TagTypeAdapter>>> GetAllTagTypesService([Header("TrackingId")][Body] GetAllTagTypesRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/TagType/GetTagTypeList")] | ||||||
|  |         Task<ApiResponse<IEnumerable<TagTypeAdapter>>> GetAllTagTypesByListService([Header("TrackingId")][Body] GetAllTagTypesByListRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Put("/api/v1/TagType/Update")] | ||||||
|  |         Task<ApiResponse<TagTypeAdapter>> UpdateTagTypeService([Header("TrackingId")][Body] UpdateTagTypeRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Patch("/api/v1/TagType/ChangeStatus")] | ||||||
|  |         Task<ApiResponse<TagTypeAdapter>> ChangeTagTypeStatusService([Header("TrackingId")][Body] ChangeTagTypeStatusRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         #endregion | ||||||
|  |  | ||||||
|  |         #region Tag | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/Tag/Create")] | ||||||
|  |         Task<ApiResponse<TagAdapter>> CreateTagService([Header("TrackingId")][Body] CreateTagRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/Tag/GetById")] | ||||||
|  |         Task<ApiResponse<TagAdapter>> GetTagByIdService([Header("TrackingId")][Body] GetTagRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Get("/api/v1/Tag/GetAll")] | ||||||
|  |         Task<ApiResponse<IEnumerable<TagAdapter>>> GetAllTagsService([Header("TrackingId")][Body] GetAllTagsRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/Tag/GetTagList")] | ||||||
|  |         Task<ApiResponse<IEnumerable<TagAdapter>>> GetAllTagsByListService([Header("TrackingId")][Body] GetAllTagsByListRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Put("/api/v1/Tag/Update")] | ||||||
|  |         Task<ApiResponse<TagAdapter>> UpdateTagService([Header("TrackingId")][Body] UpdateTagRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Patch("/api/v1/Tag/ChangeStatus")] | ||||||
|  |         Task<ApiResponse<TagAdapter>> ChangeTagStatusService([Header("TrackingId")][Body] ChangeTagStatusRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Post("/api/v1/Tag/AddParentTag")] | ||||||
|  |         Task<ApiResponse<TagAdapter>> AddParentTagAsync([Header("TrackingId")][Body] AddParentTagToTagRequest request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         [Delete("/api/v1/Tag/RemoveParentTag")] | ||||||
|  |         Task<ApiResponse<TagAdapter>> RemoveParentTagAsync([Header("TrackingId")][Body] RemoveParentTagFromTag request, CancellationToken cancellationToken = default); | ||||||
|  |  | ||||||
|  |         #endregion | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,10 @@ | |||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Base | ||||||
|  | { | ||||||
|  |     public class ChangeFurnitureBaseStatusRequest | ||||||
|  |     { | ||||||
|  |         public string MongoId { get; set; } = default!; | ||||||
|  |         public StatusEnum Status { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,16 @@ | |||||||
|  | using Core.Inventory.External.Clients.Inventory.Requests.Common; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Base | ||||||
|  | { | ||||||
|  |     public class CreateFurnitureBaseRequest | ||||||
|  |     { | ||||||
|  |         public string ModelName { get; set; } = default!; | ||||||
|  |         public string Material { get; set; } = default!; | ||||||
|  |         public string Condition { get; set; } = default!; | ||||||
|  |         public string? BaseDescription { get; set; } | ||||||
|  |         public string? Representation { get; set; } | ||||||
|  |         public string? MaintenanceNotes { get; set; } | ||||||
|  |         public DimensionsRequest Dimensions { get; set; } = new(); | ||||||
|  |         public List<string>? VariantIds { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,6 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Base | ||||||
|  | { | ||||||
|  |     public class GetAllFurnitureBaseRequest | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,7 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Base | ||||||
|  | { | ||||||
|  |     public class GetFurnitureBaseByIdRequest | ||||||
|  |     { | ||||||
|  |         public string MongoId { get; set; } = default!; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,18 @@ | |||||||
|  | using Core.Inventory.External.Clients.Inventory.Requests.Common; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Base | ||||||
|  | { | ||||||
|  |     public class UpdateFurnitureBaseRequest | ||||||
|  |     { | ||||||
|  |         public string _Id { get; set; } = default!; | ||||||
|  |         public string Id { get; set; } = default!; | ||||||
|  |         public string ModelName { get; set; } = default!; | ||||||
|  |         public string Material { get; set; } = default!; | ||||||
|  |         public string Condition { get; set; } = default!; | ||||||
|  |         public string? BaseDescription { get; set; } | ||||||
|  |         public string? Representation { get; set; } | ||||||
|  |         public string? MaintenanceNotes { get; set; } | ||||||
|  |         public DimensionsRequest Dimensions { get; set; } = new(); | ||||||
|  |         public List<string>? VariantIds { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,9 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Common | ||||||
|  | { | ||||||
|  |     public class DimensionsRequest | ||||||
|  |     { | ||||||
|  |         public decimal Width { get; set; } | ||||||
|  |         public decimal Height { get; set; } | ||||||
|  |         public decimal Depth { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,8 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Tag | ||||||
|  | { | ||||||
|  |     public class AddParentTagToTagRequest | ||||||
|  |     { | ||||||
|  |         public string TagId { get; set; } | ||||||
|  |         public string ParentTagId { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,10 @@ | |||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Tag | ||||||
|  | { | ||||||
|  |     public class ChangeTagStatusRequest | ||||||
|  |     { | ||||||
|  |         public string Id { get; set; } | ||||||
|  |         public StatusEnum Status { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,13 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Tag | ||||||
|  | { | ||||||
|  |     public class CreateTagRequest | ||||||
|  |     { | ||||||
|  |         public string TenantId { get; set; } = null!; | ||||||
|  |         public string TagName { get; set; } = null!; | ||||||
|  |         public string TypeId { get; set; } = null!; | ||||||
|  |         public string[] ParentTagId { get; set; } = null!; | ||||||
|  |         public string Slug { get; set; } = null!; | ||||||
|  |         public int DisplayOrder { get; set; } | ||||||
|  |         public string Icon { get; set; } = null!; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,7 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Tag | ||||||
|  | { | ||||||
|  |     public class GetAllTagsByListRequest | ||||||
|  |     { | ||||||
|  |         public string[] Tags { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,6 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Tag | ||||||
|  | { | ||||||
|  |     public class GetAllTagsRequest | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,7 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Tag | ||||||
|  | { | ||||||
|  |     public class GetTagRequest | ||||||
|  |     { | ||||||
|  |         public string Id { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,8 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Tag | ||||||
|  | { | ||||||
|  |     public class RemoveParentTagFromTag | ||||||
|  |     { | ||||||
|  |         public string TagId { get; set; } | ||||||
|  |         public string ParentTagId { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,17 @@ | |||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Tag | ||||||
|  | { | ||||||
|  |     public class UpdateTagRequest | ||||||
|  |     { | ||||||
|  |         public string Id { get; set; } = null!; | ||||||
|  |         public string TenantId { get; set; } = null!; | ||||||
|  |         public string TagName { get; set; } = null!; | ||||||
|  |         public string TypeId { get; set; } = null!; | ||||||
|  |         public string[] ParentTagId { get; set; } = null!; | ||||||
|  |         public string Slug { get; set; } = null!; | ||||||
|  |         public int DisplayOrder { get; set; } | ||||||
|  |         public string Icon { get; set; } = null!; | ||||||
|  |         public StatusEnum Status { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,10 @@ | |||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.TagType | ||||||
|  | { | ||||||
|  |     public class ChangeTagTypeStatusRequest | ||||||
|  |     { | ||||||
|  |         public string Id { get; set; } | ||||||
|  |         public StatusEnum Status { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,10 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.TagType | ||||||
|  | { | ||||||
|  |     public class CreateTagTypeRequest | ||||||
|  |     { | ||||||
|  |         public string TenantId { get; set; } = null!; | ||||||
|  |         public string TypeName { get; set; } = null!; | ||||||
|  |         public int Level { get; set; } | ||||||
|  |         public string ParentTypeId { get; set; } = null!; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,7 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.TagType | ||||||
|  | { | ||||||
|  |     public class GetAllTagTypesByListRequest | ||||||
|  |     { | ||||||
|  |         public string[] TagTypes { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,6 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.TagType | ||||||
|  | { | ||||||
|  |     public class GetAllTagTypesRequest | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,7 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.TagType | ||||||
|  | { | ||||||
|  |     public class GetTagTypeRequest | ||||||
|  |     { | ||||||
|  |         public string Id { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,14 @@ | |||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.TagType | ||||||
|  | { | ||||||
|  |     public class UpdateTagTypeRequest | ||||||
|  |     { | ||||||
|  |         public string Id { get; set; } = null!; | ||||||
|  |         public string TenantId { get; set; } = null!; | ||||||
|  |         public string TypeName { get; set; } = null!; | ||||||
|  |         public int Level { get; set; } | ||||||
|  |         public string ParentTypeId { get; set; } = null!; | ||||||
|  |         public StatusEnum Status { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,10 @@ | |||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Variant | ||||||
|  | { | ||||||
|  |     public class ChangeFurnitureVariantStatusRequest | ||||||
|  |     { | ||||||
|  |         public string MongoId { get; set; } = default!; | ||||||
|  |         public StatusEnum Status { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,19 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Variant | ||||||
|  | { | ||||||
|  |     public class CreateFurnitureVariantRequest | ||||||
|  |     { | ||||||
|  |         public string ModelId { get; set; } = default!; | ||||||
|  |         public string Name { get; set; } = default!; | ||||||
|  |         public string Color { get; set; } = default!; | ||||||
|  |         public string? Line { get; set; } | ||||||
|  |  | ||||||
|  |         public decimal Price { get; set; } | ||||||
|  |         public string Currency { get; set; } = "USD"; | ||||||
|  |         public int Stock { get; set; } | ||||||
|  |  | ||||||
|  |         public string CategoryId { get; set; } = string.Empty; | ||||||
|  |         public string ProviderId { get; set; } = string.Empty; | ||||||
|  |  | ||||||
|  |         public Dictionary<string, string> Attributes { get; set; } = []; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,6 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Variant | ||||||
|  | { | ||||||
|  |     public class GetAllFurnitureVariantRequest | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,7 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Variant | ||||||
|  | { | ||||||
|  |     public class GetAllFurnitureVariantsByModelIdRequest | ||||||
|  |     { | ||||||
|  |         public string ModelId { get; set; } = default!; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,7 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Variant | ||||||
|  | { | ||||||
|  |     public class GetFurnitureVariantByIdRequest | ||||||
|  |     { | ||||||
|  |         public string MongoId { get; set; } = default!; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,7 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Variant | ||||||
|  | { | ||||||
|  |     public class GetFurnitureVariantsByIdsRequest | ||||||
|  |     { | ||||||
|  |         public List<string> Ids { get; set; } = []; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,21 @@ | |||||||
|  | namespace Core.Inventory.External.Clients.Inventory.Requests.Variant | ||||||
|  | { | ||||||
|  |     public class UpdateFurnitureVariantRequest | ||||||
|  |     { | ||||||
|  |         public string _Id { get; set; } = default!; | ||||||
|  |         public string Id { get; set; } = default!; | ||||||
|  |         public string ModelId { get; set; } = default!; | ||||||
|  |         public string Name { get; set; } = default!; | ||||||
|  |         public string Color { get; set; } = default!; | ||||||
|  |         public string? Line { get; set; } | ||||||
|  |  | ||||||
|  |         public int Stock { get; set; } | ||||||
|  |         public decimal Price { get; set; } | ||||||
|  |         public string Currency { get; set; } = "USD"; | ||||||
|  |  | ||||||
|  |         public string CategoryId { get; set; } = string.Empty; | ||||||
|  |         public string ProviderId { get; set; } = string.Empty; | ||||||
|  |  | ||||||
|  |         public Dictionary<string, string> Attributes { get; set; } = new(); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										15
									
								
								Core.Inventory.External/Core.Inventory.External.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								Core.Inventory.External/Core.Inventory.External.csproj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | |||||||
|  | <Project Sdk="Microsoft.NET.Sdk"> | ||||||
|  |  | ||||||
|  |   <PropertyGroup> | ||||||
|  |     <TargetFramework>net8.0</TargetFramework> | ||||||
|  |     <ImplicitUsings>enable</ImplicitUsings> | ||||||
|  |     <Nullable>enable</Nullable> | ||||||
|  |   </PropertyGroup> | ||||||
|  |  | ||||||
|  |   <ItemGroup> | ||||||
|  |     <PackageReference Include="Adapters.Lib" Version="1.0.10" /> | ||||||
|  |     <PackageReference Include="BuildingBlocks.Library" Version="1.0.0" /> | ||||||
|  |     <PackageReference Include="Refit" Version="8.0.0" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |  | ||||||
|  | </Project> | ||||||
| @@ -0,0 +1,19 @@ | |||||||
|  | using Core.Blueprint.External; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.External.GatewayConfigurations | ||||||
|  | { | ||||||
|  |     public record GatewayConfiguration | ||||||
|  |     { | ||||||
|  |         public GatewayConfiguration() | ||||||
|  |         { | ||||||
|  |             InventoryService = new InventoryServiceAPI(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public InventoryServiceAPI InventoryService { get; set; } | ||||||
|  |     } | ||||||
|  |     public record InventoryServiceAPI | ||||||
|  |     { | ||||||
|  |         public string Channel { get; set; } | ||||||
|  |         public BaseEndpoint Endpoint { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,48 @@ | |||||||
|  | using Core.Blueprint.External; | ||||||
|  | using Microsoft.Extensions.Configuration; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.External.GatewayConfigurations | ||||||
|  | { | ||||||
|  |     public class GatewaySettingsConfigurations | ||||||
|  |     { | ||||||
|  |         private static GatewayConfiguration GatewayConfigurations { get; set; } = new GatewayConfiguration(); | ||||||
|  |         private readonly IConfiguration _configuration; | ||||||
|  |  | ||||||
|  |         public GatewaySettingsConfigurations(IConfiguration configuration) | ||||||
|  |         { | ||||||
|  |             _configuration = configuration; | ||||||
|  |             SetDashboardServiceAPIEndpoint(); | ||||||
|  |         } | ||||||
|  |         public static InventoryServiceAPI GetInventoryServiceAPIEndpoint() | ||||||
|  |         { | ||||||
|  |             return GatewayConfigurations.InventoryService; | ||||||
|  |         } | ||||||
|  |         private GatewayConfiguration SetDashboardServiceAPIEndpoint() | ||||||
|  |         { | ||||||
|  |             IConfigurationSection source; | ||||||
|  |             var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? string.Empty; | ||||||
|  |  | ||||||
|  |             if (environment == "Local") | ||||||
|  |                 source = _configuration.GetSection("LocalGateways"); | ||||||
|  |             else | ||||||
|  |                 source = _configuration.GetSection("Gateways"); | ||||||
|  |  | ||||||
|  |             var endpoint = source["InventoryService"] ?? string.Empty; | ||||||
|  |  | ||||||
|  |             if (string.IsNullOrEmpty(endpoint)) throw new Exception("Inventory Service endpoint is empty or null"); | ||||||
|  |  | ||||||
|  |             GatewayConfigurations.InventoryService = new InventoryServiceAPI() | ||||||
|  |             { | ||||||
|  |                 Endpoint = new BaseEndpoint() | ||||||
|  |                 { | ||||||
|  |                     Uri = new Uri(endpoint), | ||||||
|  |                     Url = endpoint, | ||||||
|  |                     Token = string.Empty, | ||||||
|  |                     APIName = "Inventory Service" | ||||||
|  |                 } | ||||||
|  |             }; | ||||||
|  |  | ||||||
|  |             return GatewayConfigurations; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										18
									
								
								Core.Inventory.External/TrackingMechanismExtension.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								Core.Inventory.External/TrackingMechanismExtension.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | |||||||
|  | using Microsoft.AspNetCore.Http; | ||||||
|  |  | ||||||
|  | namespace Core.Inventory.External | ||||||
|  | { | ||||||
|  |     public sealed class TrackingMechanismExtension(IHttpContextAccessor httpContextAccessor) : DelegatingHandler | ||||||
|  |     { | ||||||
|  |         private readonly IHttpContextAccessor _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor)); | ||||||
|  |  | ||||||
|  |         protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             if (_httpContextAccessor.HttpContext != null) | ||||||
|  |             { | ||||||
|  |                 request.Headers.Add("TrackingId", Guid.NewGuid().ToString()); | ||||||
|  |             } | ||||||
|  |             return await base.SendAsync(request, cancellationToken).ConfigureAwait(false); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user