diff --git a/src/Supermarket.API/Controllers/CategoriesController.cs b/src/Supermarket.API/Controllers/CategoriesController.cs index 5a470eb..63e5dbe 100644 --- a/src/Supermarket.API/Controllers/CategoriesController.cs +++ b/src/Supermarket.API/Controllers/CategoriesController.cs @@ -54,7 +54,7 @@ public async Task PostAsync([FromBody] SaveCategoryResource resou return BadRequest(new ErrorResource(result.Message)); } - var categoryResource = _mapper.Map(result.Category); + var categoryResource = _mapper.Map(result.Resource); return Ok(categoryResource); } @@ -77,7 +77,7 @@ public async Task PutAsync(int id, [FromBody] SaveCategoryResourc return BadRequest(new ErrorResource(result.Message)); } - var categoryResource = _mapper.Map(result.Category); + var categoryResource = _mapper.Map(result.Resource); return Ok(categoryResource); } @@ -98,7 +98,7 @@ public async Task DeleteAsync(int id) return BadRequest(new ErrorResource(result.Message)); } - var categoryResource = _mapper.Map(result.Category); + var categoryResource = _mapper.Map(result.Resource); return Ok(categoryResource); } } diff --git a/src/Supermarket.API/Controllers/ProductsController.cs b/src/Supermarket.API/Controllers/ProductsController.cs index 9545f71..a389208 100644 --- a/src/Supermarket.API/Controllers/ProductsController.cs +++ b/src/Supermarket.API/Controllers/ProductsController.cs @@ -56,7 +56,7 @@ public async Task PostAsync([FromBody] SaveProductResource resour return BadRequest(new ErrorResource(result.Message)); } - var productResource = _mapper.Map(result.Product); + var productResource = _mapper.Map(result.Resource); return Ok(productResource); } @@ -79,7 +79,7 @@ public async Task PutAsync(int id, [FromBody] SaveProductResource return BadRequest(new ErrorResource(result.Message)); } - var productResource = _mapper.Map(result.Product); + var productResource = _mapper.Map(result.Resource); return Ok(productResource); } @@ -100,7 +100,7 @@ public async Task DeleteAsync(int id) return BadRequest(new ErrorResource(result.Message)); } - var categoryResource = _mapper.Map(result.Product); + var categoryResource = _mapper.Map(result.Resource); return Ok(categoryResource); } } diff --git a/src/Supermarket.API/Domain/Services/Communication/BaseResponse.cs b/src/Supermarket.API/Domain/Services/Communication/BaseResponse.cs index 019f79d..71e474f 100644 --- a/src/Supermarket.API/Domain/Services/Communication/BaseResponse.cs +++ b/src/Supermarket.API/Domain/Services/Communication/BaseResponse.cs @@ -1,14 +1,23 @@ namespace Supermarket.API.Domain.Services.Communication { - public abstract class BaseResponse + public abstract class BaseResponse { - public bool Success { get; protected set; } - public string Message { get; protected set; } + public bool Success { get; private set; } + public string Message { get; private set; } + public T Resource { get; private set; } - public BaseResponse(bool success, string message) + protected BaseResponse(T resource) { - Success = success; + Success = true; + Message = string.Empty; + Resource = resource; + } + + protected BaseResponse(string message) + { + Success = false; Message = message; + Resource = default; } } } \ No newline at end of file diff --git a/src/Supermarket.API/Domain/Services/Communication/CategoryResponse.cs b/src/Supermarket.API/Domain/Services/Communication/CategoryResponse.cs index e03fd99..78a607c 100644 --- a/src/Supermarket.API/Domain/Services/Communication/CategoryResponse.cs +++ b/src/Supermarket.API/Domain/Services/Communication/CategoryResponse.cs @@ -2,21 +2,14 @@ namespace Supermarket.API.Domain.Services.Communication { - public class CategoryResponse : BaseResponse + public class CategoryResponse : BaseResponse { - public Category Category { get; private set; } - - private CategoryResponse(bool success, string message, Category category) : base(success, message) - { - Category = category; - } - /// /// Creates a success response. /// /// Saved category. /// Response. - public CategoryResponse(Category category) : this(true, string.Empty, category) + public CategoryResponse(Category category) : base(category) { } /// @@ -24,7 +17,7 @@ public CategoryResponse(Category category) : this(true, string.Empty, category) /// /// Error message. /// Response. - public CategoryResponse(string message) : this(false, message, null) + public CategoryResponse(string message) : base(message) { } } } \ No newline at end of file diff --git a/src/Supermarket.API/Domain/Services/Communication/ProductResponse.cs b/src/Supermarket.API/Domain/Services/Communication/ProductResponse.cs index c787029..011b76c 100644 --- a/src/Supermarket.API/Domain/Services/Communication/ProductResponse.cs +++ b/src/Supermarket.API/Domain/Services/Communication/ProductResponse.cs @@ -2,17 +2,10 @@ namespace Supermarket.API.Domain.Services.Communication { - public class ProductResponse : BaseResponse + public class ProductResponse : BaseResponse { - public Product Product { get; private set; } + public ProductResponse(Product product) : base(product) { } - private ProductResponse(bool success, string message, Product product) : base(success, message) - { - Product = product; - } - - public ProductResponse(Product product) : this(true, string.Empty, product) { } - - public ProductResponse(string message) : this(false, message, null) { } + public ProductResponse(string message) : base(message) { } } } \ No newline at end of file