TokoBapak / mock-shipping-provider

Mock shipping provider
Apache License 2.0
0 stars 3 forks source link

Implement shipping service (business layer) #2

Open aldy505 opened 1 year ago

aldy505 commented 1 year ago

Unit tests can come later when the repository tests are finished. But you can try and execute the function that are defined by the repository interface.

https://github.com/TokoBapak/mock-shipping-provider/blob/413bb3e6abb6362ced4b4bdc42173c1c82f6065d/business/shipping/shipping.go#L17-L32

Interface definition:

https://github.com/TokoBapak/mock-shipping-provider/blob/68058d64cc9b8f7db73478fd0a1392055c5c8d45/business/shipping.go#L11-L24

The background worker on the Create function is a simple goroutine that is managed by a time.Sleep. So basically it goes like this:

func Create(ctx context.Context, request business.CreateRequest) (business.CreateResponse, error) {
  var orderHistory = []OrderHistory{
    {
      Status: primitive.StatusOrderPlaced,
      Timestamp: time.Now(),
    },
    {
      Status: primitive.StatusPickupPending,
      Timestamp: time.Now().Add(time.Minute),
    },
    {
      Status: primitive.StatusPickedUp,
      Timestamp: time.Now().Add(time.Hour * 2),
   }, // and so on forth
  }

  // Insert the order history to the database
  go func() {
    for i, entry := range orderHistory {
      if entry.Status == primitive.StatusOrderPlaced {
        continue
      }

      time.Sleep(entry.Timestamp.Sub(orderHistory[i-1].Timestamp))
      // Send webhook
    }
  }()
}

The example above can be wrong. Please test your function accordingly.

WahidinAji commented 1 year ago

btw, I think this return should be non-array status-history

'cuz. when we see the response sample of the StatusHistory and the Struct of it. its just history that given the array to the response.

{
    "reference_number": "string",
    "air_waybill": "string",
    "history": [
        {
            "status_code": 1,
            "status_description": "ORDER_PLACED",
            "timestamp": "2023-01-01T00:00:00Z",
            "note": "string"
        }
    ]
}

I found this issue while I tried to handle the presentation-layer.

aldy505 commented 1 year ago

btw, I think this return should be non-array status-history

'cuz. when we see the response sample of the StatusHistory and the Struct of it. its just history that given the array to the response.

{
    "reference_number": "string",
    "air_waybill": "string",
    "history": [
        {
            "status_code": 1,
            "status_description": "ORDER_PLACED",
            "timestamp": "2023-01-01T00:00:00Z",
            "note": "string"
        }
    ]
}

I found this issue while I tried to handle the presentation-layer.

Oh you're right. You can change that one.

YogiPristiawan commented 1 year ago

I think the shipping.Estimate() should return an array of EstimateResult with included Provider, because in the presentation we expect array of Estimation to be returned as response

https://github.com/TokoBapak/mock-shipping-provider/blob/68058d64cc9b8f7db73478fd0a1392055c5c8d45/presentation/schema/estimate_response.go#L10

WahidinAji commented 1 year ago

we've already discussed this btw. but yes, you're right

YogiPristiawan commented 1 year ago

we've already discussed this btw. but yes, you're right

you are discussed about StatusHistory 😅

WahidinAji commented 1 year ago

nope, we discuss it on private chat a few days ago.

WahidinAji commented 1 year ago

here's the actual how the interface looks like image

YogiPristiawan commented 1 year ago

Again, should we change the request method for /status-history into POST? Because the StatusRequest struct in the package business requires some fields https://github.com/TokoBapak/mock-shipping-provider/blob/68058d64cc9b8f7db73478fd0a1392055c5c8d45/business/shipping.go#L65-L68

aldy505 commented 1 year ago

Again, should we change the request method for /status-history into POST? Because the StatusRequest struct in the package business requires some fields

https://github.com/TokoBapak/mock-shipping-provider/blob/68058d64cc9b8f7db73478fd0a1392055c5c8d45/business/shipping.go#L65-L68

What you're specifying is business layer, it's not the same as presentation layer. Remember, the business layer does not care about what happens on the presentation layer. Presentation layer can get the values from the URL parameters. Nothing's wrong with that.

YogiPristiawan commented 1 year ago

so, what's the StatusRequest used for? Where can we get the required data? is it from the query parameters?