installed gin
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"ruben/inventory2/internal/consts"
|
||||
"slices"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
@@ -18,7 +19,8 @@ type (
|
||||
SyncGroupListing struct {
|
||||
SyncGroupIDs
|
||||
AccountShopIDs
|
||||
ListingID string
|
||||
ListingID string
|
||||
OrderIndex int
|
||||
}
|
||||
|
||||
SyncGroupIDs struct {
|
||||
@@ -28,7 +30,8 @@ type (
|
||||
|
||||
SyncGroupListingDraft struct {
|
||||
AccountShopIDs
|
||||
ListingID string
|
||||
ListingID string
|
||||
OrderIndex int
|
||||
}
|
||||
)
|
||||
|
||||
@@ -96,9 +99,10 @@ func (db *Store) GetSyncGroupListingDraft(ctx context.Context, acctID int64, ord
|
||||
}
|
||||
|
||||
r, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByNameLax[struct {
|
||||
Platform *Platform
|
||||
Shop_id *string
|
||||
Listing_id *string
|
||||
Platform *Platform
|
||||
Shop_id *string
|
||||
Listing_id *string
|
||||
Order_index *int
|
||||
}])
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
@@ -115,7 +119,8 @@ func (db *Store) GetSyncGroupListingDraft(ctx context.Context, acctID int64, ord
|
||||
Platform: deref(r.Platform),
|
||||
ShopID: deref(r.Shop_id),
|
||||
},
|
||||
ListingID: deref(r.Listing_id),
|
||||
ListingID: deref(r.Listing_id),
|
||||
OrderIndex: orderIndex,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -182,17 +187,7 @@ func (db *Store) DeleteSyncGroupListingDraft(ctx context.Context, acctID int64,
|
||||
rows, err := db.db.Query(
|
||||
ctx,
|
||||
`
|
||||
WITH updated_drafts AS (
|
||||
UPDATE
|
||||
sync_group_listing_drafts
|
||||
SET
|
||||
order_index = (order_index - 1)
|
||||
WHERE
|
||||
account_id = @account_id
|
||||
AND order_index > @order_index
|
||||
RETURNING
|
||||
order_index
|
||||
), deleted_draft AS (
|
||||
WITH deleted_draft AS (
|
||||
DELETE FROM
|
||||
sync_group_listing_drafts
|
||||
WHERE
|
||||
@@ -202,17 +197,17 @@ func (db *Store) DeleteSyncGroupListingDraft(ctx context.Context, acctID int64,
|
||||
true AS found
|
||||
)
|
||||
SELECT
|
||||
COALESCE(dd.found, false) AS found,
|
||||
(COALESCE(MAX(ud.order_index), -1) + 1) AS num_rows
|
||||
COUNT(*) as num_rows,
|
||||
COALESCE(dd.found, FALSE) as found
|
||||
FROM
|
||||
deleted_draft dd
|
||||
sync_group_listing_drafts ld
|
||||
LEFT JOIN
|
||||
updated_drafts ud
|
||||
ON true
|
||||
deleted_draft dd
|
||||
ON TRUE
|
||||
WHERE
|
||||
account_id = @account_id
|
||||
GROUP BY
|
||||
ud.order_index, dd.found
|
||||
LIMIT
|
||||
1
|
||||
ld.account_id, dd.found
|
||||
`,
|
||||
pgx.NamedArgs{
|
||||
"account_id": acctID,
|
||||
@@ -256,6 +251,8 @@ func (db *Store) GetSyncGroupListingDrafts(ctx context.Context, acctID int64) ([
|
||||
sync_group_listing_drafts
|
||||
WHERE
|
||||
account_id = @account_id
|
||||
ORDER BY
|
||||
order_index ASC
|
||||
`,
|
||||
pgx.NamedArgs{
|
||||
"account_id": acctID,
|
||||
@@ -278,8 +275,8 @@ func (db *Store) GetSyncGroupListingDrafts(ctx context.Context, acctID int64) ([
|
||||
}
|
||||
|
||||
listings := make([]SyncGroupListingDraft, len(rs))
|
||||
for _, r := range rs {
|
||||
listings[r.Order_index] = SyncGroupListingDraft{
|
||||
for i, r := range rs {
|
||||
listings[i] = SyncGroupListingDraft{
|
||||
AccountShopIDs: AccountShopIDs{
|
||||
AccountIDs: AccountIDs{
|
||||
AccountID: acctID,
|
||||
@@ -287,10 +284,15 @@ func (db *Store) GetSyncGroupListingDrafts(ctx context.Context, acctID int64) ([
|
||||
Platform: deref(r.Platform),
|
||||
ShopID: deref(r.Shop_id),
|
||||
},
|
||||
ListingID: deref(r.Listing_id),
|
||||
ListingID: deref(r.Listing_id),
|
||||
OrderIndex: r.Order_index,
|
||||
}
|
||||
}
|
||||
|
||||
slices.SortFunc(listings, func(a, b SyncGroupListingDraft) int {
|
||||
return a.OrderIndex - b.OrderIndex
|
||||
})
|
||||
|
||||
return listings, nil
|
||||
}
|
||||
|
||||
@@ -397,8 +399,8 @@ func (db *Store) SaveNewSyncGroup(ctx context.Context, acctID int64) (SyncGroup,
|
||||
}
|
||||
|
||||
listings := make([]SyncGroupListing, len(rs))
|
||||
for _, r := range rs {
|
||||
listings[r.Order_index] = SyncGroupListing{
|
||||
for i, r := range rs {
|
||||
listings[i] = SyncGroupListing{
|
||||
SyncGroupIDs: SyncGroupIDs{
|
||||
AccountIDs: AccountIDs{
|
||||
AccountID: acctID,
|
||||
@@ -412,10 +414,15 @@ func (db *Store) SaveNewSyncGroup(ctx context.Context, acctID int64) (SyncGroup,
|
||||
Platform: r.Platform,
|
||||
ShopID: r.Shop_id,
|
||||
},
|
||||
ListingID: r.Listing_id,
|
||||
ListingID: r.Listing_id,
|
||||
OrderIndex: r.Order_index,
|
||||
}
|
||||
}
|
||||
|
||||
slices.SortFunc(listings, func(a, b SyncGroupListing) int {
|
||||
return a.OrderIndex - b.OrderIndex
|
||||
})
|
||||
|
||||
return SyncGroup{
|
||||
SyncGroupIDs: SyncGroupIDs{
|
||||
AccountIDs: AccountIDs{
|
||||
|
||||
@@ -31,7 +31,7 @@ const (
|
||||
AUTH0_CLIENT_SECRET = "83U-iWdVaNnwk9XDzteo_2VMyOq_l1siKYqg1_2E7jCzgL8MnkaxlysPMcPMGlxA"
|
||||
|
||||
// The Callback URL of our application.
|
||||
AUTH0_CALLBACK_URL = "https://inventory-plus-plus.com/auth/login/callback"
|
||||
AUTH0_CALLBACK_URL = "https://inventory-plus-plus.com/api/auth/login/callback"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
Reference in New Issue
Block a user