Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement provider calculation for each providers (repository layer) #4

Open
aldy505 opened this issue Jan 1, 2023 · 0 comments
Open
Labels

Comments

@aldy505
Copy link
Member

aldy505 commented Jan 1, 2023

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.

type ProviderCalculation interface {
// CalculateTimeOfArrival calculates the time of arrival (in hours) based on distance.
CalculateTimeOfArrival(distance float64) int64
// CalculatePrice price from distance, dimension, and weight combination.
CalculatePrice(distance float64, dimension primitive.Dimension, weight float64) int64
}

Providers are defined here:

const (
ProviderUnspecified Provider = iota
ProviderJNE
ProviderSiCepat
ProviderJNT
ProviderAnterAja
)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant