修复卖家商品价格展示
This commit is contained in:
@@ -378,7 +378,7 @@ func (r *Repository) ListMine(ownerID uint64) ([]ListingDTO, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rowsToDTO(rows), nil
|
||||
return sellerListings(rowsToDTO(rows)), nil
|
||||
}
|
||||
|
||||
func (r *Repository) FindPublic(id uint64) (*ListingDTO, error) {
|
||||
@@ -412,7 +412,12 @@ func (r *Repository) FindPublicScreenshotKey(id uint64, index int) (string, erro
|
||||
}
|
||||
|
||||
func (r *Repository) FindMine(ownerID uint64, id uint64) (*ListingDTO, error) {
|
||||
return r.findDTO("l.id = ? AND l.owner_id = ?", id, ownerID)
|
||||
dto, err := r.findDTO("l.id = ? AND l.owner_id = ?", id, ownerID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
applySellerListingPrice(dto)
|
||||
return dto, nil
|
||||
}
|
||||
|
||||
func (r *Repository) findOwnedForUpdate(tx *gorm.DB, ownerID uint64, listingID uint64) (*model.RentalListing, *model.GameAccount, error) {
|
||||
@@ -493,6 +498,13 @@ func publicListings(items []ListingDTO) []ListingDTO {
|
||||
return items
|
||||
}
|
||||
|
||||
func sellerListings(items []ListingDTO) []ListingDTO {
|
||||
for index := range items {
|
||||
applySellerListingPrice(&items[index])
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func applyPublicListingURLs(item *ListingDTO) {
|
||||
item.ScreenshotURLS = publicScreenshotURLs(item.ID, item.ScreenshotURLS, item.Status, item.ReviewStatus)
|
||||
if item.AssetSummary != nil {
|
||||
@@ -500,6 +512,20 @@ func applyPublicListingURLs(item *ListingDTO) {
|
||||
}
|
||||
}
|
||||
|
||||
func applySellerListingPrice(item *ListingDTO) {
|
||||
if item == nil || item.AssetSummary == nil {
|
||||
return
|
||||
}
|
||||
breakdown, ok := item.AssetSummary["price_breakdown"].(map[string]any)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
sellerPrice := readSummaryNumber(breakdown["seller_total_price"])
|
||||
if sellerPrice > 0 {
|
||||
item.Price = sellerPrice
|
||||
}
|
||||
}
|
||||
|
||||
func (row listingRow) toDTO() ListingDTO {
|
||||
assetSummary := decodeAssetSummary(row.AssetSummary)
|
||||
screenshotURLS := cleanScreenshotURLs(decodeScreenshots(row.ScreenshotURLS))
|
||||
|
||||
@@ -40,3 +40,37 @@ func TestValidateRequestRequiresDepositAboveConsumables(t *testing.T) {
|
||||
t.Fatalf("expected valid request, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplySellerListingPriceUsesSellerTotalPrice(t *testing.T) {
|
||||
item := &ListingDTO{
|
||||
Price: 238,
|
||||
AssetSummary: map[string]any{
|
||||
"price_breakdown": map[string]any{
|
||||
"seller_total_price": 200,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
applySellerListingPrice(item)
|
||||
|
||||
if item.Price != 200 {
|
||||
t.Fatalf("expected seller price 200, got %.2f", item.Price)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplySellerListingPriceKeepsFallbackPrice(t *testing.T) {
|
||||
item := &ListingDTO{
|
||||
Price: 238,
|
||||
AssetSummary: map[string]any{
|
||||
"price_breakdown": map[string]any{
|
||||
"seller_total_price": 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
applySellerListingPrice(item)
|
||||
|
||||
if item.Price != 238 {
|
||||
t.Fatalf("expected fallback price 238, got %.2f", item.Price)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user