mock mode: database queries implemented and checkbox on account page built

This commit is contained in:
2026-02-26 22:54:58 -07:00
parent 85817a4adb
commit c6b8a9a00d
10 changed files with 278 additions and 27 deletions
+28
View File
@@ -37,6 +37,8 @@ func Routes(
r.POST("", response.Handler(as.createAccount))
// TODO: make the subroutes more readable
platformGroup := r.Group("/:acctID/platforms/:platform", pub.Publish("/:acctID/platforms"))
platformGroup.PUT("/order-index", response.Handler(as.setOrderOfPlatformOnAccountPage))
platformGroup.POST("/shops/mocks", response.Handler(as.createMockShop))
@@ -55,6 +57,9 @@ func Routes(
draftListings.PUT("/:orderIndex/listing", response.Handler(as.setListingInSyncGroupListingDraft))
draftListings.DELETE("/:orderIndex", response.Handler(as.deleteSyncGroupListingDraft))
mockModeGroup := r.Group("/:acctID/mock-mode", pub.Publish("/:acctID/mock-mode"))
mockModeGroup.PUT("", response.Handler(as.setMockMode))
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))
@@ -500,6 +505,29 @@ func (s *accountSubrouter) deleteMockSyncGroupListingDraft(c *gin.Context) (resp
return response.StatusOK(), nil
}
// PUT /:acctID/mock-mode
func (s *accountSubrouter) setMockMode(c *gin.Context) (response.Response, error) {
r := c.Request
ctx := r.Context()
acctID := auth.GetIdentity(ctx).Account.AccountID
var (
on bool
)
err := param.Form("on", param.Bool(&on)).
Unmarshal(c)
if err != nil {
return nil, err
}
if err := s.accts.SetMockMode(ctx, acctID, on); err != nil {
return nil, response.Errorf("failed to set mock mode: %w", response.ErrorFromConstant(err))
}
return response.StatusOK(), nil
}
// POST /:acctID/inventory/sync-groups/mock
func (s *accountSubrouter) saveNewMockSyncGroup(c *gin.Context) (response.Response, error) {
r := c.Request
+14
View File
@@ -21,6 +21,10 @@ func Int64(dst *int64) encoding.TextUnmarshaler {
return (*int64Text)(dst)
}
func Bool(dst *bool) encoding.TextUnmarshaler {
return (*boolText)(dst)
}
func Platform(dst *accounts.Platform) encoding.TextUnmarshaler {
return (*platformText)(dst)
}
@@ -29,6 +33,7 @@ type (
rawText string
intText int
int64Text int64
boolText bool
platformText accounts.Platform
)
@@ -55,6 +60,15 @@ func (n *int64Text) UnmarshalText(text []byte) error {
return nil
}
func (b *boolText) UnmarshalText(text []byte) error {
v, err := strconv.ParseBool(string(text))
if err != nil {
return err
}
*b = boolText(v)
return nil
}
func (p *platformText) UnmarshalText(text []byte) error {
v, err := accounts.NewPlatform(string(text))
if err != nil {
+14 -2
View File
@@ -167,10 +167,22 @@ func ErrorFromConstant(err error) error {
cerr := err
for cerr != nil {
switch cerr {
// if the error already is an ErrorResponse with the appropriate status, nothing needs to be done.
// else the error needs to be wrapped in the appropriate ErrorResponse.
case consts.ErrNotFound:
return NotFound()
if er, ok := GetError(err); ok {
if s, ok := er.GetStatus(); ok && s == http.StatusNotFound {
return err
}
}
return NotFound().Wrap(err)
case consts.ErrConflict:
return Conflict()
if er, ok := GetError(err); ok {
if s, ok := er.GetStatus(); ok && s == http.StatusConflict {
return err
}
}
return Conflict().Wrap(err)
}
uerr, ok := cerr.(interface {