replaced sync-group api redirect response with 200s and 201s
This commit is contained in:
@@ -3,7 +3,6 @@ package accounts
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -44,6 +43,7 @@ func Routes(
|
|||||||
draftListings.DELETE("/:orderIndex", response.Handler(as.deleteSyncGroupListingDraft))
|
draftListings.DELETE("/:orderIndex", response.Handler(as.deleteSyncGroupListingDraft))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: test this endpoint again, to make it work.
|
||||||
// POST /
|
// POST /
|
||||||
func (s *accountSubrouter) createAccount(c *gin.Context) (response.Response, error) {
|
func (s *accountSubrouter) createAccount(c *gin.Context) (response.Response, error) {
|
||||||
r := c.Request
|
r := c.Request
|
||||||
@@ -64,7 +64,7 @@ func (s *accountSubrouter) createAccount(c *gin.Context) (response.Response, err
|
|||||||
return nil, response.Errorf("failed to create account: %w", err)
|
return nil, response.Errorf("failed to create account: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.SeeOther(fmt.Sprintf("/api/accounts/%d", acct.AccountID)), nil
|
return response.SeeOther(fmt.Sprintf("/ui/accounts/%d", acct.AccountID)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST /:acctID/inventory/sync-groups/draft/listings
|
// POST /:acctID/inventory/sync-groups/draft/listings
|
||||||
@@ -77,10 +77,7 @@ func (s *accountSubrouter) createSyncGroupListingDraft(c *gin.Context) (response
|
|||||||
return nil, response.Errorf("failed to create new listing draft: %w", err)
|
return nil, response.Errorf("failed to create new listing draft: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.Redirect(
|
return response.StatusCreated(), nil
|
||||||
http.StatusSeeOther,
|
|
||||||
fmt.Sprintf("/ui/accounts/%d/inventory/sync-groups/draft/table", acctID),
|
|
||||||
), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT /:acctID/inventory/sync-groups/draft/listings/{orderIndex}/shop
|
// PUT /:acctID/inventory/sync-groups/draft/listings/{orderIndex}/shop
|
||||||
@@ -113,10 +110,7 @@ func (s *accountSubrouter) setShopInSyncGroupListingDraft(c *gin.Context) (respo
|
|||||||
return nil, response.Errorf("failed to set shop: %w", response.ErrorFromConstant(err))
|
return nil, response.Errorf("failed to set shop: %w", response.ErrorFromConstant(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.Redirect(
|
return response.StatusOK(), nil
|
||||||
http.StatusSeeOther,
|
|
||||||
fmt.Sprintf("/ui/accounts/%d/inventory/sync-groups/draft/table", acctID),
|
|
||||||
), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT /:acctID/inventory/sync-groups/draft/listings/{orderIndex}/listing
|
// PUT /:acctID/inventory/sync-groups/draft/listings/{orderIndex}/listing
|
||||||
@@ -140,10 +134,7 @@ func (s *accountSubrouter) setListingInSyncGroupListingDraft(c *gin.Context) (re
|
|||||||
return nil, response.Errorf("failed to set listing: %w", response.ErrorFromConstant(err))
|
return nil, response.Errorf("failed to set listing: %w", response.ErrorFromConstant(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.Redirect(
|
return response.StatusOK(), nil
|
||||||
http.StatusSeeOther,
|
|
||||||
fmt.Sprintf("/ui/accounts/%d/inventory/sync-groups/draft/table", acctID),
|
|
||||||
), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE /:acctID/inventory/sync-groups/draft/listings/{orderIndex}
|
// DELETE /:acctID/inventory/sync-groups/draft/listings/{orderIndex}
|
||||||
@@ -161,10 +152,7 @@ func (s *accountSubrouter) deleteSyncGroupListingDraft(c *gin.Context) (response
|
|||||||
return nil, response.Errorf("failed to delete listing: %w", response.ErrorFromConstant(err))
|
return nil, response.Errorf("failed to delete listing: %w", response.ErrorFromConstant(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.Redirect(
|
return response.StatusOK(), nil
|
||||||
http.StatusSeeOther,
|
|
||||||
fmt.Sprintf("/ui/accounts/%d/inventory/sync-groups/draft/table", acctID),
|
|
||||||
), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST /:acctID/inventory/sync-groups
|
// POST /:acctID/inventory/sync-groups
|
||||||
@@ -173,16 +161,11 @@ func (s *accountSubrouter) saveNewSyncGroup(c *gin.Context) (response.Response,
|
|||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
acctID := auth.GetIdentity(ctx).Account.AccountID
|
acctID := auth.GetIdentity(ctx).Account.AccountID
|
||||||
|
|
||||||
grp, err := s.accts.SaveNewSyncGroup(ctx, acctID)
|
if _, err := s.accts.SaveNewSyncGroup(ctx, acctID); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, response.Errorf("failed to save new sync group: %w", response.ErrorFromConstant(err))
|
return nil, response.Errorf("failed to save new sync group: %w", response.ErrorFromConstant(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.Redirect(
|
return response.StatusCreated(), nil
|
||||||
http.StatusSeeOther,
|
|
||||||
// TODO: template not implemented
|
|
||||||
fmt.Sprintf("/ui/accounts/%d/inventory/sync-groups/%d", acctID, grp.SyncGroupID),
|
|
||||||
), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getOrderIndexForSyncGroupListingDraftFromPath(c *gin.Context) (int, error) {
|
func getOrderIndexForSyncGroupListingDraftFromPath(c *gin.Context) (int, error) {
|
||||||
|
|||||||
@@ -23,6 +23,22 @@ func Status(code int) Response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StatusOK() Response {
|
||||||
|
return Status(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
func StatusCreated() Response {
|
||||||
|
return Status(http.StatusCreated)
|
||||||
|
}
|
||||||
|
|
||||||
|
func StatusAccepted() Response {
|
||||||
|
return Status(http.StatusAccepted)
|
||||||
|
}
|
||||||
|
|
||||||
|
func StatusNoContent() Response {
|
||||||
|
return Status(http.StatusNoContent)
|
||||||
|
}
|
||||||
|
|
||||||
func (s statusRes) String() string {
|
func (s statusRes) String() string {
|
||||||
if s.res != nil {
|
if s.res != nil {
|
||||||
return fmt.Sprintf(`{"status": %d, "nested": %s}`, s.code, s.res)
|
return fmt.Sprintf(`{"status": %d, "nested": %s}`, s.code, s.res)
|
||||||
|
|||||||
Reference in New Issue
Block a user