Open aldy505 opened 1 year ago
It should be put on a sub-package under the repository package. The logic on how the pricing works is totally up to you. If possible, please include unit tests.
repository
https://github.com/TokoBapak/mock-shipping-provider/blob/68058d64cc9b8f7db73478fd0a1392055c5c8d45/repository/provider_calculation.go#L5-L10
Providers are defined here:
https://github.com/TokoBapak/mock-shipping-provider/blob/413bb3e6abb6362ced4b4bdc42173c1c82f6065d/primitive/provider.go#L6-L12
Example:
type JNE struct{} func (JNE) CalculatePrice(distance float64, dimension primitive.Dimension, weight float64) int64 { var basePrice = 9000 // Multiply basePrice by volume var volume = dimension.Width * dimension.Height * dimension.Depth // 1 hop every 200 km var hops float64 if distance < 1 { hops = 1 } else { hops = distance / 200 // division by 0 causes panic, avoid that! } return basePrice * int64(volume) * hops } func (JNE) CalculateTimeOfArrival(distance float64) int64 { return 0 // do it yourself }
That's just an example, you don't have to follow it. Be creative.
It should be put on a sub-package under the
repository
package. The logic on how the pricing works is totally up to you. If possible, please include unit tests.https://github.com/TokoBapak/mock-shipping-provider/blob/68058d64cc9b8f7db73478fd0a1392055c5c8d45/repository/provider_calculation.go#L5-L10
Providers are defined here:
https://github.com/TokoBapak/mock-shipping-provider/blob/413bb3e6abb6362ced4b4bdc42173c1c82f6065d/primitive/provider.go#L6-L12
Example:
That's just an example, you don't have to follow it. Be creative.