stubbed updating of saved mock listing

This commit is contained in:
2026-02-04 23:33:04 -07:00
parent 813fbb11b1
commit c61f291dba
3 changed files with 98 additions and 37 deletions
+15 -13
View File
@@ -8,6 +8,7 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
"github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
) )
type ( type (
@@ -354,8 +355,8 @@ func (db *Store) ListMockListingsForShop(ctx context.Context, acctID int64, plat
ON ON
TRUE TRUE
WHERE WHERE
account_id = @account_id (account_id IS NULL OR account_id = @account_id)
AND shop_id = @shop_id AND (shop_id IS NULL OR shop_id = @shop_id)
`, `,
shopTableName, shopTableName,
listingsTableName, listingsTableName,
@@ -371,11 +372,11 @@ func (db *Store) ListMockListingsForShop(ctx context.Context, acctID int64, plat
vs, err := pgx.CollectRows(rows, pgx.RowToStructByNameLax[struct { vs, err := pgx.CollectRows(rows, pgx.RowToStructByNameLax[struct {
Shop_exists bool Shop_exists bool
Listing_id string Listing_id pgtype.Text
SKU string SKU pgtype.Text
Name string Name pgtype.Text
Description string Description pgtype.Text
Count int64 Count pgtype.Int8
}]) }])
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to scan rows: %w", err) return nil, fmt.Errorf("failed to scan rows: %w", err)
@@ -384,9 +385,10 @@ func (db *Store) ListMockListingsForShop(ctx context.Context, acctID int64, plat
// check if the shop exists, and confirm there were actually listings (LEFT JOIN) // check if the shop exists, and confirm there were actually listings (LEFT JOIN)
if len(vs) == 0 || !vs[0].Shop_exists { if len(vs) == 0 || !vs[0].Shop_exists {
fmt.Println("TEST")
return nil, fmt.Errorf("%w: shop not found", consts.ErrNotFound) return nil, fmt.Errorf("%w: shop not found", consts.ErrNotFound)
} }
if vs[0].SKU == "" { if !vs[0].SKU.Valid {
return nil, nil return nil, nil
} }
@@ -401,12 +403,12 @@ func (db *Store) ListMockListingsForShop(ctx context.Context, acctID int64, plat
Platform: platform, Platform: platform,
ShopID: shopID, ShopID: shopID,
}, },
ListingID: v.Listing_id, ListingID: v.Listing_id.String,
}, },
SKU: v.SKU, SKU: v.SKU.String,
Name: v.Name, Name: v.Name.String,
Description: v.Description, Description: v.Description.String,
Count: v.Count, Count: v.Count.Int64,
} }
} }
+10 -9
View File
@@ -265,6 +265,9 @@
.ml-\[1em\] { .ml-\[1em\] {
margin-left: 1em; margin-left: 1em;
} }
.box-border {
box-sizing: border-box;
}
.block { .block {
display: block; display: block;
} }
@@ -289,15 +292,9 @@
.h-\[2rem\] { .h-\[2rem\] {
height: 2rem; height: 2rem;
} }
.h-\[10em\] {
height: 10em;
}
.h-fit { .h-fit {
height: fit-content; height: fit-content;
} }
.max-h-\[10em\] {
max-height: 10em;
}
.max-h-\[50em\] { .max-h-\[50em\] {
max-height: 50em; max-height: 50em;
} }
@@ -403,6 +400,9 @@
.gap-\[1em\] { .gap-\[1em\] {
gap: 1em; gap: 1em;
} }
.gap-x-\[1em\] {
column-gap: 1em;
}
.gap-y-\[2em\] { .gap-y-\[2em\] {
row-gap: 2em; row-gap: 2em;
} }
@@ -421,9 +421,6 @@
.overflow-y-hidden { .overflow-y-hidden {
overflow-y: hidden; overflow-y: hidden;
} }
.overflow-y-scroll {
overflow-y: scroll;
}
.rounded { .rounded {
border-radius: 0.25rem; border-radius: 0.25rem;
} }
@@ -439,6 +436,10 @@
.rounded-sm { .rounded-sm {
border-radius: calc(var(--radius) - 4px); border-radius: calc(var(--radius) - 4px);
} }
.border {
border-style: var(--tw-border-style);
border-width: 1px;
}
.border-\[1px\] { .border-\[1px\] {
border-style: var(--tw-border-style); border-style: var(--tw-border-style);
border-width: 1px; border-width: 1px;
@@ -29,7 +29,7 @@
<div class="grid grid-cols-[1fr_1fr] gap-[1em] p-[1em]"> <div class="grid grid-cols-[1fr_1fr] gap-[1em] p-[1em]">
<form <form
id="new-listing-form" id="edit-listing-form"
hx-post={{ printf "/api/accounts/%d/platforms/amazon/shops/mocks/%s/listings" $acctID $shopID }} hx-post={{ printf "/api/accounts/%d/platforms/amazon/shops/mocks/%s/listings" $acctID $shopID }}
hx-swap="none" hx-swap="none"
class=" class="
@@ -42,6 +42,19 @@
h-fit h-fit
rounded-lg rounded-lg
" "
_="
on editListing(
listingID,
name,
sku,
description
)
set the value of the first <input[name='name']/> in me to name
set the value of the first <input[name='sku']/> in me to sku
set the value of the first <input[name='description']/> in me to description
remove .hidden from <button#save-as-new-listing-button/>
remove @disabled from <button#save-as-new-listing-button/>
"
> >
<label for="name"> <label for="name">
Name: Name:
@@ -77,25 +90,70 @@
{{ component "button" {{ component "button"
"Text" "Save Listing" "Text" "Save Listing"
"Class" "self-center p-[1em] col-span-2" "Class" "self-center p-[1em] col-span-2"
"_" "on click send reset() to <li/> in next <ul/>"
}}
{{ component "button"
"Text" "Save As New Listing"
"Class" "self-center p-[1em] col-span-2 hidden"
"ID" "save-as-new-listing-button"
"Disabled" true
"_" "on click event.preventDefault() then send reset() to <li/> in next <ul/>"
}} }}
</form> </form>
<ul class="max-h-[50em] overflow-y-auto flex flex-col gap-[1em]"> <ul class="max-h-[50em] overflow-y-auto flex flex-col gap-[1em]">
{{- range $listing := .Accounts.ListMockListingsForShop $acctID $platform $shopID }} {{- range $listing := .Accounts.ListMockListingsForShop $acctID $platform $shopID }}
<li class="p-[1em] bg-card rounded-lg"> <li
<div> class="
Name: {{ $listing.Name }} p-[1em]
</div> grid grid-cols-[max-content_1fr] gap-x-[1em]
<div> bg-card
SKU: {{ $listing.SKU }} rounded-lg
</div> "
<div> _="
Description: {{ $listing.Description }} on click
</div> send reset() to <li/> in the closest <ul/>
<div> add .border-foreground to me
Count: {{ $listing.Count }} add .border to me
</div> send editListing(
listingID: '{{$listing.ListingID}}',
name: '{{$listing.Name}}',
sku: '{{$listing.SKU}}',
description: '{{$listing.Description}}'
) to #edit-listing-form
on reset
remove .border-foreground from me
remove .border from me
"
>
<span>
Name:
</span>
<span>
{{ $listing.Name }}
</span>
<span>
SKU:
</span>
<span>
{{ $listing.SKU }}
</span>
<span>
Description:
</span>
<span>
{{ $listing.Description }}
</span>
<span>
Count:
</span>
<span>
{{ $listing.Count }}
</span>
</li> </li>
{{- end }} {{- end }}
</ul> </ul>