diff --git a/internal/domains/accounts/mocks.go b/internal/domains/accounts/mocks.go index 4101641..cf5193d 100644 --- a/internal/domains/accounts/mocks.go +++ b/internal/domains/accounts/mocks.go @@ -309,7 +309,7 @@ func (db *Store) CreateMockListing(ctx context.Context, listing MockListing) (Mo "sku": listing.SKU, "name": listing.Name, "description": listing.Description, - "count": listing.Count + 5, + "count": listing.Count, }, ) if err != nil { @@ -322,6 +322,49 @@ func (db *Store) CreateMockListing(ctx context.Context, listing MockListing) (Mo return listing, nil } +// UpdateMockListing updates a mock listing, but not it's count +func (db *Store) UpdateMockListing(ctx context.Context, listing MockListing) error { + _, listingTableName, err := getMockShopAndListingsTableNames(listing.Platform) + if err != nil { + return err + } + + tag, err := db.db.Exec( + ctx, + fmt.Sprintf( + ` + UPDATE + %s + SET + sku = @sku, + name = @name, + description = @description + WHERE + account_id = @account_id + AND shop_id = @shop_id + AND listing_id = @listing_id + `, + listingTableName, + ), + pgx.NamedArgs{ + "account_id": listing.AccountID, + "shop_id": listing.ShopID, + "listing_id": listing.ListingID, + "sku": listing.SKU, + "name": listing.Name, + "description": listing.Description, + }, + ) + if err != nil { + return fmt.Errorf("failed to perform query: %w", err) + } + if tag.RowsAffected() == 0 { + return fmt.Errorf("%w: listing not found", consts.ErrNotFound) + } + + return nil +} + func (db *Store) ListMockListingsForShop(ctx context.Context, acctID int64, platform Platform, shopID string) ([]MockListing, error) { shopTableName, listingsTableName, err := getMockShopAndListingsTableNames(platform) if err != nil { diff --git a/internal/domains/accounts/store_with_context.go b/internal/domains/accounts/store_with_context.go index 17d93ba..58dcb59 100644 --- a/internal/domains/accounts/store_with_context.go +++ b/internal/domains/accounts/store_with_context.go @@ -68,6 +68,10 @@ func (v_ctx *StoreWithContext) CreateMockListing(listing MockListing) (MockListi return v_ctx.Store.CreateMockListing(v_ctx.ctx, listing) } +func (v_ctx *StoreWithContext) UpdateMockListing(listing MockListing) error { + return v_ctx.Store.UpdateMockListing(v_ctx.ctx, listing) +} + func (v_ctx *StoreWithContext) ListMockListingsForShop(acctID int64, platform Platform, shopID string) ([]MockListing, error) { return v_ctx.Store.ListMockListingsForShop(v_ctx.ctx, acctID, platform, shopID) } diff --git a/internal/server/api/accounts/router.go b/internal/server/api/accounts/router.go index 102e799..c196f23 100644 --- a/internal/server/api/accounts/router.go +++ b/internal/server/api/accounts/router.go @@ -43,6 +43,7 @@ func Routes( mockShops := platformGroup.Group("/shops/mocks/:shop-id") mockShops.POST("/listings", response.Handler(as.addMockListing)) + mockShops.PUT("/listings/:listing-id", response.Handler(as.updateMockListing)) syncGroups := r.Group("/:acctID/inventory/sync-groups") syncGroups.POST("", pub.Publish("/:acctID/inventory/sync-groups"), response.Handler(as.saveNewSyncGroup)) @@ -304,7 +305,49 @@ func (s *accountSubrouter) addMockListing(c *gin.Context) (response.Response, er return nil, fmt.Errorf("failed to create new listing: %w", err) } - return nil, nil + return response.StatusCreated(), nil +} + +// PUT /:acctID/platforms/:platform/shops/mocks/:shop-id/listings/:listing-id +func (s *accountSubrouter) updateMockListing(c *gin.Context) (response.Response, error) { + acctID := auth.GetIdentity(c).Account.AccountID + + var ( + platform accounts.Platform + shopID string + listingID string + name string + sku string + description string + ) + + err := param.Path("platform", param.Platform(&platform)). + Path("shop-id", param.Text(&shopID)). + Path("listing-id", param.Text(&listingID)). + Form("name", param.Text(&name)). + Form("sku", param.Text(&sku)). + Form("description", param.Text(&description)). + Unmarshal(c) + if err != nil { + return nil, err + } + + err = s.accts.UpdateMockListing( + c, + accounts.MockListing{ + AccountShopListingIDs: accounts.NewAccountIDs(acctID). + ShopID(platform, shopID). + ListingID(listingID), + Name: name, + SKU: sku, + Description: description, + }, + ) + if err != nil { + return nil, fmt.Errorf("failed to update new listing: %w", err) + } + + return response.StatusOK(), nil } func lowerSnakeCase(s accounts.Platform) string { diff --git a/styles/index.css b/styles/index.css index 024b15f..60d3a4e 100644 --- a/styles/index.css +++ b/styles/index.css @@ -193,6 +193,9 @@ .col-3 { grid-column: 3; } + .col-\[span_2\] { + grid-column: span 2; + } .col-span-2 { grid-column: span 2 / span 2; } @@ -265,9 +268,6 @@ .ml-\[1em\] { margin-left: 1em; } - .box-border { - box-sizing: border-box; - } .block { display: block; } @@ -355,9 +355,6 @@ .list-none { list-style-type: none; } - .grid-cols-\[1fr_1fr\] { - grid-template-columns: 1fr 1fr; - } .grid-cols-\[2fr_8fr_2fr\] { grid-template-columns: 2fr 8fr 2fr; } @@ -799,11 +796,6 @@ padding-block: calc(8vw - 0.5em); } } - .sm\:grid-cols-\[1fr_1fr\] { - @media (width >= 40rem) { - grid-template-columns: 1fr 1fr; - } - } .md\:grid-cols-\[1fr_1fr\] { @media (width >= 48rem) { grid-template-columns: 1fr 1fr; diff --git a/templates/pages/accounts/{acctID.int64}/platforms/{platform}/shops/mocks/{shopID}/index.html.tmpl b/templates/pages/accounts/{acctID.int64}/platforms/{platform}/shops/mocks/{shopID}/index.html.tmpl index 1566cd0..313abf2 100644 --- a/templates/pages/accounts/{acctID.int64}/platforms/{platform}/shops/mocks/{shopID}/index.html.tmpl +++ b/templates/pages/accounts/{acctID.int64}/platforms/{platform}/shops/mocks/{shopID}/index.html.tmpl @@ -27,9 +27,32 @@ -
+
+

+ New Listing +

{{ component "button" - "Text" "Save Listing" + "Text" "Save" "Class" "self-center p-[1em] col-span-2" - "_" "on click send reset() to
  • in next
      " + "ID" "save-as-new-listing-button" + }} + + +