From a55ff6fdb13e2b9481a1cfc4d0bbf1b8de410211 Mon Sep 17 00:00:00 2001 From: Denis Fomichev Date: Wed, 18 Oct 2023 18:08:14 +0400 Subject: [PATCH 1/5] ECWID-127184 Custom URL slugs for catalog pages: Enable new URL format on Instant sites - add SlugInfo API to api client --- .../com/ecwid/apiclient/v3/ApiClient.kt | 13 +++++-- .../v3/dto/sluginfo/FetchedSlugInfo.kt | 23 ++++++++++++ .../v3/dto/sluginfo/SlugInfoRequest.kt | 36 +++++++++++++++++++ .../v3/impl/SlugInfoApiClientImpl.kt | 14 ++++++++ 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt create mode 100644 src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/SlugInfoRequest.kt create mode 100644 src/main/kotlin/com/ecwid/apiclient/v3/impl/SlugInfoApiClientImpl.kt diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt index dd6eba34..f8a67ccc 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt @@ -31,6 +31,8 @@ import com.ecwid.apiclient.v3.dto.report.request.ReportRequest import com.ecwid.apiclient.v3.dto.report.result.FetchedReportResponse import com.ecwid.apiclient.v3.dto.saleschannels.request.* import com.ecwid.apiclient.v3.dto.saleschannels.response.* +import com.ecwid.apiclient.v3.dto.sluginfo.FetchedSlugInfo +import com.ecwid.apiclient.v3.dto.sluginfo.SlugInfoRequest import com.ecwid.apiclient.v3.dto.storage.request.* import com.ecwid.apiclient.v3.dto.storage.result.* import com.ecwid.apiclient.v3.dto.subscriptions.request.SubscriptionsSearchRequest @@ -61,6 +63,7 @@ open class ApiClient private constructor( reportsApiClient: ReportsApiClientImpl, subscriptionsApiClient: SubscriptionsApiClientImpl, instantSiteRedirectsApiClient: InstantSiteRedirectsApiClientImpl, + slugInfoApiClient: SlugInfoApiClientImpl, ) : StoreProfileApiClient by storeProfileApiClient, ProductsApiClient by productsApiClient, @@ -78,7 +81,8 @@ open class ApiClient private constructor( ApplicationStorageApiClient by applicationStorageApiClient, ReportsApiClient by reportsApiClient, SubscriptionsApiClient by subscriptionsApiClient, - InstantSiteRedirectsApiClient by instantSiteRedirectsApiClient { + InstantSiteRedirectsApiClient by instantSiteRedirectsApiClient, + SlugInfoApiClient by slugInfoApiClient { constructor(apiClientHelper: ApiClientHelper) : this( apiClientHelper = apiClientHelper, @@ -98,7 +102,8 @@ open class ApiClient private constructor( applicationStorageApiClient = ApplicationStorageApiClientImpl(apiClientHelper), reportsApiClient = ReportsApiClientImpl(apiClientHelper), subscriptionsApiClient = SubscriptionsApiClientImpl(apiClientHelper), - instantSiteRedirectsApiClient = InstantSiteRedirectsApiClientImpl(apiClientHelper) + instantSiteRedirectsApiClient = InstantSiteRedirectsApiClientImpl(apiClientHelper), + slugInfoApiClient = SlugInfoApiClientImpl(apiClientHelper), ) companion object { @@ -282,3 +287,7 @@ interface InstantSiteRedirectsApiClient { fun createInstantSiteRedirects(request: InstantSiteRedirectsCreateRequest): InstantSiteRedirectsCreateResult fun deleteInstantSiteRedirect(request: InstantSiteRedirectDeleteRequest): InstantSiteRedirectsDeleteResult } + +interface SlugInfoApiClient { + fun getSlugInfo(request: SlugInfoRequest): FetchedSlugInfo +} diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt new file mode 100644 index 00000000..bbf82b26 --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt @@ -0,0 +1,23 @@ +package com.ecwid.apiclient.v3.dto.sluginfo + +data class FetchedSlugInfo( + val status: String, + val type: String?, + val canonicalSlug: String?, + val storeEntityData: EntityData?, + var staticContent: StaticContent?, +) + +data class EntityData(val id: String?) + +data class StaticContent( + val cssFiles: List? = null, + val htmlCode: String? = null, + val jsCode: String? = null, + val metaDescriptionHtml: String? = null, + val canonicalUrl: String? = null, + val ogTagsHtml: String? = null, + val jsonLDHtml: String? = null, + val hrefLangHtml: String? = null, + val lastUpdated: Long? = null +) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/SlugInfoRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/SlugInfoRequest.kt new file mode 100644 index 00000000..b4487f36 --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/SlugInfoRequest.kt @@ -0,0 +1,36 @@ +package com.ecwid.apiclient.v3.dto.sluginfo + +import com.ecwid.apiclient.v3.dto.ApiRequest +import com.ecwid.apiclient.v3.impl.RequestInfo +import com.ecwid.apiclient.v3.responsefields.ResponseFields + +data class SlugInfoRequest( + val storeRootPage: Boolean = false, + val slug: String = "", + val getStaticContent: Boolean = false, + val degeneratorParams: Map? = null, + val responseFields: ResponseFields = ResponseFields.All, + ) : ApiRequest { + override fun toRequestInfo(): RequestInfo = RequestInfo.createGetRequest( + pathSegments = listOf( + "storefront-widget-pages" + ), + params = toParams(), + responseFields = responseFields, + ) + + + private fun toParams(): Map { + val request = this + return mutableMapOf().apply { + put("storeRootPage", storeRootPage.toString()) + put("getStaticContent", getStaticContent.toString()) + put("slug", slug) + request.degeneratorParams?.let { + request.degeneratorParams.forEach { put(it.key, it.value.toString()) } + } + }.toMap() + } +} + + diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/impl/SlugInfoApiClientImpl.kt b/src/main/kotlin/com/ecwid/apiclient/v3/impl/SlugInfoApiClientImpl.kt new file mode 100644 index 00000000..c3168c4d --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/impl/SlugInfoApiClientImpl.kt @@ -0,0 +1,14 @@ +package com.ecwid.apiclient.v3.impl + +import com.ecwid.apiclient.v3.ApiClientHelper +import com.ecwid.apiclient.v3.SlugInfoApiClient +import com.ecwid.apiclient.v3.dto.sluginfo.FetchedSlugInfo +import com.ecwid.apiclient.v3.dto.sluginfo.SlugInfoRequest + +internal class SlugInfoApiClientImpl( + private val apiClientHelper: ApiClientHelper +): SlugInfoApiClient { + override fun getSlugInfo(request: SlugInfoRequest): FetchedSlugInfo = + apiClientHelper.makeObjectResultRequest(request) + +} From 950e49b570bc063feeb5ac539904fa6b959d4dae Mon Sep 17 00:00:00 2001 From: Denis Fomichev Date: Wed, 18 Oct 2023 18:54:04 +0400 Subject: [PATCH 2/5] fix detekt --- .../kotlin/com/ecwid/apiclient/v3/impl/SlugInfoApiClientImpl.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/impl/SlugInfoApiClientImpl.kt b/src/main/kotlin/com/ecwid/apiclient/v3/impl/SlugInfoApiClientImpl.kt index c3168c4d..e620e789 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/impl/SlugInfoApiClientImpl.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/impl/SlugInfoApiClientImpl.kt @@ -7,7 +7,7 @@ import com.ecwid.apiclient.v3.dto.sluginfo.SlugInfoRequest internal class SlugInfoApiClientImpl( private val apiClientHelper: ApiClientHelper -): SlugInfoApiClient { +) : SlugInfoApiClient { override fun getSlugInfo(request: SlugInfoRequest): FetchedSlugInfo = apiClientHelper.makeObjectResultRequest(request) From 883283d08fdeeb37746b8a43760b0b0c1e47e194 Mon Sep 17 00:00:00 2001 From: Denis Fomichev Date: Wed, 18 Oct 2023 19:26:42 +0400 Subject: [PATCH 3/5] fix FetchedSlugInfo default constructor --- .../apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt | 12 ++++++------ .../apiclient/v3/dto/sluginfo/SlugInfoRequest.kt | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt index bbf82b26..052d989e 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt @@ -1,14 +1,14 @@ package com.ecwid.apiclient.v3.dto.sluginfo data class FetchedSlugInfo( - val status: String, - val type: String?, - val canonicalSlug: String?, - val storeEntityData: EntityData?, - var staticContent: StaticContent?, + val status: String = "", + val type: String? = null, + val canonicalSlug: String? = null, + val storeEntityData: EntityData? = null, + var staticContent: StaticContent? = null, ) -data class EntityData(val id: String?) +data class EntityData(val id: String? = null) data class StaticContent( val cssFiles: List? = null, diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/SlugInfoRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/SlugInfoRequest.kt index b4487f36..57c4643c 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/SlugInfoRequest.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/SlugInfoRequest.kt @@ -9,8 +9,9 @@ data class SlugInfoRequest( val slug: String = "", val getStaticContent: Boolean = false, val degeneratorParams: Map? = null, - val responseFields: ResponseFields = ResponseFields.All, - ) : ApiRequest { + val responseFields: ResponseFields = ResponseFields.All +) : ApiRequest { + override fun toRequestInfo(): RequestInfo = RequestInfo.createGetRequest( pathSegments = listOf( "storefront-widget-pages" From 4ebead2e575cca5eb18cec7e487d9fba45d5fb64 Mon Sep 17 00:00:00 2001 From: Denis Fomichev Date: Thu, 19 Oct 2023 10:19:23 +0400 Subject: [PATCH 4/5] fix tests for new entities --- .../v3/dto/sluginfo/FetchedSlugInfo.kt | 37 ++++++++++++------- .../v3/rule/NullablePropertyRules.kt | 5 ++- .../FetchedSlugInfoRules.kt | 25 +++++++++++++ .../SlugInfoRequestRules.kt | 9 +++++ 4 files changed, 61 insertions(+), 15 deletions(-) create mode 100644 src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedSlugInfoRules.kt create mode 100644 src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/SlugInfoRequestRules.kt diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt index 052d989e..c329cdda 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt @@ -1,23 +1,32 @@ package com.ecwid.apiclient.v3.dto.sluginfo +import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO +import com.ecwid.apiclient.v3.dto.common.ApiResultDTO + data class FetchedSlugInfo( val status: String = "", val type: String? = null, val canonicalSlug: String? = null, val storeEntityData: EntityData? = null, - var staticContent: StaticContent? = null, -) + val staticContent: StaticContent? = null, +): ApiFetchedDTO, ApiResultDTO { + + data class EntityData(val id: String? = null) + + data class StaticContent( + val cssFiles: List? = null, + val htmlCode: String? = null, + val jsCode: String? = null, + val metaDescriptionHtml: String? = null, + val canonicalUrl: String? = null, + val ogTagsHtml: String? = null, + val jsonLDHtml: String? = null, + val hrefLangHtml: String? = null, + val lastUpdated: Long? = null + ) + + override fun getModifyKind(): ApiFetchedDTO.ModifyKind = + ApiFetchedDTO.ModifyKind.ReadOnly -data class EntityData(val id: String? = null) -data class StaticContent( - val cssFiles: List? = null, - val htmlCode: String? = null, - val jsCode: String? = null, - val metaDescriptionHtml: String? = null, - val canonicalUrl: String? = null, - val ogTagsHtml: String? = null, - val jsonLDHtml: String? = null, - val hrefLangHtml: String? = null, - val lastUpdated: Long? = null -) +} diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt b/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt index 87982abf..8db23555 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt @@ -143,7 +143,10 @@ val nullablePropertyRules: List> = listOf( productsSearchRequestNullablePropertyRules, subscriptionsSearchRequestNullablePropertyRules, fetchedSubscriptionsNullablePropertyRules, - otherNullablePropertyRules + otherNullablePropertyRules, + fetchedSlugInfoNullablePropertyRules, + fetchedSlugInfoClassesNullablePropertyRules, + slugInfoRequestNullablePropertyRules ).flatten() sealed class NullablePropertyRule( diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedSlugInfoRules.kt b/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedSlugInfoRules.kt new file mode 100644 index 00000000..fc730a2e --- /dev/null +++ b/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedSlugInfoRules.kt @@ -0,0 +1,25 @@ +package com.ecwid.apiclient.v3.rule.nullablepropertyrules + +import com.ecwid.apiclient.v3.dto.sluginfo.FetchedSlugInfo +import com.ecwid.apiclient.v3.rule.NullablePropertyRule +import com.ecwid.apiclient.v3.rule.NullablePropertyRule.AllowNullable + +val fetchedSlugInfoNullablePropertyRules: List> = listOf( + AllowNullable(FetchedSlugInfo::canonicalSlug), + AllowNullable(FetchedSlugInfo::type), + AllowNullable(FetchedSlugInfo::staticContent), + AllowNullable(FetchedSlugInfo::storeEntityData), +) + +val fetchedSlugInfoClassesNullablePropertyRules: List> = listOf( + AllowNullable(FetchedSlugInfo.EntityData::id), + AllowNullable(FetchedSlugInfo.StaticContent::canonicalUrl), + AllowNullable(FetchedSlugInfo.StaticContent::cssFiles), + AllowNullable(FetchedSlugInfo.StaticContent::jsCode), + AllowNullable(FetchedSlugInfo.StaticContent::hrefLangHtml), + AllowNullable(FetchedSlugInfo.StaticContent::htmlCode), + AllowNullable(FetchedSlugInfo.StaticContent::jsonLDHtml), + AllowNullable(FetchedSlugInfo.StaticContent::lastUpdated), + AllowNullable(FetchedSlugInfo.StaticContent::metaDescriptionHtml), + AllowNullable(FetchedSlugInfo.StaticContent::ogTagsHtml), +) diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/SlugInfoRequestRules.kt b/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/SlugInfoRequestRules.kt new file mode 100644 index 00000000..ab01f811 --- /dev/null +++ b/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/SlugInfoRequestRules.kt @@ -0,0 +1,9 @@ +package com.ecwid.apiclient.v3.rule.nullablepropertyrules + +import com.ecwid.apiclient.v3.dto.sluginfo.SlugInfoRequest +import com.ecwid.apiclient.v3.rule.NullablePropertyRule +import com.ecwid.apiclient.v3.rule.NullablePropertyRule.AllowNullable + +val slugInfoRequestNullablePropertyRules: List> = listOf( + AllowNullable(SlugInfoRequest::degeneratorParams), +) From 4db09ff38d2c3c4438e8a8a22a9d0eeaba9e2df1 Mon Sep 17 00:00:00 2001 From: Denis Fomichev Date: Thu, 19 Oct 2023 10:55:12 +0400 Subject: [PATCH 5/5] fix detekt --- .../com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt index c329cdda..3ab3dfa0 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/sluginfo/FetchedSlugInfo.kt @@ -9,7 +9,7 @@ data class FetchedSlugInfo( val canonicalSlug: String? = null, val storeEntityData: EntityData? = null, val staticContent: StaticContent? = null, -): ApiFetchedDTO, ApiResultDTO { +) : ApiFetchedDTO, ApiResultDTO { data class EntityData(val id: String? = null)