彻底优化数据库字段
This commit is contained in:
@@ -65,9 +65,6 @@ func (r *Repository) Create(ownerID uint64, req CreateRequest, reviewRequired bo
|
||||
AccountID: account.ID,
|
||||
OwnerID: ownerID,
|
||||
Price: price,
|
||||
PriceHourly: listingHourlyPrice(req, price),
|
||||
PriceDaily: listingDailyPrice(req, price),
|
||||
PriceWeekly: listingWeeklyPrice(req, price),
|
||||
DepositAmount: req.DepositAmount,
|
||||
Status: listingStatus,
|
||||
ReviewStatus: reviewStatus,
|
||||
@@ -112,9 +109,6 @@ func (r *Repository) Update(ownerID uint64, listingID uint64, req UpdateRequest,
|
||||
|
||||
price := normalizedListingPrice(req)
|
||||
listing.Price = price
|
||||
listing.PriceHourly = listingHourlyPrice(req, price)
|
||||
listing.PriceDaily = listingDailyPrice(req, price)
|
||||
listing.PriceWeekly = listingWeeklyPrice(req, price)
|
||||
listing.DepositAmount = req.DepositAmount
|
||||
listingStatus, reviewStatus, publishedAt := initialPublishState(reviewRequired)
|
||||
listing.Status = listingStatus
|
||||
@@ -489,63 +483,7 @@ func rowsToDTO(rows []listingRow) []ListingDTO {
|
||||
}
|
||||
|
||||
func normalizedListingPrice(req CreateRequest) float64 {
|
||||
if req.Price > 0 {
|
||||
return req.Price
|
||||
}
|
||||
if req.PriceDaily > 0 {
|
||||
return req.PriceDaily
|
||||
}
|
||||
if req.PriceHourly > 0 {
|
||||
return req.PriceHourly * 24
|
||||
}
|
||||
if req.PriceWeekly > 0 {
|
||||
return req.PriceWeekly / 7
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func listingHourlyPrice(req CreateRequest, price float64) float64 {
|
||||
if req.PriceHourly > 0 {
|
||||
return req.PriceHourly
|
||||
}
|
||||
return price / 24
|
||||
}
|
||||
|
||||
func listingDailyPrice(req CreateRequest, price float64) float64 {
|
||||
if req.PriceDaily > 0 {
|
||||
return req.PriceDaily
|
||||
}
|
||||
return price
|
||||
}
|
||||
|
||||
func listingWeeklyPrice(req CreateRequest, price float64) float64 {
|
||||
if req.PriceWeekly > 0 {
|
||||
return req.PriceWeekly
|
||||
}
|
||||
return price * 7
|
||||
}
|
||||
|
||||
func listingDisplayPrices(price float64, hourly float64, daily float64, weekly float64) (float64, float64, float64, float64) {
|
||||
if price <= 0 {
|
||||
switch {
|
||||
case daily > 0:
|
||||
price = daily
|
||||
case hourly > 0:
|
||||
price = hourly * 24
|
||||
case weekly > 0:
|
||||
price = weekly / 7
|
||||
}
|
||||
}
|
||||
if daily <= 0 {
|
||||
daily = price
|
||||
}
|
||||
if hourly <= 0 && price > 0 {
|
||||
hourly = price / 24
|
||||
}
|
||||
if weekly <= 0 && price > 0 {
|
||||
weekly = price * 7
|
||||
}
|
||||
return price, hourly, daily, weekly
|
||||
return req.Price
|
||||
}
|
||||
|
||||
func publicListings(items []ListingDTO) []ListingDTO {
|
||||
@@ -565,7 +503,6 @@ func applyPublicListingURLs(item *ListingDTO) {
|
||||
func (row listingRow) toDTO() ListingDTO {
|
||||
assetSummary := decodeAssetSummary(row.AssetSummary)
|
||||
screenshotURLS := cleanScreenshotURLs(decodeScreenshots(row.ScreenshotURLS))
|
||||
price, priceHourly, priceDaily, priceWeekly := listingDisplayPrices(row.Price, row.PriceHourly, row.PriceDaily, row.PriceWeekly)
|
||||
return ListingDTO{
|
||||
ID: row.ID,
|
||||
AccountID: row.AccountID,
|
||||
@@ -582,10 +519,7 @@ func (row listingRow) toDTO() ListingDTO {
|
||||
AssetSummary: assetSummary,
|
||||
ScreenshotURLS: screenshotURLS,
|
||||
CoverURL: publicCoverURL(row.ID, screenshotURLS, row.Status, row.ReviewStatus),
|
||||
Price: price,
|
||||
PriceHourly: priceHourly,
|
||||
PriceDaily: priceDaily,
|
||||
PriceWeekly: priceWeekly,
|
||||
Price: row.Price,
|
||||
DepositAmount: row.DepositAmount,
|
||||
IsAccelerated: isAcceleratedSale(assetSummary),
|
||||
InTransaction: row.InTransaction,
|
||||
@@ -601,7 +535,6 @@ func (row listingRow) toDTO() ListingDTO {
|
||||
func toDTO(account model.GameAccount, listing model.RentalListing) *ListingDTO {
|
||||
assetSummary := decodeAssetSummary(account.AssetSummary)
|
||||
screenshotURLS := cleanScreenshotURLs(decodeScreenshots(account.ScreenshotURLS))
|
||||
price, priceHourly, priceDaily, priceWeekly := listingDisplayPrices(listing.Price, listing.PriceHourly, listing.PriceDaily, listing.PriceWeekly)
|
||||
return &ListingDTO{
|
||||
ID: listing.ID,
|
||||
AccountID: account.ID,
|
||||
@@ -616,10 +549,7 @@ func toDTO(account model.GameAccount, listing model.RentalListing) *ListingDTO {
|
||||
AssetSummary: assetSummary,
|
||||
ScreenshotURLS: screenshotURLS,
|
||||
CoverURL: publicCoverURL(listing.ID, screenshotURLS, listing.Status, listing.ReviewStatus),
|
||||
Price: price,
|
||||
PriceHourly: priceHourly,
|
||||
PriceDaily: priceDaily,
|
||||
PriceWeekly: priceWeekly,
|
||||
Price: listing.Price,
|
||||
DepositAmount: listing.DepositAmount,
|
||||
IsAccelerated: isAcceleratedSale(assetSummary),
|
||||
InTransaction: listing.InTransaction,
|
||||
|
||||
Reference in New Issue
Block a user