stubbed updating of saved mock listing
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -354,8 +355,8 @@ func (db *Store) ListMockListingsForShop(ctx context.Context, acctID int64, plat
|
||||
ON
|
||||
TRUE
|
||||
WHERE
|
||||
account_id = @account_id
|
||||
AND shop_id = @shop_id
|
||||
(account_id IS NULL OR account_id = @account_id)
|
||||
AND (shop_id IS NULL OR shop_id = @shop_id)
|
||||
`,
|
||||
shopTableName,
|
||||
listingsTableName,
|
||||
@@ -371,11 +372,11 @@ func (db *Store) ListMockListingsForShop(ctx context.Context, acctID int64, plat
|
||||
|
||||
vs, err := pgx.CollectRows(rows, pgx.RowToStructByNameLax[struct {
|
||||
Shop_exists bool
|
||||
Listing_id string
|
||||
SKU string
|
||||
Name string
|
||||
Description string
|
||||
Count int64
|
||||
Listing_id pgtype.Text
|
||||
SKU pgtype.Text
|
||||
Name pgtype.Text
|
||||
Description pgtype.Text
|
||||
Count pgtype.Int8
|
||||
}])
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
if len(vs) == 0 || !vs[0].Shop_exists {
|
||||
fmt.Println("TEST")
|
||||
return nil, fmt.Errorf("%w: shop not found", consts.ErrNotFound)
|
||||
}
|
||||
if vs[0].SKU == "" {
|
||||
if !vs[0].SKU.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -401,12 +403,12 @@ func (db *Store) ListMockListingsForShop(ctx context.Context, acctID int64, plat
|
||||
Platform: platform,
|
||||
ShopID: shopID,
|
||||
},
|
||||
ListingID: v.Listing_id,
|
||||
ListingID: v.Listing_id.String,
|
||||
},
|
||||
SKU: v.SKU,
|
||||
Name: v.Name,
|
||||
Description: v.Description,
|
||||
Count: v.Count,
|
||||
SKU: v.SKU.String,
|
||||
Name: v.Name.String,
|
||||
Description: v.Description.String,
|
||||
Count: v.Count.Int64,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-9
@@ -265,6 +265,9 @@
|
||||
.ml-\[1em\] {
|
||||
margin-left: 1em;
|
||||
}
|
||||
.box-border {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.block {
|
||||
display: block;
|
||||
}
|
||||
@@ -289,15 +292,9 @@
|
||||
.h-\[2rem\] {
|
||||
height: 2rem;
|
||||
}
|
||||
.h-\[10em\] {
|
||||
height: 10em;
|
||||
}
|
||||
.h-fit {
|
||||
height: fit-content;
|
||||
}
|
||||
.max-h-\[10em\] {
|
||||
max-height: 10em;
|
||||
}
|
||||
.max-h-\[50em\] {
|
||||
max-height: 50em;
|
||||
}
|
||||
@@ -403,6 +400,9 @@
|
||||
.gap-\[1em\] {
|
||||
gap: 1em;
|
||||
}
|
||||
.gap-x-\[1em\] {
|
||||
column-gap: 1em;
|
||||
}
|
||||
.gap-y-\[2em\] {
|
||||
row-gap: 2em;
|
||||
}
|
||||
@@ -421,9 +421,6 @@
|
||||
.overflow-y-hidden {
|
||||
overflow-y: hidden;
|
||||
}
|
||||
.overflow-y-scroll {
|
||||
overflow-y: scroll;
|
||||
}
|
||||
.rounded {
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
@@ -439,6 +436,10 @@
|
||||
.rounded-sm {
|
||||
border-radius: calc(var(--radius) - 4px);
|
||||
}
|
||||
.border {
|
||||
border-style: var(--tw-border-style);
|
||||
border-width: 1px;
|
||||
}
|
||||
.border-\[1px\] {
|
||||
border-style: var(--tw-border-style);
|
||||
border-width: 1px;
|
||||
|
||||
+73
-15
@@ -29,7 +29,7 @@
|
||||
|
||||
<div class="grid grid-cols-[1fr_1fr] gap-[1em] p-[1em]">
|
||||
<form
|
||||
id="new-listing-form"
|
||||
id="edit-listing-form"
|
||||
hx-post={{ printf "/api/accounts/%d/platforms/amazon/shops/mocks/%s/listings" $acctID $shopID }}
|
||||
hx-swap="none"
|
||||
class="
|
||||
@@ -42,6 +42,19 @@
|
||||
h-fit
|
||||
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">
|
||||
Name:
|
||||
@@ -77,25 +90,70 @@
|
||||
{{ component "button"
|
||||
"Text" "Save Listing"
|
||||
"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>
|
||||
|
||||
|
||||
<ul class="max-h-[50em] overflow-y-auto flex flex-col gap-[1em]">
|
||||
{{- range $listing := .Accounts.ListMockListingsForShop $acctID $platform $shopID }}
|
||||
<li class="p-[1em] bg-card rounded-lg">
|
||||
<div>
|
||||
Name: {{ $listing.Name }}
|
||||
</div>
|
||||
<div>
|
||||
SKU: {{ $listing.SKU }}
|
||||
</div>
|
||||
<div>
|
||||
Description: {{ $listing.Description }}
|
||||
</div>
|
||||
<div>
|
||||
Count: {{ $listing.Count }}
|
||||
</div>
|
||||
<li
|
||||
class="
|
||||
p-[1em]
|
||||
grid grid-cols-[max-content_1fr] gap-x-[1em]
|
||||
bg-card
|
||||
rounded-lg
|
||||
"
|
||||
_="
|
||||
on click
|
||||
send reset() to <li/> in the closest <ul/>
|
||||
add .border-foreground to me
|
||||
add .border to me
|
||||
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>
|
||||
{{- end }}
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user