account page: can now reorder entries under shops sections by drag and drop
This commit is contained in:
@@ -2,6 +2,7 @@ package accounts
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -32,9 +33,10 @@ func Routes(
|
||||
}
|
||||
|
||||
r.POST("", response.Handler(as.createAccount))
|
||||
r.PUT("/:acctID/platforms/:platform/order-index", pub.Publish("/:acctID/platforms"), response.Handler(as.setOrderOfPlatformOnAccountPage))
|
||||
|
||||
syncGroups := r.Group("/:acctID/inventory/sync-groups")
|
||||
syncGroups.POST("", response.Handler(as.saveNewSyncGroup))
|
||||
syncGroups.POST("", pub.Publish("/:acctID/inventory/sync-groups"), response.Handler(as.saveNewSyncGroup))
|
||||
|
||||
draftListings := syncGroups.Group("/draft/listings", pub.Publish("/:acctID/inventory/sync-groups/draft/listings"))
|
||||
draftListings.POST("", response.Handler(as.createSyncGroupListingDraft))
|
||||
@@ -184,3 +186,39 @@ func getOrderIndexForSyncGroupListingDraftFromPath(c *gin.Context) (int, error)
|
||||
|
||||
return orderIndex, nil
|
||||
}
|
||||
|
||||
func (s *accountSubrouter) setOrderOfPlatformOnAccountPage(c *gin.Context) (response.Response, error) {
|
||||
acctID := auth.GetIdentity(c).Account.AccountID
|
||||
|
||||
var orderIndex int
|
||||
if v, ok := c.GetPostForm("order-index"); !ok {
|
||||
return nil, response.BadRequest().
|
||||
Msg("no order-index provided")
|
||||
} else if i, err := strconv.Atoi(v); err != nil {
|
||||
return nil, response.BadRequest().
|
||||
Msgf("order-index must be a non-negative integer: %s", v)
|
||||
} else if i < 0 {
|
||||
return nil, response.BadRequest().
|
||||
Msgf("order-index must be a non-negative integer: %s", v)
|
||||
} else {
|
||||
orderIndex = i
|
||||
}
|
||||
|
||||
var platform accounts.Platform
|
||||
if v := c.Param("platform"); v == "" {
|
||||
return nil, response.BadRequest().
|
||||
Msg("no platform provided")
|
||||
} else if p, err := accounts.NewPlatform(v); err != nil {
|
||||
return nil, response.BadRequest().
|
||||
Wrap(err).
|
||||
Msgf("unrecognized platform: %v", v)
|
||||
} else {
|
||||
platform = p
|
||||
}
|
||||
|
||||
if err := s.accts.SetOrderOfPlatformOnAccountPage(c, acctID, platform, orderIndex); err != nil {
|
||||
return nil, fmt.Errorf("failed to save record: %w", err)
|
||||
}
|
||||
|
||||
return response.Status(200), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user