fix(distribution): 统一分销订单租户管理口径
This commit is contained in:
@@ -19,8 +19,10 @@ func (r *Repository) FindTenantOffer(ctx context.Context, listingID uint64) (*Te
|
||||
}
|
||||
var listing model.RentalListing
|
||||
if err := r.db.WithContext(ctx).
|
||||
Select("id, price_cent").
|
||||
Where("id = ? AND (distribution_site_id IS NULL OR distribution_site_id = 0)", listingID).
|
||||
Table("rental_listings AS l").
|
||||
Select("l.id, l.price_cent").
|
||||
Joins("JOIN tenant_listing_offers AS tlo ON tlo.listing_id = l.id AND tlo.tenant_id = ?", tenantID).
|
||||
Where("l.id = ?", listingID).
|
||||
First(&listing).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -54,8 +56,10 @@ func (r *Repository) UpdateTenantOffer(
|
||||
}
|
||||
var listing model.RentalListing
|
||||
if err := r.db.WithContext(ctx).
|
||||
Select("id, price_cent").
|
||||
Where("id = ? AND (distribution_site_id IS NULL OR distribution_site_id = 0)", listingID).
|
||||
Table("rental_listings AS l").
|
||||
Select("l.id, l.price_cent").
|
||||
Joins("JOIN tenant_listing_offers AS tlo ON tlo.listing_id = l.id AND tlo.tenant_id = ?", tenantID).
|
||||
Where("l.id = ?", listingID).
|
||||
First(&listing).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, ErrListingNotFound
|
||||
|
||||
@@ -2,6 +2,7 @@ package listing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"hfb_sys/backend/internal/database"
|
||||
@@ -219,6 +220,19 @@ func TestPublicListingSharedPoolUsesTenantOffers(t *testing.T) {
|
||||
if _, err := repo.FindPublic(listingTenantContext(jieyou.ID), listing.ID, "", 0); err != nil {
|
||||
t.Fatalf("shared distribution listing detail should be visible to jieyou: %v", err)
|
||||
}
|
||||
if _, err := repo.FindTenantOffer(listingTenantContext(dachui.ID), listing.ID); err != nil {
|
||||
t.Fatalf("dachui should read its distribution listing offer: %v", err)
|
||||
}
|
||||
updatedPrice := int64(12000)
|
||||
updated, err := repo.UpdateTenantOffer(listingTenantContext(jieyou.ID), listing.ID, UpdateTenantListingOfferRequest{
|
||||
DisplayStatus: "disabled", PriceCent: &updatedPrice,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("jieyou should update its distribution listing offer: %v", err)
|
||||
}
|
||||
if updated.DisplayStatus != "disabled" || updated.EffectivePriceCent != updatedPrice {
|
||||
t.Fatalf("updated distribution offer = %+v", updated)
|
||||
}
|
||||
|
||||
otherResult, err := repo.ListPublic(listingTenantContext(other.ID), PublicListQuery{})
|
||||
if err != nil {
|
||||
@@ -230,4 +244,9 @@ func TestPublicListingSharedPoolUsesTenantOffers(t *testing.T) {
|
||||
if _, err := repo.FindPublic(listingTenantContext(other.ID), listing.ID, "", 0); err == nil {
|
||||
t.Fatal("distribution listing detail must not be visible without tenant offer")
|
||||
}
|
||||
if _, err := repo.UpdateTenantOffer(listingTenantContext(other.ID), listing.ID, UpdateTenantListingOfferRequest{
|
||||
DisplayStatus: "enabled",
|
||||
}); !errors.Is(err, ErrListingNotFound) {
|
||||
t.Fatalf("tenant without offer must not create distribution offer, err=%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user