Skip to content
Permalink
Browse files

Parallel buy

  • Loading branch information...
takonomura committed Sep 8, 2019
1 parent c6947ac commit ce3e0853becfc060c5e94aa030e4c040de7c4f66
Showing with 22 additions and 13 deletions.
  1. +22 −13 isucari/webapp/go/main.go
@@ -1499,19 +1499,19 @@ func postBuy(w http.ResponseWriter, r *http.Request) {
return
}

scr, err := APIShipmentCreate(r.Context(), getShipmentServiceURL(r.Context()), &APIShipmentCreateReq{
ToAddress: buyer.Address,
ToName: buyer.AccountName,
FromAddress: seller.Address,
FromName: seller.AccountName,
})
if err != nil {
log.Print(err)
outputErrorMsg(w, http.StatusInternalServerError, "failed to request to shipment service")
tx.Rollback()

return
}
var scr *APIShipmentCreateRes
var scrErr error
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
scr, scrErr = APIShipmentCreate(r.Context(), getShipmentServiceURL(r.Context()), &APIShipmentCreateReq{
ToAddress: buyer.Address,
ToName: buyer.AccountName,
FromAddress: seller.Address,
FromName: seller.AccountName,
})
}()

pstr, err := APIPaymentToken(r.Context(), getPaymentServiceURL(r.Context()), &APIPaymentServiceTokenReq{
ShopID: PaymentServiceIsucariShopID,
@@ -1527,6 +1527,15 @@ func postBuy(w http.ResponseWriter, r *http.Request) {
return
}

wg.Wait()
if scrErr != nil {
log.Print(err)
outputErrorMsg(w, http.StatusInternalServerError, "failed to request to shipment service")
tx.Rollback()

return
}

if pstr.Status == "invalid" {
outputErrorMsg(w, http.StatusBadRequest, "カード情報に誤りがあります")
tx.Rollback()

0 comments on commit ce3e085

Please sign in to comment.
You can’t perform that action at this time.