ability to delete mock sync groups
This commit is contained in:
@@ -56,6 +56,9 @@ func Routes(
|
||||
draftListings.DELETE("/:orderIndex", response.Handler(as.deleteSyncGroupListingDraft))
|
||||
|
||||
mockSyncGroups := syncGroups.Group("/mock")
|
||||
mockSyncGroups.POST("", pub.Publish("/:acctID/inventory/sync-groups/mock"), response.Handler(as.saveNewMockSyncGroup))
|
||||
mockSyncGroups.DELETE("/:syncGroupID", pub.Publish("/:acctID/inventory/sync-groups/mock"), response.Handler(as.deleteMockSyncGroup))
|
||||
|
||||
mockDraftListings := mockSyncGroups.Group("/draft/listings", pub.Publish("/:acctID/inventory/sync-groups/mock/draft/listings"))
|
||||
mockDraftListings.POST("", response.Handler(as.createMockSyncGroupListingDraft))
|
||||
mockDraftListings.PUT("/:orderIndex/shop", response.Handler(as.setShopInMockSyncGroupListingDraft))
|
||||
@@ -486,6 +489,51 @@ func (s *accountSubrouter) deleteMockSyncGroupListingDraft(c *gin.Context) (resp
|
||||
return response.StatusOK(), nil
|
||||
}
|
||||
|
||||
// POST /:acctID/inventory/sync-groups/mock
|
||||
func (s *accountSubrouter) saveNewMockSyncGroup(c *gin.Context) (response.Response, error) {
|
||||
r := c.Request
|
||||
ctx := r.Context()
|
||||
acctID := auth.GetIdentity(ctx).Account.AccountID
|
||||
|
||||
var (
|
||||
name string
|
||||
)
|
||||
|
||||
err := param.Form("name", param.Text(&name)).
|
||||
Unmarshal(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err := s.accts.SaveNewMockSyncGroup(ctx, acctID, name); err != nil {
|
||||
return nil, response.Errorf("failed to save new mock sync group: %w", response.ErrorFromConstant(err))
|
||||
}
|
||||
|
||||
return response.StatusCreated(), nil
|
||||
}
|
||||
|
||||
// DELETE /:acctID/inventory/sync-groups/mock/:syncGroupID
|
||||
func (s *accountSubrouter) deleteMockSyncGroup(c *gin.Context) (response.Response, error) {
|
||||
r := c.Request
|
||||
ctx := r.Context()
|
||||
acctID := auth.GetIdentity(ctx).Account.AccountID
|
||||
|
||||
var (
|
||||
syncGroupID int64
|
||||
)
|
||||
|
||||
if err := param.Path("syncGroupID", param.Int64(&syncGroupID)).
|
||||
Unmarshal(c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := s.accts.DeleteMockSyncGroup(ctx, acctID, syncGroupID); err != nil {
|
||||
return nil, response.Errorf("failed to save new mock sync group: %w", response.ErrorFromConstant(err))
|
||||
}
|
||||
|
||||
return response.StatusCreated(), nil
|
||||
}
|
||||
|
||||
func lowerSnakeCase(s accounts.Platform) string {
|
||||
return strings.ToLower(strings.Join(strings.Split(string(s), " "), "_"))
|
||||
}
|
||||
|
||||
@@ -17,6 +17,10 @@ func Int(dst *int) encoding.TextUnmarshaler {
|
||||
return (*intText)(dst)
|
||||
}
|
||||
|
||||
func Int64(dst *int64) encoding.TextUnmarshaler {
|
||||
return (*int64Text)(dst)
|
||||
}
|
||||
|
||||
func Platform(dst *accounts.Platform) encoding.TextUnmarshaler {
|
||||
return (*platformText)(dst)
|
||||
}
|
||||
@@ -24,6 +28,7 @@ func Platform(dst *accounts.Platform) encoding.TextUnmarshaler {
|
||||
type (
|
||||
rawText string
|
||||
intText int
|
||||
int64Text int64
|
||||
platformText accounts.Platform
|
||||
)
|
||||
|
||||
@@ -41,6 +46,15 @@ func (n *intText) UnmarshalText(text []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *int64Text) UnmarshalText(text []byte) error {
|
||||
i, err := strconv.ParseInt(string(text), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*n = int64Text(i)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *platformText) UnmarshalText(text []byte) error {
|
||||
v, err := accounts.NewPlatform(string(text))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user