diff --git a/src/Modules/Grand.Module.Api/Attributes/EnableQueryAttribute.cs b/src/Modules/Grand.Module.Api/Attributes/EnableQueryAttribute.cs index c8dedce7a..b77a19ca6 100644 --- a/src/Modules/Grand.Module.Api/Attributes/EnableQueryAttribute.cs +++ b/src/Modules/Grand.Module.Api/Attributes/EnableQueryAttribute.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc; using System.Linq.Dynamic.Core; using Microsoft.AspNetCore.Http; +using Grand.Module.Api.Constants; namespace Grand.Module.Api.Attributes; @@ -35,13 +36,12 @@ private IQueryable ApplyQueryOptions(IQueryable queryable, IQueryCollection quer queryable = queryable.Skip(skip); if (query.TryGetValue("$top", out var topValue) && int.TryParse(topValue, out var top)) - queryable = queryable.Take(top); - - if (query.TryGetValue("$count", out var countValue) && bool.TryParse(countValue, out var includeCount) && includeCount) { - var totalCount = queryable.Count(); - response?.Headers?.Append("X-Total-Count", totalCount.ToString()); + top = Math.Min(top, Configurations.MaxLimit); + queryable = queryable.Take(top); } + else + queryable = queryable.Take(Configurations.MaxLimit); return queryable; } diff --git a/src/Modules/Grand.Module.Api/Controllers/BaseApiController.cs b/src/Modules/Grand.Module.Api/Controllers/BaseApiController.cs index 17cded136..2816e836b 100644 --- a/src/Modules/Grand.Module.Api/Controllers/BaseApiController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/BaseApiController.cs @@ -1,4 +1,5 @@ using Grand.Module.Api.Attributes; +using Grand.Module.Api.Constants; using Grand.Module.Api.Filters; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; @@ -9,6 +10,8 @@ namespace Grand.Module.Api.Controllers; [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] [AuthorizeApiAdmin] [ServiceFilter(typeof(ModelValidationAttribute))] +[Route($"{Configurations.RestRoutePrefix}/[controller]")] +[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] [Produces("application/json")] public abstract class BaseApiController : ControllerBase { diff --git a/src/Modules/Grand.Module.Api/Controllers/BrandController.cs b/src/Modules/Grand.Module.Api/Controllers/BrandController.cs index a7cc1f688..2f1850d99 100644 --- a/src/Modules/Grand.Module.Api/Controllers/BrandController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/BrandController.cs @@ -9,14 +9,11 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; -using Grand.Module.Api.Constants; using Microsoft.AspNetCore.Http; using Grand.Module.Api.Attributes; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/Brand")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class BrandController : BaseApiController { private readonly IMediator _mediator; @@ -44,7 +41,7 @@ public async Task Get() [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BrandDto))] public async Task GetById([FromRoute] string key) { if (!await _permissionService.Authorize(PermissionSystemName.Brands)) return Forbid(); @@ -58,7 +55,7 @@ public async Task GetById([FromRoute] string key) [SwaggerOperation("Add new entity to Brand", OperationId = "InsertBrand")] [HttpPost] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BrandDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] public async Task Post([FromBody] BrandDto model) { @@ -71,7 +68,7 @@ public async Task Post([FromBody] BrandDto model) [SwaggerOperation("Update entity in Brand", OperationId = "UpdateBrand")] [HttpPut("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BrandDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Put([FromRoute] string key, [FromBody] BrandDto model) diff --git a/src/Modules/Grand.Module.Api/Controllers/BrandLayoutController.cs b/src/Modules/Grand.Module.Api/Controllers/BrandLayoutController.cs index 5179dc856..54e4e9b70 100644 --- a/src/Modules/Grand.Module.Api/Controllers/BrandLayoutController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/BrandLayoutController.cs @@ -7,13 +7,11 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; -using Grand.Module.Api.Constants; using Grand.Module.Api.Attributes; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/BrandLayout")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class BrandLayoutController : BaseApiController { private readonly IMediator _mediator; @@ -28,9 +26,9 @@ public BrandLayoutController(IMediator mediator, IPermissionService permissionSe [SwaggerOperation("Get entity from BrandLayout by key", OperationId = "GetBrandLayoutById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(LayoutDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Get(string key) + public async Task Get([FromRoute] string key) { if (!await _permissionService.Authorize(PermissionSystemName.Maintenance)) return Forbid(); @@ -44,7 +42,7 @@ public async Task Get(string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.Maintenance)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/CategoryController.cs b/src/Modules/Grand.Module.Api/Controllers/CategoryController.cs index 736c336bb..239a549a7 100644 --- a/src/Modules/Grand.Module.Api/Controllers/CategoryController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/CategoryController.cs @@ -9,13 +9,11 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; -using Grand.Module.Api.Constants; using Grand.Module.Api.Attributes; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/Category")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class CategoryController : BaseApiController { private readonly IMediator _mediator; @@ -32,7 +30,7 @@ public CategoryController( [SwaggerOperation("Get entity from Category by key", OperationId = "GetCategoryById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CategoryDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -48,7 +46,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.Categories)) return Forbid(); @@ -59,7 +57,7 @@ public async Task Get() [SwaggerOperation("Add new entity to Category", OperationId = "InsertCategory")] [HttpPost] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CategoryDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] public async Task Post([FromBody] CategoryDto model) { @@ -70,16 +68,16 @@ public async Task Post([FromBody] CategoryDto model) } [SwaggerOperation("Update entity in Category", OperationId = "UpdateCategory")] - [HttpPut] + [HttpPut("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CategoryDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Put([FromBody] CategoryDto model) + public async Task Put([FromRoute] string key, [FromBody] CategoryDto model) { if (!await _permissionService.Authorize(PermissionSystemName.Categories)) return Forbid(); - var category = await _mediator.Send(new GetGenericQuery(model.Id)); + var category = await _mediator.Send(new GetGenericQuery(key)); if (!category.Any()) return NotFound(); model = await _mediator.Send(new UpdateCategoryCommand { Model = model }); @@ -109,11 +107,11 @@ public async Task Patch([FromRoute] string key, [FromBody] JsonPa } [SwaggerOperation("Delete entity from Category", OperationId = "DeleteCategory")] - [HttpDelete] + [HttpDelete("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Delete(string key) + public async Task Delete([FromRoute] string key) { if (!await _permissionService.Authorize(PermissionSystemName.Categories)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/CategoryLayoutController.cs b/src/Modules/Grand.Module.Api/Controllers/CategoryLayoutController.cs index 951b557f0..caaa837f5 100644 --- a/src/Modules/Grand.Module.Api/Controllers/CategoryLayoutController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/CategoryLayoutController.cs @@ -7,13 +7,11 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; -using Grand.Module.Api.Constants; using Grand.Module.Api.Attributes; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/CategoryLayout")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class CategoryLayoutController : BaseApiController { private readonly IMediator _mediator; @@ -30,7 +28,7 @@ public CategoryLayoutController( [SwaggerOperation("Get entity from CategoryLayout by key", OperationId = "GetCategoryLayoutById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(LayoutDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -46,7 +44,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.Maintenance)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/CollectionController.cs b/src/Modules/Grand.Module.Api/Controllers/CollectionController.cs index b108b62fb..9533c8856 100644 --- a/src/Modules/Grand.Module.Api/Controllers/CollectionController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/CollectionController.cs @@ -2,7 +2,6 @@ using Grand.Domain.Catalog; using Grand.Domain.Permissions; using Grand.Module.Api.Commands.Models.Catalog; -using Grand.Module.Api.Constants; using Grand.Module.Api.DTOs.Catalog; using Grand.Module.Api.Attributes; using Grand.Module.Api.Queries.Models.Common; @@ -11,11 +10,10 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/Collection")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class CollectionController : BaseApiController { private readonly IMediator _mediator; @@ -30,7 +28,7 @@ public CollectionController(IMediator mediator, IPermissionService permissionSer [SwaggerOperation("Get entity from Collection by key", OperationId = "GetCollectionById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CollectionDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -46,7 +44,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.Collections)) return Forbid(); @@ -57,7 +55,7 @@ public async Task Get() [SwaggerOperation("Add new entity to Collection", OperationId = "InsertCollection")] [HttpPost] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CollectionDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] public async Task Post([FromBody] CollectionDto model) { @@ -68,16 +66,16 @@ public async Task Post([FromBody] CollectionDto model) } [SwaggerOperation("Update entity in Collection", OperationId = "UpdateCollection")] - [HttpPut] + [HttpPut("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CollectionDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Put([FromBody] CollectionDto model) + public async Task Put([FromRoute] string key, [FromBody] CollectionDto model) { if (!await _permissionService.Authorize(PermissionSystemName.Collections)) return Forbid(); - var collection = await _mediator.Send(new GetGenericQuery(model.Id)); + var collection = await _mediator.Send(new GetGenericQuery(key)); if (!collection.Any()) return NotFound(); model = await _mediator.Send(new UpdateCollectionCommand { Model = model }); @@ -107,11 +105,11 @@ public async Task Patch([FromRoute] string key, [FromBody] JsonPa } [SwaggerOperation("Delete entity in Collection", OperationId = "DeleteCollection")] - [HttpDelete] + [HttpDelete("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Delete(string key) + public async Task Delete([FromRoute] string key) { if (!await _permissionService.Authorize(PermissionSystemName.Collections)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/CollectionLayoutController.cs b/src/Modules/Grand.Module.Api/Controllers/CollectionLayoutController.cs index 436c7f9d6..47c6cb456 100644 --- a/src/Modules/Grand.Module.Api/Controllers/CollectionLayoutController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/CollectionLayoutController.cs @@ -7,13 +7,11 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; -using Grand.Module.Api.Constants; using Grand.Module.Api.Attributes; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/CollectionLayout")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class CollectionLayoutController : BaseApiController { private readonly IMediator _mediator; @@ -28,7 +26,7 @@ public CollectionLayoutController(IMediator mediator, IPermissionService permiss [SwaggerOperation("Get entity from CollectionLayout by key", OperationId = "GetCollectionLayoutById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(LayoutDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -44,7 +42,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.Maintenance)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/CountryController.cs b/src/Modules/Grand.Module.Api/Controllers/CountryController.cs index b3fbce89c..87a30b395 100644 --- a/src/Modules/Grand.Module.Api/Controllers/CountryController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/CountryController.cs @@ -7,13 +7,11 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; -using Grand.Module.Api.Constants; using Grand.Module.Api.Attributes; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/Country")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class CountryController : BaseApiController { private readonly IMediator _mediator; @@ -28,7 +26,7 @@ public CountryController(IMediator mediator, IPermissionService permissionServic [SwaggerOperation("Get entity from Country by key", OperationId = "GetCountryById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CountryDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -45,7 +43,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.Countries)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/CurrencyController.cs b/src/Modules/Grand.Module.Api/Controllers/CurrencyController.cs index 2e348a400..466239f77 100644 --- a/src/Modules/Grand.Module.Api/Controllers/CurrencyController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/CurrencyController.cs @@ -7,13 +7,11 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; -using Grand.Module.Api.Constants; using Grand.Module.Api.Attributes; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/Currency")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class CurrencyController : BaseApiController { private readonly IMediator _mediator; @@ -28,7 +26,7 @@ public CurrencyController(IMediator mediator, IPermissionService permissionServi [SwaggerOperation("Get entity from Currency by key", OperationId = "GetCurrencyById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CurrencyDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -44,7 +42,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.Currencies)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/CustomerController.cs b/src/Modules/Grand.Module.Api/Controllers/CustomerController.cs index d00ddaa82..1804991ee 100644 --- a/src/Modules/Grand.Module.Api/Controllers/CustomerController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/CustomerController.cs @@ -10,12 +10,10 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; -using Grand.Module.Api.Constants; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/Customer")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class CustomerController : BaseApiController { private readonly ICustomerManagerService _customerManagerService; @@ -39,7 +37,7 @@ public CustomerController( [SwaggerOperation("Get entity from Customer by email", OperationId = "GetCustomerByEmail")] [HttpGet] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CustomerDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string email) { @@ -54,7 +52,7 @@ public async Task Get([FromRoute] string email) [SwaggerOperation("Add new entity to Customer", OperationId = "InsertCustomer")] [HttpPost] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CustomerDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] public async Task Post([FromBody] CustomerDto model) { @@ -65,20 +63,24 @@ public async Task Post([FromBody] CustomerDto model) } [SwaggerOperation("Update entity in Customer", OperationId = "UpdateCustomer")] - [HttpPut] + [HttpPut("{email}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CustomerDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] - public async Task Put([FromBody] CustomerDto model) + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task Put([FromRoute] string email, [FromBody] CustomerDto model) { if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid(); + var customer = await _mediator.Send(new GetCustomerQuery { Email = email }); + if (customer == null) return NotFound(); + model = await _mediator.Send(new UpdateCustomerCommand { Model = model }); return Ok(model); } [SwaggerOperation("Delete entity from Customer", OperationId = "DeleteCustomer")] - [HttpDelete] + [HttpDelete("{email}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NotFound)] @@ -96,9 +98,9 @@ public async Task Delete([FromRoute] string email) //api/Customer/email/AddAddress [SwaggerOperation("Invoke action AddAddress", OperationId = "AddAddress")] - [HttpPost("/{email}/AddAddress")] + [HttpPost("{email}/AddAddress")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(AddressDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task AddAddress([FromRoute] string email, [FromBody] AddressDto address) @@ -114,9 +116,9 @@ public async Task AddAddress([FromRoute] string email, [FromBody] //api/Customer/email/UpdateAddress [SwaggerOperation("Invoke action UpdateAddress", OperationId = "UpdateAddress")] - [HttpPost("/{email}/UpdateAddress")] + [HttpPost("{email}/UpdateAddress")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(AddressDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task UpdateAddress([FromRoute] string email, [FromBody] AddressDto address) @@ -134,7 +136,7 @@ public async Task UpdateAddress([FromRoute] string email, [FromBo //api/Customer/email/DeleteAddress //body: { "addressId": "xxx" } [SwaggerOperation("Invoke action DeleteAddress", OperationId = "DeleteAddress")] - [HttpPost("/{email}/DeleteAddress")] + [HttpPost("{email}/DeleteAddress")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NotFound)] @@ -158,7 +160,7 @@ public async Task DeleteAddress([FromRoute] string email, [FromBo //api/Customer/email/SetPassword //body: { "password": "123456" } [SwaggerOperation("Invoke action SetPassword", OperationId = "SetPassword")] - [HttpPost("/{email}/SetPassword")] + [HttpPost("{email}/SetPassword")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] @@ -169,8 +171,7 @@ public async Task SetPassword([FromRoute] string email, [FromBody if (model == null || string.IsNullOrEmpty(model.Password)) return NotFound(); - var changePassRequest = - new ChangePasswordRequest(email, _customerSettings.DefaultPasswordFormat, model.Password); + var changePassRequest = new ChangePasswordRequest(email, _customerSettings.DefaultPasswordFormat, model.Password); await _customerManagerService.ChangePassword(changePassRequest); return Ok(true); diff --git a/src/Modules/Grand.Module.Api/Controllers/CustomerGroupController.cs b/src/Modules/Grand.Module.Api/Controllers/CustomerGroupController.cs index 0aa32c268..9b5d8f830 100644 --- a/src/Modules/Grand.Module.Api/Controllers/CustomerGroupController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/CustomerGroupController.cs @@ -11,11 +11,11 @@ using System.Net; using Grand.Module.Api.Constants; using Grand.Module.Api.Attributes; +using Grand.Module.Api.DTOs.Common; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/CustomerGroup")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class CustomerGroupController : BaseApiController { private readonly IMediator _mediator; @@ -30,7 +30,7 @@ public CustomerGroupController(IMediator mediator, IPermissionService permission [SwaggerOperation("Get entity from CustomerGroup by key", OperationId = "GetCustomerGroupById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CustomerGroupDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -46,7 +46,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid(); @@ -57,7 +57,7 @@ public async Task Get() [SwaggerOperation("Add new entity to CustomerGroup", OperationId = "InsertCustomerGroup")] [HttpPost] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CustomerGroupDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] public async Task Post([FromBody] CustomerGroupDto model) { @@ -68,16 +68,16 @@ public async Task Post([FromBody] CustomerGroupDto model) } [SwaggerOperation("Update entity in CustomerGroup", OperationId = "UpdateCustomerGroup")] - [HttpPut] + [HttpPut("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(CustomerGroupDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Put([FromBody] CustomerGroupDto model) + public async Task Put([FromRoute] string key, [FromBody] CustomerGroupDto model) { if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid(); - var customerGroup = await _mediator.Send(new GetGenericQuery(model.Id)); + var customerGroup = await _mediator.Send(new GetGenericQuery(key)); if (!customerGroup.Any()) return NotFound(); if (!model.IsSystem) @@ -117,11 +117,11 @@ public async Task Patch([FromRoute] string key, [FromBody] JsonPa } [SwaggerOperation("Delete entity in CustomerGroup", OperationId = "DeleteCustomerGroup")] - [HttpDelete] + [HttpDelete("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Delete(string key) + public async Task Delete([FromRoute] string key) { if (!await _permissionService.Authorize(PermissionSystemName.Customers)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/DeliveryDateController.cs b/src/Modules/Grand.Module.Api/Controllers/DeliveryDateController.cs index 0a97df707..0b02efe27 100644 --- a/src/Modules/Grand.Module.Api/Controllers/DeliveryDateController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/DeliveryDateController.cs @@ -7,13 +7,11 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; -using Grand.Module.Api.Constants; using Grand.Module.Api.Attributes; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/DeliveryDate")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class DeliveryDateController : BaseApiController { private readonly IMediator _mediator; @@ -28,7 +26,7 @@ public DeliveryDateController(IMediator mediator, IPermissionService permissionS [SwaggerOperation("Get entity from Delivery Date by key", OperationId = "GetDeliveryDateById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(DeliveryDateDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -44,7 +42,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.ShippingSettings)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/LanguageController.cs b/src/Modules/Grand.Module.Api/Controllers/LanguageController.cs index 777f9e1ec..f82367a32 100644 --- a/src/Modules/Grand.Module.Api/Controllers/LanguageController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/LanguageController.cs @@ -7,13 +7,11 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; -using Grand.Module.Api.Constants; using Grand.Module.Api.Attributes; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/Language")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class LanguageController : BaseApiController { private readonly IMediator _mediator; @@ -28,7 +26,7 @@ public LanguageController(IMediator mediator, IPermissionService permissionServi [SwaggerOperation("Get entity from Languages by key", OperationId = "GetLanguageById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(LanguageDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -44,7 +42,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.Languages)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/PickupPointController.cs b/src/Modules/Grand.Module.Api/Controllers/PickupPointController.cs index f79276a69..dbad9b7e4 100644 --- a/src/Modules/Grand.Module.Api/Controllers/PickupPointController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/PickupPointController.cs @@ -7,13 +7,11 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; -using Grand.Module.Api.Constants; using Grand.Module.Api.Attributes; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/PickupPoint")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class PickupPointController : BaseApiController { private readonly IMediator _mediator; @@ -28,7 +26,7 @@ public PickupPointController(IMediator mediator, IPermissionService permissionSe [SwaggerOperation("Get entity from PickupPoint by key", OperationId = "GetPickupPointById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(PickupPointDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -44,7 +42,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.ShippingSettings)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/PictureController.cs b/src/Modules/Grand.Module.Api/Controllers/PictureController.cs index d59d9a122..fef2f6f17 100644 --- a/src/Modules/Grand.Module.Api/Controllers/PictureController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/PictureController.cs @@ -8,12 +8,10 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; -using Grand.Module.Api.Constants; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/Picture")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class PictureController : BaseApiController { private readonly IMediator _mediator; @@ -28,7 +26,7 @@ public PictureController(IMediator mediator, IPermissionService permissionServic [SwaggerOperation("Get entities from Picture by key", OperationId = "GetPictureById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(PictureDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -54,16 +52,16 @@ public async Task Post([FromBody] PictureDto model) } [SwaggerOperation("Update entity in Picture", OperationId = "UpdatePicture")] - [HttpPut] + [HttpPut("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Put([FromBody] PictureDto model) + public async Task Put([FromRoute] string key, [FromBody] PictureDto model) { - if (!await _permissionService.Authorize(PermissionSystemName.Categories)) return Forbid(); + if (!await _permissionService.Authorize(PermissionSystemName.Pictures)) return Forbid(); - var picture = await _mediator.Send(new GetGenericQuery(model.Id)); + var picture = await _mediator.Send(new GetGenericQuery(key)); if (picture == null || !picture.Any()) return NotFound(); var result = await _mediator.Send(new UpdatePictureCommand { Model = model }); @@ -71,11 +69,11 @@ public async Task Put([FromBody] PictureDto model) } [SwaggerOperation("Delete entity in Picture", OperationId = "DeletePicture")] - [HttpDelete] + [HttpDelete("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Delete(string key) + public async Task Delete([FromRoute] string key) { if (!await _permissionService.Authorize(PermissionSystemName.Pictures)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/ProductAttributeController.cs b/src/Modules/Grand.Module.Api/Controllers/ProductAttributeController.cs index 6ef967717..e227a28d2 100644 --- a/src/Modules/Grand.Module.Api/Controllers/ProductAttributeController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/ProductAttributeController.cs @@ -11,11 +11,12 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; +using Grand.Module.Api.DTOs.Shipping; +using Microsoft.AspNetCore.Http; +using Grand.Module.Api.DTOs.Common; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/ProductAttribute")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class ProductAttributeController : BaseApiController { private readonly IMediator _mediator; @@ -32,7 +33,7 @@ public ProductAttributeController( [SwaggerOperation("Get entity from ProductAttribute by key", OperationId = "GetProductAttributeById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ProductAttributeDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -48,7 +49,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.ProductAttributes)) return Forbid(); @@ -59,7 +60,7 @@ public async Task Get() [SwaggerOperation("Add new entity to ProductAttribute", OperationId = "InsertProductAttribute")] [HttpPost] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ProductAttributeDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] public async Task Post([FromBody] ProductAttributeDto model) { @@ -70,14 +71,18 @@ public async Task Post([FromBody] ProductAttributeDto model) } [SwaggerOperation("Update entity in ProductAttribute", OperationId = "UpdateProductAttribute")] - [HttpPut] + [HttpPut("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ProductAttributeDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] - public async Task Put([FromBody] ProductAttributeDto model) + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task Put([FromRoute] string key, [FromBody] ProductAttributeDto model) { if (!await _permissionService.Authorize(PermissionSystemName.ProductAttributes)) return Forbid(); + var productAttribute = await _mediator.Send(new GetGenericQuery(key)); + if (!productAttribute.Any()) return NotFound(); + model = await _mediator.Send(new UpdateProductAttributeCommand { Model = model }); return Ok(model); } @@ -85,11 +90,10 @@ public async Task Put([FromBody] ProductAttributeDto model) [SwaggerOperation("Partially update entity in ProductAttribute", OperationId = "PartiallyUpdateProductAttribute")] [HttpPatch("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ProductAttributeDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Patch([FromRoute] string key, - [FromBody] JsonPatchDocument model) + public async Task Patch([FromRoute] string key, [FromBody] JsonPatchDocument model) { if (string.IsNullOrEmpty(key)) return BadRequest("Key is null or empty"); @@ -106,11 +110,11 @@ public async Task Patch([FromRoute] string key, } [SwaggerOperation("Delete entity from ProductAttribute", OperationId = "DeleteProductAttribute")] - [HttpDelete] + [HttpDelete("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Delete(string key) + public async Task Delete([FromRoute] string key) { if (!await _permissionService.Authorize(PermissionSystemName.ProductAttributes)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/ProductController.cs b/src/Modules/Grand.Module.Api/Controllers/ProductController.cs index 13ccb86e7..9cf781e72 100644 --- a/src/Modules/Grand.Module.Api/Controllers/ProductController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/ProductController.cs @@ -11,11 +11,12 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; +using Grand.Module.Api.DTOs.Shipping; +using Microsoft.AspNetCore.Http; +using Grand.Module.Api.DTOs.Common; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/Product")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class ProductController : BaseApiController { private readonly IMediator _mediator; @@ -32,7 +33,7 @@ public ProductController( [SwaggerOperation("Get entity from Product by key", OperationId = "GetProductById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ProductDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -48,7 +49,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -59,7 +60,7 @@ public async Task Get() [SwaggerOperation("Add new entity to Product", OperationId = "InsertProduct")] [HttpPost] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ProductDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] public async Task Post([FromBody] ProductDto model) { @@ -70,20 +71,24 @@ public async Task Post([FromBody] ProductDto model) } [SwaggerOperation("Update entity in Product", OperationId = "UpdateProduct")] - [HttpPut] + [HttpPut("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ProductDto))] + [ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] - public async Task Put([FromBody] ProductDto model) + public async Task Put([FromRoute] string key, [FromBody] ProductDto model) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); + var product = await _mediator.Send(new GetGenericQuery(key)); + if (!product.Any()) return NotFound(); + await _mediator.Send(new UpdateProductCommand { Model = model }); return Ok(); } [SwaggerOperation("Partially update entity in Product", OperationId = "PartiallyUpdateProduct")] - [HttpPatch] + [HttpPatch("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] @@ -105,7 +110,7 @@ public async Task Patch([FromRoute] string key, [FromBody] JsonPa } [SwaggerOperation("Delete entity in Product", OperationId = "DeleteProduct")] - [HttpDelete] + [HttpDelete("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NotFound)] @@ -124,7 +129,7 @@ public async Task Delete([FromRoute] string key) //api/Product/id/UpdateStock //body: { "WarehouseId": "", "Stock": 10 } [SwaggerOperation("Invoke action UpdateStock", OperationId = "UpdateStock")] - [HttpPost("/{key}/UpdateStock")] + [HttpPost("{key}/UpdateStock")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] @@ -146,13 +151,12 @@ public async Task UpdateStock([FromRoute] string key, [FromBody] #region Product category [SwaggerOperation("Invoke action CreateProductCategory", OperationId = "CreateProductCategory")] - [HttpPost("/{key}/CreateProductCategory")] + [HttpPost("{key}/CreateProductCategory")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task CreateProductCategory([FromRoute] string key, - [FromBody] ProductCategoryDto productCategory) + public async Task CreateProductCategory([FromRoute] string key, [FromBody] ProductCategoryDto productCategory) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -175,13 +179,12 @@ public async Task CreateProductCategory([FromRoute] string key, } [SwaggerOperation("Invoke action UpdateProductCategory", OperationId = "UpdateProductCategory")] - [HttpPost("/{key}/UpdateProductCategory")] + [HttpPost("{key}/UpdateProductCategory")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task UpdateProductCategory([FromRoute] string key, - [FromBody] ProductCategoryDto productCategory) + public async Task UpdateProductCategory([FromRoute] string key, [FromBody] ProductCategoryDto productCategory) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -204,13 +207,12 @@ public async Task UpdateProductCategory([FromRoute] string key, } [SwaggerOperation("Invoke action DeleteProductCategory", OperationId = "DeleteProductCategory")] - [HttpPost("/{key}/DeleteProductCategory")] + [HttpPost("{key}/DeleteProductCategory")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task DeleteProductCategory([FromRoute] string key, - [FromBody] ProductCategoryDeleteDto model) + public async Task DeleteProductCategory([FromRoute] string key, [FromBody] ProductCategoryDeleteDto model) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -242,13 +244,12 @@ public async Task DeleteProductCategory([FromRoute] string key, #region Product collection [SwaggerOperation("Invoke action CreateProductCollection", OperationId = "CreateProductCollection")] - [HttpPost("/{key}/CreateProductCollection")] + [HttpPost("{key}/CreateProductCollection")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task CreateProductCollection([FromRoute] string key, - [FromBody] ProductCollectionDto productCollection) + public async Task CreateProductCollection([FromRoute] string key, [FromBody] ProductCollectionDto productCollection) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -257,8 +258,7 @@ public async Task CreateProductCollection([FromRoute] string key, var product = await _mediator.Send(new GetGenericQuery(key)); if (!product.Any()) return NotFound(); - var pm = product.FirstOrDefault()!.ProductCollections.FirstOrDefault(x => - x.CollectionId == productCollection.CollectionId); + var pm = product.FirstOrDefault()!.ProductCollections.FirstOrDefault(x => x.CollectionId == productCollection.CollectionId); if (pm != null) return BadRequest("Product collection mapping found with the specified CollectionId"); if (ModelState.IsValid) @@ -271,13 +271,12 @@ public async Task CreateProductCollection([FromRoute] string key, } [SwaggerOperation("Invoke action UpdateProductCollection", OperationId = "UpdateProductCollection")] - [HttpPost("/{key}/UpdateProductCollection")] + [HttpPost("{key}/UpdateProductCollection")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task UpdateProductCollection([FromRoute] string key, - [FromBody] ProductCollectionDto productCollection) + public async Task UpdateProductCollection([FromRoute] string key, [FromBody] ProductCollectionDto productCollection) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -300,13 +299,12 @@ public async Task UpdateProductCollection([FromRoute] string key, } [SwaggerOperation("Invoke action DeleteProductCollection", OperationId = "DeleteProductCollection")] - [HttpPost("/{key}/DeleteProductCollection")] + [HttpPost("{key}/DeleteProductCollection")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task DeleteProductCollection([FromRoute] string key, - [FromBody] ProductCollectionDeleteDto model) + public async Task DeleteProductCollection([FromRoute] string key, [FromBody] ProductCollectionDeleteDto model) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -338,13 +336,12 @@ public async Task DeleteProductCollection([FromRoute] string key, #region Product picture [SwaggerOperation("Invoke action CreateProductPicture", OperationId = "CreateProductPicture")] - [HttpPost("/{key}/CreateProductPicture")] + [HttpPost("{key}/CreateProductPicture")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task CreateProductPicture([FromRoute] string key, - [FromBody] ProductPictureDto productPicture) + public async Task CreateProductPicture([FromRoute] string key, [FromBody] ProductPictureDto productPicture) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -366,13 +363,12 @@ public async Task CreateProductPicture([FromRoute] string key, } [SwaggerOperation("Invoke action UpdateProductPicture", OperationId = "UpdateProductPicture")] - [HttpPost("/{key}/UpdateProductPicture")] + [HttpPost("{key}/UpdateProductPicture")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task UpdateProductPicture([FromRoute] string key, - [FromBody] ProductPictureDto productPicture) + public async Task UpdateProductPicture([FromRoute] string key, [FromBody] ProductPictureDto productPicture) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -394,13 +390,12 @@ public async Task UpdateProductPicture([FromRoute] string key, } [SwaggerOperation("Invoke action DeleteProductPicture", OperationId = "DeleteProductPicture")] - [HttpPost("/{key}/DeleteProductPicture")] + [HttpPost("{key}/DeleteProductPicture")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task DeleteProductPicture([FromRoute] string key, - [FromBody] ProductPictureDeleteDto model) + public async Task DeleteProductPicture([FromRoute] string key, [FromBody] ProductPictureDeleteDto model) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -432,13 +427,12 @@ public async Task DeleteProductPicture([FromRoute] string key, #region Product specification [SwaggerOperation("Invoke action CreateProductSpecification", OperationId = "CreateProductSpecification")] - [HttpPost("/{key}/CreateProductSpecification")] + [HttpPost("{key}/CreateProductSpecification")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task CreateProductSpecification([FromRoute] string key, - [FromBody] ProductSpecificationAttributeDto productSpecification) + public async Task CreateProductSpecification([FromRoute] string key, [FromBody] ProductSpecificationAttributeDto productSpecification) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -461,13 +455,12 @@ public async Task CreateProductSpecification([FromRoute] string k } [SwaggerOperation("Invoke action UpdateProductSpecification", OperationId = "UpdateProductSpecification")] - [HttpPost("/{key}/UpdateProductSpecification")] + [HttpPost("{key}/UpdateProductSpecification")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task UpdateProductSpecification([FromRoute] string key, - [FromBody] ProductSpecificationAttributeDto productSpecification) + public async Task UpdateProductSpecification([FromRoute] string key, [FromBody] ProductSpecificationAttributeDto productSpecification) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -490,13 +483,12 @@ public async Task UpdateProductSpecification([FromRoute] string k } [SwaggerOperation("Invoke action DeleteProductSpecification", OperationId = "DeleteProductSpecification")] - [HttpPost("/{key}/DeleteProductSpecification")] + [HttpPost("{key}/DeleteProductSpecification")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task DeleteProductSpecification([FromRoute] string key, - [FromBody] ProductSpecificationAttributeDeleteDto model) + public async Task DeleteProductSpecification([FromRoute] string key, [FromBody] ProductSpecificationAttributeDeleteDto model) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -529,13 +521,12 @@ public async Task DeleteProductSpecification([FromRoute] string k #region Product tierprice [SwaggerOperation("Invoke action CreateProductTierPrice", OperationId = "CreateProductTierPrice")] - [HttpPost("/{key}/CreateProductTierPrice")] + [HttpPost("{key}/CreateProductTierPrice")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task CreateProductTierPrice([FromRoute] string key, - [FromBody] ProductTierPriceDto productTierPrice) + public async Task CreateProductTierPrice([FromRoute] string key, [FromBody] ProductTierPriceDto productTierPrice) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -557,13 +548,12 @@ public async Task CreateProductTierPrice([FromRoute] string key, } [SwaggerOperation("Invoke action UpdateProductTierPrice", OperationId = "UpdateProductTierPrice")] - [HttpPost("/{key}/UpdateProductTierPrice")] + [HttpPost("{key}/UpdateProductTierPrice")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task UpdateProductTierPrice([FromRoute] string key, - [FromBody] ProductTierPriceDto productTierPrice) + public async Task UpdateProductTierPrice([FromRoute] string key, [FromBody] ProductTierPriceDto productTierPrice) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -585,13 +575,12 @@ public async Task UpdateProductTierPrice([FromRoute] string key, } [SwaggerOperation("Invoke action DeleteProductTierPrice", OperationId = "DeleteProductTierPrice")] - [HttpPost("/{key}/DeleteProductTierPrice")] + [HttpPost("{key}/DeleteProductTierPrice")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task DeleteProductTierPrice([FromRoute] string key, - [FromBody] ProductTierPriceDeleteDto model) + public async Task DeleteProductTierPrice([FromRoute] string key, [FromBody] ProductTierPriceDeleteDto model) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -623,13 +612,12 @@ public async Task DeleteProductTierPrice([FromRoute] string key, #region Product attribute mapping [SwaggerOperation("Invoke action CreateProductAttributeMapping", OperationId = "CreateProductAttributeMapping")] - [HttpPost("/{key}/CreateProductAttributeMapping")] + [HttpPost("{key}/CreateProductAttributeMapping")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task CreateProductAttributeMapping([FromRoute] string key, - [FromBody] ProductAttributeMappingDto productAttributeMapping) + public async Task CreateProductAttributeMapping([FromRoute] string key, [FromBody] ProductAttributeMappingDto productAttributeMapping) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -652,13 +640,12 @@ public async Task CreateProductAttributeMapping([FromRoute] strin } [SwaggerOperation("Invoke action UpdateProductAttributeMapping", OperationId = "UpdateProductAttributeMapping")] - [HttpPost("/{key}/UpdateProductAttributeMapping")] + [HttpPost("{key}/UpdateProductAttributeMapping")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task UpdateProductAttributeMapping([FromRoute] string key, - [FromBody] ProductAttributeMappingDto productAttributeMapping) + public async Task UpdateProductAttributeMapping([FromRoute] string key, [FromBody] ProductAttributeMappingDto productAttributeMapping) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); @@ -681,13 +668,12 @@ public async Task UpdateProductAttributeMapping([FromRoute] strin } [SwaggerOperation("Invoke action DeleteProductAttributeMapping", OperationId = "DeleteProductAttributeMapping")] - [HttpPost("/{key}/DeleteProductAttributeMapping")] + [HttpPost("{key}/DeleteProductAttributeMapping")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task DeleteProductAttributeMapping([FromRoute] string key, - [FromBody] ProductAttributeMappingDeleteDto model) + public async Task DeleteProductAttributeMapping([FromRoute] string key, [FromBody] ProductAttributeMappingDeleteDto model) { if (!await _permissionService.Authorize(PermissionSystemName.Products)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/ProductLayoutController.cs b/src/Modules/Grand.Module.Api/Controllers/ProductLayoutController.cs index 3a784273e..87ddc40a1 100644 --- a/src/Modules/Grand.Module.Api/Controllers/ProductLayoutController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/ProductLayoutController.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; @@ -28,7 +29,7 @@ public ProductLayoutController(IMediator mediator, IPermissionService permission [SwaggerOperation("Get entity from ProductLayout by key", OperationId = "GetProductLayoutById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(LayoutDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -44,7 +45,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.Maintenance)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/ShippingMethodController.cs b/src/Modules/Grand.Module.Api/Controllers/ShippingMethodController.cs index 3c429f6ba..6e74caa1d 100644 --- a/src/Modules/Grand.Module.Api/Controllers/ShippingMethodController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/ShippingMethodController.cs @@ -1,7 +1,6 @@ using Grand.Business.Core.Interfaces.Common.Security; using Grand.Domain.Permissions; using Grand.Domain.Shipping; -using Grand.Module.Api.Constants; using Grand.Module.Api.DTOs.Shipping; using Grand.Module.Api.Attributes; using Grand.Module.Api.Queries.Models.Common; @@ -9,11 +8,10 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/ShippingMethod")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class ShippingMethodController : BaseApiController { private readonly IMediator _mediator; @@ -28,7 +26,7 @@ public ShippingMethodController(IMediator mediator, IPermissionService permissio [SwaggerOperation("Get entity from ShippingMethod by key", OperationId = "GetShippingMethodById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ShippingMethodDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -44,7 +42,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.ShippingSettings)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/SpecificationAttributeController.cs b/src/Modules/Grand.Module.Api/Controllers/SpecificationAttributeController.cs index c625a6036..fa570fd3f 100644 --- a/src/Modules/Grand.Module.Api/Controllers/SpecificationAttributeController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/SpecificationAttributeController.cs @@ -2,7 +2,6 @@ using Grand.Domain.Catalog; using Grand.Domain.Permissions; using Grand.Module.Api.Commands.Models.Catalog; -using Grand.Module.Api.Constants; using Grand.Module.Api.DTOs.Catalog; using Grand.Module.Api.Attributes; using Grand.Module.Api.Queries.Models.Common; @@ -11,11 +10,10 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/SpecificationAttribute")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class SpecificationAttributeController : BaseApiController { private readonly IMediator _mediator; @@ -30,14 +28,13 @@ public SpecificationAttributeController(IMediator mediator, IPermissionService p [SwaggerOperation("Get entity from SpecificationAttribute by key", OperationId = "GetSpecificationAttributeById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(SpecificationAttributeDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { if (!await _permissionService.Authorize(PermissionSystemName.SpecificationAttributes)) return Forbid(); - var specificationAttribute = - await _mediator.Send(new GetGenericQuery(key)); + var specificationAttribute = await _mediator.Send(new GetGenericQuery(key)); if (!specificationAttribute.Any()) return NotFound(); return Ok(specificationAttribute.FirstOrDefault()); @@ -47,7 +44,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.SpecificationAttributes)) return Forbid(); @@ -58,7 +55,7 @@ public async Task Get() [SwaggerOperation("Add new entity to SpecificationAttribute", OperationId = "InsertSpecificationAttribute")] [HttpPost] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(SpecificationAttributeDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] public async Task Post([FromBody] SpecificationAttributeDto model) { @@ -69,35 +66,34 @@ public async Task Post([FromBody] SpecificationAttributeDto model } [SwaggerOperation("Update entity in SpecificationAttribute", OperationId = "UpdateSpecificationAttribute")] - [HttpPut] + [HttpPut("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(SpecificationAttributeDto))] [ProducesResponseType((int)HttpStatusCode.BadRequest)] - public async Task Put([FromBody] SpecificationAttributeDto model) + public async Task Put([FromRoute] string key, [FromBody] SpecificationAttributeDto model) { if (!await _permissionService.Authorize(PermissionSystemName.SpecificationAttributes)) return Forbid(); + var specification = await _mediator.Send(new GetGenericQuery(key)); + if (!specification.Any()) return NotFound(); model = await _mediator.Send(new UpdateSpecificationAttributeCommand { Model = model }); return Ok(model); } - [SwaggerOperation("Partially update entity in SpecificationAttribute", - OperationId = "PartiallyUpdateSpecificationAttribute")] + [SwaggerOperation("Partially update entity in SpecificationAttribute", OperationId = "PartiallyUpdateSpecificationAttribute")] [HttpPatch("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Patch([FromRoute] string key, - [FromBody] JsonPatchDocument model) + public async Task Patch([FromRoute] string key, [FromBody] JsonPatchDocument model) { if (string.IsNullOrEmpty(key)) return BadRequest("Key is null or empty"); if (!await _permissionService.Authorize(PermissionSystemName.SpecificationAttributes)) return Forbid(); - var specification = - await _mediator.Send(new GetGenericQuery(key)); + var specification = await _mediator.Send(new GetGenericQuery(key)); if (!specification.Any()) return NotFound(); var spec = specification.FirstOrDefault(); @@ -107,11 +103,11 @@ public async Task Patch([FromRoute] string key, } [SwaggerOperation("Delete entity in SpecificationAttribute", OperationId = "DeleteSpecificationAttribute")] - [HttpDelete] + [HttpDelete("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Delete(string key) + public async Task Delete([FromRoute] string key) { if (!await _permissionService.Authorize(PermissionSystemName.SpecificationAttributes)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/StoreController.cs b/src/Modules/Grand.Module.Api/Controllers/StoreController.cs index eb77544fd..4a40c7789 100644 --- a/src/Modules/Grand.Module.Api/Controllers/StoreController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/StoreController.cs @@ -7,13 +7,11 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; -using Grand.Module.Api.Constants; using Grand.Module.Api.Attributes; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/Store")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class StoreController : BaseApiController { private readonly IMediator _mediator; @@ -28,7 +26,7 @@ public StoreController(IMediator mediator, IPermissionService permissionService) [SwaggerOperation("Get entity from Store by key", OperationId = "GetStoreById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(StoreDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -44,7 +42,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.Stores)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/VendorController.cs b/src/Modules/Grand.Module.Api/Controllers/VendorController.cs index 7508bd023..974ccc8e2 100644 --- a/src/Modules/Grand.Module.Api/Controllers/VendorController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/VendorController.cs @@ -7,13 +7,11 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; -using Grand.Module.Api.Constants; using Grand.Module.Api.Attributes; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/Vendor")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class VendorController : BaseApiController { private readonly IMediator _mediator; @@ -28,7 +26,7 @@ public VendorController(IMediator mediator, IPermissionService permissionService [SwaggerOperation("Get entity from Vendor by key", OperationId = "GetVendorById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(VendorDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -44,7 +42,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.Vendors)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Controllers/WarehouseController.cs b/src/Modules/Grand.Module.Api/Controllers/WarehouseController.cs index 854d6d2c8..b147ddd79 100644 --- a/src/Modules/Grand.Module.Api/Controllers/WarehouseController.cs +++ b/src/Modules/Grand.Module.Api/Controllers/WarehouseController.cs @@ -7,13 +7,11 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net; -using Grand.Module.Api.Constants; using Grand.Module.Api.Attributes; +using Microsoft.AspNetCore.Http; namespace Grand.Module.Api.Controllers; -[Route($"{Configurations.RestRoutePrefix}/Warehouse")] -[ApiExplorerSettings(IgnoreApi = false, GroupName = "v1")] public class WarehouseController : BaseApiController { private readonly IMediator _mediator; @@ -28,7 +26,7 @@ public WarehouseController(IMediator mediator, IPermissionService permissionServ [SwaggerOperation("Get entity from Warehouse by key", OperationId = "GetWarehouseById")] [HttpGet("{key}")] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(WarehouseDto))] [ProducesResponseType((int)HttpStatusCode.NotFound)] public async Task Get([FromRoute] string key) { @@ -44,7 +42,7 @@ public async Task Get([FromRoute] string key) [HttpGet] [EnableQuery] [ProducesResponseType((int)HttpStatusCode.Forbidden)] - [ProducesResponseType((int)HttpStatusCode.OK)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] public async Task Get() { if (!await _permissionService.Authorize(PermissionSystemName.ShippingSettings)) return Forbid(); diff --git a/src/Modules/Grand.Module.Api/Extensions/AddParamOperationFilter.cs b/src/Modules/Grand.Module.Api/Extensions/AddParamOperationFilter.cs index 7be72b594..103b68903 100644 --- a/src/Modules/Grand.Module.Api/Extensions/AddParamOperationFilter.cs +++ b/src/Modules/Grand.Module.Api/Extensions/AddParamOperationFilter.cs @@ -44,16 +44,6 @@ private void ApplyV1(OpenApiOperation operation) Type = "integer" } }); - operation.Parameters.Add(new OpenApiParameter { - Name = "$count", - AllowReserved = true, - In = ParameterLocation.Query, - Description = "Include count of items", - Required = false, - Schema = new OpenApiSchema { - Type = "boolean" - } - }); operation.Parameters.Add(new OpenApiParameter { Name = "$orderby", AllowReserved = true, diff --git a/src/Modules/Grand.Module.Api/Queries/Handlers/Common/GetGenericQueryHandler.cs b/src/Modules/Grand.Module.Api/Queries/Handlers/Common/GetGenericQueryHandler.cs index 5a4d10a95..befbdebfc 100644 --- a/src/Modules/Grand.Module.Api/Queries/Handlers/Common/GetGenericQueryHandler.cs +++ b/src/Modules/Grand.Module.Api/Queries/Handlers/Common/GetGenericQueryHandler.cs @@ -20,6 +20,7 @@ public GetGenericQueryHandler(IRepository repository) public async Task> Handle(GetGenericQuery request, CancellationToken cancellationToken) { var query = _repository.TableCollection(); + if (string.IsNullOrEmpty(request.Id)) return query; return await Task.FromResult(query.Where(x => x.Id == request.Id)); diff --git a/src/Modules/Grand.Module.Api/Queries/Models/Common/GetGenericQuery.cs b/src/Modules/Grand.Module.Api/Queries/Models/Common/GetGenericQuery.cs index df79fb8ce..db80d9d4a 100644 --- a/src/Modules/Grand.Module.Api/Queries/Models/Common/GetGenericQuery.cs +++ b/src/Modules/Grand.Module.Api/Queries/Models/Common/GetGenericQuery.cs @@ -4,5 +4,4 @@ namespace Grand.Module.Api.Queries.Models.Common; -public record GetGenericQuery(string Id = null) - : IRequest> where T : BaseApiEntityModel where C : BaseEntity; \ No newline at end of file +public record GetGenericQuery(string Id = null) : IRequest> where T : BaseApiEntityModel where C : BaseEntity; \ No newline at end of file