replaced sync-group api redirect response with 200s and 201s
This commit is contained in:
@@ -3,7 +3,6 @@ package accounts
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -44,6 +43,7 @@ func Routes(
|
||||
draftListings.DELETE("/:orderIndex", response.Handler(as.deleteSyncGroupListingDraft))
|
||||
}
|
||||
|
||||
// TODO: test this endpoint again, to make it work.
|
||||
// POST /
|
||||
func (s *accountSubrouter) createAccount(c *gin.Context) (response.Response, error) {
|
||||
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 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
|
||||
@@ -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 response.Redirect(
|
||||
http.StatusSeeOther,
|
||||
fmt.Sprintf("/ui/accounts/%d/inventory/sync-groups/draft/table", acctID),
|
||||
), nil
|
||||
return response.StatusCreated(), nil
|
||||
}
|
||||
|
||||
// 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 response.Redirect(
|
||||
http.StatusSeeOther,
|
||||
fmt.Sprintf("/ui/accounts/%d/inventory/sync-groups/draft/table", acctID),
|
||||
), nil
|
||||
return response.StatusOK(), nil
|
||||
}
|
||||
|
||||
// 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 response.Redirect(
|
||||
http.StatusSeeOther,
|
||||
fmt.Sprintf("/ui/accounts/%d/inventory/sync-groups/draft/table", acctID),
|
||||
), nil
|
||||
return response.StatusOK(), nil
|
||||
}
|
||||
|
||||
// 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 response.Redirect(
|
||||
http.StatusSeeOther,
|
||||
fmt.Sprintf("/ui/accounts/%d/inventory/sync-groups/draft/table", acctID),
|
||||
), nil
|
||||
return response.StatusOK(), nil
|
||||
}
|
||||
|
||||
// POST /:acctID/inventory/sync-groups
|
||||
@@ -173,16 +161,11 @@ func (s *accountSubrouter) saveNewSyncGroup(c *gin.Context) (response.Response,
|
||||
ctx := r.Context()
|
||||
acctID := auth.GetIdentity(ctx).Account.AccountID
|
||||
|
||||
grp, err := s.accts.SaveNewSyncGroup(ctx, acctID)
|
||||
if err != nil {
|
||||
if _, err := s.accts.SaveNewSyncGroup(ctx, acctID); err != nil {
|
||||
return nil, response.Errorf("failed to save new sync group: %w", response.ErrorFromConstant(err))
|
||||
}
|
||||
|
||||
return response.Redirect(
|
||||
http.StatusSeeOther,
|
||||
// TODO: template not implemented
|
||||
fmt.Sprintf("/ui/accounts/%d/inventory/sync-groups/%d", acctID, grp.SyncGroupID),
|
||||
), nil
|
||||
return response.StatusCreated(), nil
|
||||
}
|
||||
|
||||
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 {
|
||||
if s.res != nil {
|
||||
return fmt.Sprintf(`{"status": %d, "nested": %s}`, s.code, s.res)
|
||||
|
||||
Reference in New Issue
Block a user