diff --git a/Directory.Build.props b/Directory.Build.props index 67b88746..cfaa9ecb 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -7,7 +7,7 @@ VirtoCommerce - 6.28.0 + 6.29.0 $(VersionSuffix)-$(BuildNumber) diff --git a/VirtoCommerce.Storefront.Model/SlugInfoRequest.cs b/VirtoCommerce.Storefront.Model/SlugInfoRequest.cs new file mode 100644 index 00000000..03065e5c --- /dev/null +++ b/VirtoCommerce.Storefront.Model/SlugInfoRequest.cs @@ -0,0 +1,11 @@ +using System.ComponentModel.DataAnnotations; + +namespace VirtoCommerce.Storefront.Model; + +public class SlugInfoRequest +{ + public string CultureName { get; set; } + + [Required] + public string Slug { get; set; } +} diff --git a/VirtoCommerce.Storefront.Model/StaticContent/ContentInThemeSearchCriteria.cs b/VirtoCommerce.Storefront.Model/StaticContent/ContentInThemeSearchCriteria.cs index 2e23eb3e..8f761e76 100644 --- a/VirtoCommerce.Storefront.Model/StaticContent/ContentInThemeSearchCriteria.cs +++ b/VirtoCommerce.Storefront.Model/StaticContent/ContentInThemeSearchCriteria.cs @@ -1,14 +1,20 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; namespace VirtoCommerce.Storefront.Model.StaticContent { public class ContentInThemeSearchCriteria { public string Permalink { get; set; } - public string Template { get; set; } + + [Obsolete("Use TemplateName instead")] + public string Template + { + get => TemplateName; + set => TemplateName = value; + } + + [Required] + public string TemplateName { get; set; } } } diff --git a/VirtoCommerce.Storefront/Controllers/Api/ApiAccountController.cs b/VirtoCommerce.Storefront/Controllers/Api/ApiAccountController.cs index 7be6005b..e9ca3af8 100644 --- a/VirtoCommerce.Storefront/Controllers/Api/ApiAccountController.cs +++ b/VirtoCommerce.Storefront/Controllers/Api/ApiAccountController.cs @@ -50,6 +50,7 @@ public ApiAccountController(IWorkContextAccessor workContextAccessor, } // GET: storefrontapi/account + [Obsolete("Use me query from GraphQL")] [HttpGet] [AllowAnonymous] public ActionResult GetCurrentUser() @@ -156,6 +157,7 @@ private void ResetIdentityCookies() } // POST: storefrontapi/account/user + [Obsolete("Use requestRegistration mutations from GraphQL")] [HttpPost("user")] public async Task> RegisterUser([FromBody] UserRegistration registration) { @@ -228,6 +230,7 @@ public async Task> RegisterUser([FromBody // POST: storefrontapi/account/password + [Obsolete("Use changePassword mutation from GraphQL")] [HttpPost("password")] public async Task> ChangePassword([FromBody] ChangePassword formModel) { @@ -309,6 +312,7 @@ public async Task Logout() } // POST: storefrontapi/account/forgotpassword + [Obsolete("Use requestPasswordReset mutation from GraphQL")] [HttpPost("forgotPassword")] [AllowAnonymous] public async Task> ForgotPassword([FromBody] ForgotPasswordModel forgotPassword) @@ -381,6 +385,7 @@ public async Task> ForgotPassword([FromBo } // POST: storefrontapi/account/validateToken + [Obsolete("This API no longer used. See XAPI documentation")] [HttpPost("validateToken")] [AllowAnonymous] public async Task> ValidateResetPasswordToken([FromBody] ValidateTokenModel model) @@ -415,6 +420,7 @@ public async Task> ValidateResetPasswordT } // POST: storefrontapi/account/resetPassword + [Obsolete("Use resetPasswordByToken mutation from GraphQL")] [HttpPost("resetPassword")] [AllowAnonymous] public async Task> ResetPassword([FromBody] ResetPasswordModel model) @@ -455,6 +461,7 @@ public async Task> ResetPassword([FromBod } // POST: storefrontapi/account/confirmemail + [Obsolete("Use confirmEmail mutation from GraphQL")] [HttpPost("confirmemail")] [AllowAnonymous] public async Task> ConfirmEmail([FromBody] ConfirmEmailModel model) diff --git a/VirtoCommerce.Storefront/Controllers/Api/ApiCommonController.cs b/VirtoCommerce.Storefront/Controllers/Api/ApiCommonController.cs index 5e0dc391..e615bd46 100644 --- a/VirtoCommerce.Storefront/Controllers/Api/ApiCommonController.cs +++ b/VirtoCommerce.Storefront/Controllers/Api/ApiCommonController.cs @@ -34,6 +34,7 @@ public ApiCommonController( } // GET: storefrontapi/countries + [Obsolete("Use countries query from GraphQL")] [HttpGet("countries")] public ActionResult GetCountries() { @@ -41,6 +42,7 @@ public ActionResult GetCountries() } // GET: storefrontapi/countries/{countryCode}/regions + [Obsolete("Use countries or regions query from GraphQL")] [HttpGet("countries/{countryCode}/regions")] public ActionResult GetCountryRegions(string countryCode) { @@ -61,9 +63,31 @@ public async Task Feedback([FromBody] ContactForm model) return Ok(); } + + [HttpPost("slug")] + public async Task GetSlugInfoBySlugAsync([FromBody] SlugInfoRequest slugInfoRequest) + { + return await GetSlugInfoAsync(slugInfoRequest.Slug, slugInfoRequest.CultureName); + } + // Wildcard parameters are not supported by OpenAPI (including latest 3.1) + // https://stackoverflow.com/a/42880107/507434 + [Obsolete("Use GetSlugInfoBySlug (POST /slug) instead")] [HttpGet("slug/{*slug}")] public async Task GetInfoBySlugAsync(string slug, [FromQuery] string culture) + { + return await GetSlugInfoAsync(slug, culture); + } + + // GET: storefrontapi/version + [HttpGet("version")] + [AllowAnonymous] + public ActionResult Version() + { + return Ok(System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).FileVersion); + } + + private async Task GetSlugInfoAsync(string slug, string culture) { var result = new SlugInfoResult(); @@ -102,13 +126,5 @@ public async Task GetInfoBySlugAsync(string slug, [FromQuery] st return result; } - - // GET: storefrontapi/version - [HttpGet("version")] - [AllowAnonymous] - public ActionResult Version() - { - return Ok(System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).FileVersion); - } } } diff --git a/VirtoCommerce.Storefront/Controllers/Api/ApiStaticContentController.cs b/VirtoCommerce.Storefront/Controllers/Api/ApiStaticContentController.cs index 6d10d3f6..73be1ffc 100644 --- a/VirtoCommerce.Storefront/Controllers/Api/ApiStaticContentController.cs +++ b/VirtoCommerce.Storefront/Controllers/Api/ApiStaticContentController.cs @@ -1,6 +1,6 @@ -using System; -using System.Collections.Generic; using System.Linq; +using System.Net.Mime; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using VirtoCommerce.LiquidThemeEngine; using VirtoCommerce.Storefront.Domain; @@ -35,7 +35,7 @@ public ActionResult ResetCache([FromBody] ResetCacheEventModel webHookEvent) // POST: storefrontapi/content/reset-cache/theme [HttpPost("reset-cache/{region}")] - public ActionResult ResetCache([FromRoute] string region) + public ActionResult ResetCacheRegion([FromRoute] string region) { if (TryResetCacheInternal(region)) { @@ -63,7 +63,9 @@ private static bool TryResetCacheInternal(string region) // POST: storefrontapi/content/pages [HttpPost("pages")] - public ActionResult FindPage([FromBody]ContentInThemeSearchCriteria value) + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(object))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public ActionResult FindPage([FromBody] ContentInThemeSearchCriteria value) { var permalink = value.Permalink; var result = WorkContext.Pages.FirstOrDefault(x => x.Permalink != null && x.Permalink.EqualsInvariant(permalink)); @@ -75,10 +77,11 @@ public ActionResult FindPage([FromBody]ContentInThemeSearchCriteria value) } [HttpPost("templates")] - public ActionResult LoadTemplate([FromBody]ContentInThemeSearchCriteria value) + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(object))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public ActionResult LoadTemplate([FromBody] ContentInThemeSearchCriteria value) { - var template = value.Template; - var result = WorkContext.Templates.FirstOrDefault(x => x.Name == template); + var result = WorkContext.Templates.FirstOrDefault(x => x.Name == value.TemplateName); if (result == null) { return NotFound(); @@ -88,7 +91,7 @@ public ActionResult LoadTemplate([FromBody]ContentInThemeSearchCriteria value) private ActionResult JsonResult(string content) { - return Content(content, "application/json"); + return Content(content, MediaTypeNames.Application.Json); } } } diff --git a/VirtoCommerce.Storefront/Controllers/CommonController.cs b/VirtoCommerce.Storefront/Controllers/CommonController.cs index d83f4cd3..0fe37806 100644 --- a/VirtoCommerce.Storefront/Controllers/CommonController.cs +++ b/VirtoCommerce.Storefront/Controllers/CommonController.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; @@ -82,6 +83,7 @@ public async Task SetCurrency(string currency, string returnUrl = } // GET: common/getcountries/json + [Obsolete("Use countries query from GraphQL")] [HttpGet("common/getcountries/json")] public ActionResult GetCountries() { @@ -90,6 +92,7 @@ public ActionResult GetCountries() } // GET: common/getregions/{countryCode}/json + [Obsolete("Use countries or regions query from GraphQL")] [HttpGet("common/getregions/{countryCode}/json")] public ActionResult GetRegions(string countryCode) { diff --git a/VirtoCommerce.Storefront/Startup.cs b/VirtoCommerce.Storefront/Startup.cs index d109dbec..684a2c6a 100644 --- a/VirtoCommerce.Storefront/Startup.cs +++ b/VirtoCommerce.Storefront/Startup.cs @@ -327,7 +327,6 @@ public void ConfigureServices(IServiceCollection services) c.OperationFilter(); c.OperationFilter(); c.SchemaFilter(); - c.SchemaFilter(); // Use method name as operation ID, i.e. ApiAccount.GetOrganization instead of /storefrontapi/account/organization (will be treated as just organization method) c.CustomOperationIds(apiDesc => apiDesc.TryGetMethodInfo(out var methodInfo) ? methodInfo.Name : null); @@ -335,6 +334,7 @@ public void ConfigureServices(IServiceCollection services) // To avoid errors with repeating type names c.CustomSchemaIds(type => (Attribute.GetCustomAttribute(type, typeof(SwaggerSchemaIdAttribute)) as SwaggerSchemaIdAttribute)?.Id ?? type.FriendlyId()); }); + services.AddSwaggerGenNewtonsoftSupport(); services.AddResponseCompression(); diff --git a/VirtoCommerce.Storefront/VirtoCommerce.Storefront.csproj b/VirtoCommerce.Storefront/VirtoCommerce.Storefront.csproj index 10756cc5..811b87ed 100644 --- a/VirtoCommerce.Storefront/VirtoCommerce.Storefront.csproj +++ b/VirtoCommerce.Storefront/VirtoCommerce.Storefront.csproj @@ -68,10 +68,11 @@ - - - - + + + + +