mock events saved to db
This commit is contained in:
@@ -79,10 +79,13 @@ func Routes(
|
||||
mockSyncGroupBeingEdited.PUT("/listings/:orderIndex/listing", response.Handler(as.setListingInListingInMockSyncGroupBeingEdited))
|
||||
mockSyncGroupBeingEdited.DELETE("/listings/:orderIndex", response.Handler(as.deleteListingInListingInMockSyncGroupBeingEdited))
|
||||
|
||||
simulations := r.Group("/:acctID/simulations")
|
||||
simulations.POST("/sale", response.Handler(as.postNewSale))
|
||||
simulations.POST("/refund", response.Handler(as.postNewRefund))
|
||||
simulations.PUT("/shops/:shopID/listings/:listingID/count", response.Handler(as.setListingCount))
|
||||
simulations := r.Group("/:acctID/simulations", pub.Publish("/:acctID/simulations"))
|
||||
simulations.PUT("/sale/form/shop", response.Handler(as.setShopInMockSaleForm))
|
||||
simulations.POST("/sale", response.Handler(as.postNewMockSale))
|
||||
simulations.PUT("/refund/form/shop", response.Handler(as.setShopInMockRefundForm))
|
||||
simulations.POST("/refund", response.Handler(as.postNewMockRefund))
|
||||
simulations.PUT("/count/form/shop", response.Handler(as.setShopInMockCountForm))
|
||||
simulations.PUT("/shops/:shopID/listings/:listingID/count", response.Handler(as.setMockListingCount))
|
||||
}
|
||||
|
||||
// POST /
|
||||
@@ -741,80 +744,146 @@ func (s *accountSubrouter) deleteListingInListingInMockSyncGroupBeingEdited(c *g
|
||||
return response.StatusOK(), nil
|
||||
}
|
||||
|
||||
// POST /:acctID/simulations/sale
|
||||
func (s *accountSubrouter) postNewSale(c *gin.Context) (response.Response, error) {
|
||||
// PUT /:acctID/simulations/sale/form/shop
|
||||
func (s *accountSubrouter) setShopInMockSaleForm(c *gin.Context) (response.Response, error) {
|
||||
acctID := auth.GetIdentity(c).Account.AccountID
|
||||
|
||||
var (
|
||||
platform accounts.Platform
|
||||
shopID string
|
||||
)
|
||||
|
||||
if err := param.Form("platform", param.Platform(&platform)).
|
||||
Form("shop-id", param.Text(&shopID)).
|
||||
Unmarshal(c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := s.accts.SetShopInMockSaleForm(c, acctID, platform, shopID); err != nil {
|
||||
return nil, fmt.Errorf("failed to set shop in mock sale form: %w", err)
|
||||
}
|
||||
|
||||
return response.StatusOK(), nil
|
||||
}
|
||||
|
||||
// POST /:acctID/simulations/sale
|
||||
func (s *accountSubrouter) postNewMockSale(c *gin.Context) (response.Response, error) {
|
||||
acctID := auth.GetIdentity(c).Account.AccountID
|
||||
|
||||
var (
|
||||
platform accounts.Platform
|
||||
shopID string
|
||||
listingID string
|
||||
count int
|
||||
)
|
||||
|
||||
if err := param.Form("shop-id", param.Text(&shopID)).
|
||||
if err := param.Form("platform", param.Platform(&platform)).
|
||||
Form("shop-id", param.Text(&shopID)).
|
||||
Form("listing-id", param.Text(&listingID)).
|
||||
Form("count", param.Int(&count)).
|
||||
Unmarshal(c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.log.Debugf("sale posted:")
|
||||
s.log.Debugf(" account: %d", acctID)
|
||||
s.log.Debugf(" shop: %s", shopID)
|
||||
s.log.Debugf(" listing: %s", listingID)
|
||||
s.log.Debugf(" count: %d", count)
|
||||
if _, err := s.accts.SaveNewMockSale(c, acctID, platform, shopID, listingID, count); err != nil {
|
||||
return nil, fmt.Errorf("failed to save new mock sale: %w", err)
|
||||
}
|
||||
|
||||
return response.StatusCreated(), nil
|
||||
}
|
||||
|
||||
// PUT /:acctID/simulations/refund/form/shop
|
||||
func (s *accountSubrouter) setShopInMockRefundForm(c *gin.Context) (response.Response, error) {
|
||||
acctID := auth.GetIdentity(c).Account.AccountID
|
||||
|
||||
var (
|
||||
platform accounts.Platform
|
||||
shopID string
|
||||
)
|
||||
|
||||
if err := param.Form("platform", param.Platform(&platform)).
|
||||
Form("shop-id", param.Text(&shopID)).
|
||||
Unmarshal(c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := s.accts.SetShopInMockRefundForm(c, acctID, platform, shopID); err != nil {
|
||||
return nil, fmt.Errorf("failed to set shop in mock refund form: %w", err)
|
||||
}
|
||||
|
||||
return response.StatusOK(), nil
|
||||
}
|
||||
|
||||
// POST /:acctID/simulations/refund
|
||||
func (s *accountSubrouter) postNewRefund(c *gin.Context) (response.Response, error) {
|
||||
func (s *accountSubrouter) postNewMockRefund(c *gin.Context) (response.Response, error) {
|
||||
acctID := auth.GetIdentity(c).Account.AccountID
|
||||
|
||||
var (
|
||||
platform accounts.Platform
|
||||
shopID string
|
||||
listingID string
|
||||
count int
|
||||
)
|
||||
|
||||
if err := param.Form("shop-id", param.Text(&shopID)).
|
||||
if err := param.Form("platform", param.Platform(&platform)).
|
||||
Form("shop-id", param.Text(&shopID)).
|
||||
Form("listing-id", param.Text(&listingID)).
|
||||
Form("count", param.Int(&count)).
|
||||
Unmarshal(c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.log.Debugf("refund posted:")
|
||||
s.log.Debugf(" account: %d", acctID)
|
||||
s.log.Debugf(" shop: %s", shopID)
|
||||
s.log.Debugf(" listing: %s", listingID)
|
||||
s.log.Debugf(" count: %d", count)
|
||||
if _, err := s.accts.SaveNewMockRefund(c, acctID, platform, shopID, listingID, count); err != nil {
|
||||
return nil, fmt.Errorf("failed to save new mock refund: %w", err)
|
||||
}
|
||||
|
||||
return response.StatusCreated(), nil
|
||||
}
|
||||
|
||||
// PUT /:acctID/simulations/shops/:shopID/listings/:listingID/count
|
||||
func (s *accountSubrouter) setListingCount(c *gin.Context) (response.Response, error) {
|
||||
// PUT /:acctID/simulations/count/form/shop
|
||||
func (s *accountSubrouter) setShopInMockCountForm(c *gin.Context) (response.Response, error) {
|
||||
acctID := auth.GetIdentity(c).Account.AccountID
|
||||
|
||||
var (
|
||||
platform accounts.Platform
|
||||
shopID string
|
||||
)
|
||||
|
||||
if err := param.Form("platform", param.Platform(&platform)).
|
||||
Form("shop-id", param.Text(&shopID)).
|
||||
Unmarshal(c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := s.accts.SetShopInMockCountForm(c, acctID, platform, shopID); err != nil {
|
||||
return nil, fmt.Errorf("failed to set shop in mock count form: %w", err)
|
||||
}
|
||||
|
||||
return response.StatusOK(), nil
|
||||
}
|
||||
|
||||
// PUT /:acctID/simulations/shops/:shopID/listings/:listingID/count
|
||||
func (s *accountSubrouter) setMockListingCount(c *gin.Context) (response.Response, error) {
|
||||
acctID := auth.GetIdentity(c).Account.AccountID
|
||||
|
||||
var (
|
||||
platform accounts.Platform
|
||||
shopID string
|
||||
listingID string
|
||||
count int
|
||||
)
|
||||
|
||||
if err := param.Path("shopID", param.Text(&shopID)).
|
||||
if err := param.Form("platform", param.Platform(&platform)).
|
||||
Path("shopID", param.Text(&shopID)).
|
||||
Path("listingID", param.Text(&listingID)).
|
||||
Form("count", param.Int(&count)).
|
||||
Unmarshal(c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.log.Debugf("listing inventory set:")
|
||||
s.log.Debugf(" account: %d", acctID)
|
||||
s.log.Debugf(" shop: %s", shopID)
|
||||
s.log.Debugf(" listing: %s", listingID)
|
||||
s.log.Debugf(" count: %d", count)
|
||||
if _, err := s.accts.SaveNewMockInventoryReset(c, acctID, platform, shopID, listingID, count); err != nil {
|
||||
return nil, fmt.Errorf("failed to save new mock inventory reset: %w", err)
|
||||
}
|
||||
|
||||
return response.StatusOK(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user