Skip to content

Commit c7e9991

Browse files
ECWID-155668 Add "updateShippingOption" method to ecwid-java-api-client - (feat) add new DTO classes
1 parent 3139ba5 commit c7e9991

11 files changed

Lines changed: 532 additions & 0 deletions

File tree

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
package com.ecwid.apiclient.v3.converter
2+
3+
import com.ecwid.apiclient.v3.dto.profile.request.UpdatedShippingOption
4+
import com.ecwid.apiclient.v3.dto.profile.result.FetchedShippingOption
5+
6+
fun FetchedShippingOption.toUpdated(): UpdatedShippingOption {
7+
return UpdatedShippingOption(
8+
id = id,
9+
appClientId = appClientId,
10+
title = title,
11+
titleTranslated = titleTranslated,
12+
description = description,
13+
descriptionTranslated = descriptionTranslated,
14+
enabled = enabled,
15+
orderBy = orderBy,
16+
fulfilmentType = fulfilmentType,
17+
minimumOrderSubtotal = minimumOrderSubtotal,
18+
destinationZone = destinationZone?.toUpdated(),
19+
deliveryTimeDays = deliveryTimeDays,
20+
ratesCalculationType = ratesCalculationType,
21+
locationId = locationId,
22+
flatRate = flatRate?.toUpdated(),
23+
ratesTable = ratesTable?.toUpdated(),
24+
shippingCostMarkup = shippingCostMarkup,
25+
pickupPreparationTimeHours = pickupPreparationTimeHours,
26+
pickupBusinessHours = pickupBusinessHours,
27+
pickupInstruction = pickupInstruction,
28+
pickupInstructionTranslated = pickupInstructionTranslated,
29+
scheduledPickup = scheduledPickup,
30+
type = type,
31+
carrier = carrier,
32+
carrierSettings = carrierSettings?.toUpdate(),
33+
carrierMethods = carrierMethods?.map { it.toUpdated() },
34+
businessHours = businessHours,
35+
businessHoursLimitationType = businessHoursLimitationType,
36+
allowSameDayDelivery = allowSameDayDelivery,
37+
availabilityPeriod = availabilityPeriod,
38+
customAvailabilityPeriodInDays = customAvailabilityPeriodInDays,
39+
scheduled = scheduled,
40+
scheduledTimePrecisionType = scheduledTimePrecisionType,
41+
timeSlotLengthInMinutes = timeSlotLengthInMinutes,
42+
cutoffTimeForSameDayDelivery = cutoffTimeForSameDayDelivery,
43+
fulfillmentTimeInMinutes = fulfillmentTimeInMinutes,
44+
blackoutDates = blackoutDates?.map { it.toUpdated() },
45+
estimatedShippingTimeAtCheckoutSettings = estimatedShippingTimeAtCheckoutSettings?.toUpdated(),
46+
)
47+
}
48+
49+
fun FetchedShippingOption.Zone.toUpdated(): UpdatedShippingOption.Zone {
50+
return UpdatedShippingOption.Zone(
51+
id = id,
52+
name = name,
53+
countryCodes = countryCodes,
54+
stateOrProvinceCodes = stateOrProvinceCodes,
55+
postCodes = postCodes,
56+
)
57+
}
58+
59+
fun FetchedShippingOption.FlatRate.toUpdated(): UpdatedShippingOption.FlatRate {
60+
return UpdatedShippingOption.FlatRate(
61+
rateType = rateType,
62+
rate = rate,
63+
)
64+
}
65+
66+
fun FetchedShippingOption.TableRates.toUpdated(): UpdatedShippingOption.TableRates {
67+
return UpdatedShippingOption.TableRates(
68+
tableBasedOn = tableBasedOn,
69+
rates = rates?.map { it.toUpdated() },
70+
)
71+
}
72+
73+
fun FetchedShippingOption.Rates.toUpdated(): UpdatedShippingOption.Rates {
74+
return UpdatedShippingOption.Rates(
75+
conditions = conditions?.toUpdated(),
76+
rate = rate?.toUpdated(),
77+
)
78+
}
79+
80+
fun FetchedShippingOption.Conditions.toUpdated(): UpdatedShippingOption.Conditions {
81+
return UpdatedShippingOption.Conditions(
82+
subtotalFrom = subtotalFrom,
83+
subtotalTo = subtotalTo,
84+
discountedSubtotalFrom = discountedSubtotalFrom,
85+
discountedSubtotalTo = discountedSubtotalTo,
86+
weightFrom = weightFrom,
87+
weightTo = weightTo,
88+
)
89+
}
90+
91+
fun FetchedShippingOption.Rate.toUpdated(): UpdatedShippingOption.Rate {
92+
return UpdatedShippingOption.Rate(
93+
perOrder = perOrder,
94+
percent = percent,
95+
perItem = perItem,
96+
perWeight = perWeight,
97+
)
98+
}
99+
100+
fun FetchedShippingOption.BlackoutPeriodItem.toUpdated(): UpdatedShippingOption.BlackoutPeriodItem {
101+
return UpdatedShippingOption.BlackoutPeriodItem(
102+
fromDate = fromDate,
103+
toDate = toDate,
104+
repeatedAnnually = repeatedAnnually,
105+
)
106+
}
107+
108+
fun FetchedShippingOption.EstimatedShippingTimeAtCheckoutSettings.toUpdated(): UpdatedShippingOption.EstimatedShippingTimeAtCheckoutSettings {
109+
return UpdatedShippingOption.EstimatedShippingTimeAtCheckoutSettings(
110+
estimatedDeliveryDateAtCheckoutEnabled = estimatedDeliveryDateAtCheckoutEnabled,
111+
estimatedTransitTimeInDays = estimatedTransitTimeInDays,
112+
fulfillmentTimeInDays = fulfillmentTimeInDays,
113+
shippingBusinessDays = shippingBusinessDays,
114+
deliveryDays = deliveryDays,
115+
cutoffTimeForSameDayPacking = cutoffTimeForSameDayPacking,
116+
)
117+
}
118+
119+
fun FetchedShippingOption.CarrierSettings.toUpdate(): UpdatedShippingOption.CarrierSettings {
120+
return UpdatedShippingOption.CarrierSettings(
121+
defaultCarrierAccountEnabled = defaultCarrierAccountEnabled,
122+
defaultPostageDimensions = defaultPostageDimensions?.toUpdate(),
123+
)
124+
}
125+
126+
fun FetchedShippingOption.DefaultPostageDimensions.toUpdate(): UpdatedShippingOption.DefaultPostageDimensions {
127+
return UpdatedShippingOption.DefaultPostageDimensions(
128+
height = height,
129+
length = length,
130+
width = width,
131+
)
132+
}
133+
134+
fun FetchedShippingOption.CarrierMethod.toUpdated(): UpdatedShippingOption.CarrierMethod {
135+
return UpdatedShippingOption.CarrierMethod(
136+
id = id,
137+
name = name,
138+
enabled = enabled,
139+
orderBy = orderBy,
140+
)
141+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.ecwid.apiclient.v3.dto.profile.enums
2+
3+
@Suppress("unused")
4+
enum class ApiBusinessHoursLimitationType {
5+
ALLOW_ORDERS_AND_INFORM_CUSTOMERS,
6+
DISALLOW_ORDERS_AND_INFORM_CUSTOMERS,
7+
ALLOW_ORDERS_AND_DONT_INFORM_CUSTOMERS
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.ecwid.apiclient.v3.dto.profile.enums
2+
3+
@Suppress("unused")
4+
enum class AvailabilityPeriodTimeUnit(val valueInMinutes: Int) {
5+
DAYS(24 * 60),
6+
MONTHS(30 * 24 * 60);
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.ecwid.apiclient.v3.dto.profile.enums
2+
3+
@Suppress("unused")
4+
enum class AvailabilityPeriodType(val unitCount: Int, val unit: AvailabilityPeriodTimeUnit?) {
5+
SEVEN_DAYS(7, AvailabilityPeriodTimeUnit.DAYS),
6+
ONE_MONTH(1, AvailabilityPeriodTimeUnit.MONTHS),
7+
UNLIMITED(1200, AvailabilityPeriodTimeUnit.MONTHS);
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.ecwid.apiclient.v3.dto.profile.enums
2+
3+
@Suppress("unused")
4+
enum class FulfilmentType {
5+
pickup, shipping, delivery
6+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.ecwid.apiclient.v3.dto.profile.enums
2+
3+
@Suppress("unused")
4+
enum class RatesCalculationType {
5+
6+
carrier_calculated,
7+
table,
8+
flat,
9+
app;
10+
11+
override fun toString(): String {
12+
return asApiString()
13+
}
14+
15+
fun asApiString(): String {
16+
return super.toString().replace("_", "-")
17+
}
18+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.ecwid.apiclient.v3.dto.profile.enums
2+
3+
@Suppress("unused")
4+
enum class ScheduledTimePrecisionType {
5+
DATE,
6+
DATE_AND_TIME_SLOT,
7+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package com.ecwid.apiclient.v3.dto.profile.request
2+
3+
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO
4+
import com.ecwid.apiclient.v3.dto.profile.enums.*
5+
import com.ecwid.apiclient.v3.dto.profile.result.FetchedShippingOption
6+
import java.util.*
7+
8+
data class UpdatedShippingOption(
9+
val id: String? = null,
10+
val appClientId: String? = null,
11+
val title: String? = null,
12+
val titleTranslated: Map<String, String>? = null,
13+
val description: String? = null,
14+
val descriptionTranslated: Map<String, String>? = null,
15+
val enabled: Boolean? = null,
16+
val orderBy: Int? = null,
17+
val fulfilmentType: FulfilmentType? = null,
18+
val minimumOrderSubtotal: Double? = null,
19+
val destinationZone: Zone? = null,
20+
val ratesCalculationType: RatesCalculationType? = null,
21+
val locationId: String? = null,
22+
val flatRate: FlatRate? = null,
23+
val shippingCostMarkup: Double? = null,
24+
val ratesTable: TableRates? = null,
25+
val pickupInstruction: String? = null,
26+
val pickupInstructionTranslated: Map<String, String>? = null,
27+
val pickupPreparationTimeHours: Int? = null,
28+
val pickupBusinessHours: String? = null,
29+
val scheduledPickup: Boolean? = null,
30+
val type: String? = null,
31+
val carrier: String? = null,
32+
val carrierMethods: List<CarrierMethod>? = null,
33+
val carrierSettings: CarrierSettings? = null,
34+
val businessHours: BusinessHours? = null,
35+
val businessHoursLimitationType: ApiBusinessHoursLimitationType? = null,
36+
val allowSameDayDelivery: Boolean? = null,
37+
val deliveryTimeDays: String? = null,
38+
val availabilityPeriod: AvailabilityPeriodType? = null,
39+
val customAvailabilityPeriodInDays: Int? = null,
40+
val scheduled: Boolean? = null,
41+
val scheduledTimePrecisionType: ScheduledTimePrecisionType? = null,
42+
val timeSlotLengthInMinutes: Int? = null,
43+
val cutoffTimeForSameDayDelivery: String? = null,
44+
val fulfillmentTimeInMinutes: Int? = null,
45+
val blackoutDates: List<BlackoutPeriodItem>? = null,
46+
val estimatedShippingTimeAtCheckoutSettings: EstimatedShippingTimeAtCheckoutSettings? = null,
47+
) : ApiUpdatedDTO {
48+
data class Zone(
49+
val id: String? = null,
50+
val name: String? = null,
51+
val countryCodes: List<String>? = null,
52+
val stateOrProvinceCodes: List<String>? = null,
53+
val postCodes: List<String>? = null,
54+
)
55+
56+
data class FlatRate(
57+
val rateType: String? = null,
58+
val rate: Double? = null,
59+
)
60+
61+
data class TableRates(
62+
val tableBasedOn: String? = null,
63+
val rates: List<Rates>? = null,
64+
)
65+
66+
data class Rates(
67+
val conditions: Conditions? = null,
68+
val rate: Rate? = null,
69+
)
70+
71+
data class Conditions(
72+
val subtotalFrom: Double? = null,
73+
val subtotalTo: Double? = null,
74+
val discountedSubtotalFrom: Double? = null,
75+
val discountedSubtotalTo: Double? = null,
76+
val weightFrom: Double? = null,
77+
val weightTo: Double? = null,
78+
)
79+
80+
data class Rate(
81+
val perOrder: Double? = null,
82+
val percent: Double? = null,
83+
val perItem: Double? = null,
84+
val perWeight: Double? = null,
85+
)
86+
87+
data class CarrierMethod(
88+
val id: String? = null,
89+
val name: String? = null,
90+
val enabled: Boolean? = null,
91+
val orderBy: Int? = null
92+
)
93+
94+
data class BlackoutPeriodItem(
95+
val fromDate: Date? = null,
96+
val toDate: Date? = null,
97+
val repeatedAnnually: Boolean? = null,
98+
)
99+
100+
data class EstimatedShippingTimeAtCheckoutSettings(
101+
val estimatedDeliveryDateAtCheckoutEnabled: Boolean? = null,
102+
val estimatedTransitTimeInDays: List<Int>? = null,
103+
val fulfillmentTimeInDays: List<Int>? = null,
104+
val shippingBusinessDays: List<String>? = null,
105+
val deliveryDays: List<String>? = null,
106+
val cutoffTimeForSameDayPacking: String? = null,
107+
)
108+
109+
data class CarrierSettings(
110+
val defaultCarrierAccountEnabled: Boolean? = null,
111+
val defaultPostageDimensions: DefaultPostageDimensions? = null
112+
)
113+
114+
data class DefaultPostageDimensions(
115+
val length: Double? = null,
116+
val width: Double? = null,
117+
val height: Double? = null
118+
)
119+
120+
override fun getModifyKind(): ApiUpdatedDTO.ModifyKind {
121+
return ApiUpdatedDTO.ModifyKind.ReadWrite(FetchedShippingOption::class)
122+
}
123+
}
124+
125+
typealias BusinessHours = Map<String, List<List<String>>>

0 commit comments

Comments
 (0)