|
|
|
@@ -60,12 +60,14 @@ func (r *Repository) Create(ownerID uint64, req CreateRequest, reviewRequired bo
|
|
|
|
|
if err := tx.Create(&account).Error; err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
price := normalizedListingPrice(req)
|
|
|
|
|
listing := model.RentalListing{
|
|
|
|
|
AccountID: account.ID,
|
|
|
|
|
OwnerID: ownerID,
|
|
|
|
|
PriceHourly: req.PriceHourly,
|
|
|
|
|
PriceDaily: req.PriceDaily,
|
|
|
|
|
PriceWeekly: req.PriceWeekly,
|
|
|
|
|
Price: price,
|
|
|
|
|
PriceHourly: listingHourlyPrice(req, price),
|
|
|
|
|
PriceDaily: listingDailyPrice(req, price),
|
|
|
|
|
PriceWeekly: listingWeeklyPrice(req, price),
|
|
|
|
|
DepositAmount: req.DepositAmount,
|
|
|
|
|
Status: listingStatus,
|
|
|
|
|
ReviewStatus: reviewStatus,
|
|
|
|
@@ -87,7 +89,7 @@ func (r *Repository) Update(ownerID uint64, listingID uint64, req UpdateRequest,
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if listing.Status == "rented" {
|
|
|
|
|
if listing.Status == "rented" || listing.InTransaction {
|
|
|
|
|
return ErrListingLocked
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -108,9 +110,11 @@ func (r *Repository) Update(ownerID uint64, listingID uint64, req UpdateRequest,
|
|
|
|
|
}
|
|
|
|
|
account.ScreenshotURLS = screenshots
|
|
|
|
|
|
|
|
|
|
listing.PriceHourly = req.PriceHourly
|
|
|
|
|
listing.PriceDaily = req.PriceDaily
|
|
|
|
|
listing.PriceWeekly = req.PriceWeekly
|
|
|
|
|
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
|
|
|
|
@@ -137,7 +141,7 @@ func (r *Repository) SubmitReview(ownerID uint64, listingID uint64, reviewRequir
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if listing.Status == "rented" {
|
|
|
|
|
if listing.Status == "rented" || listing.InTransaction {
|
|
|
|
|
return ErrListingLocked
|
|
|
|
|
}
|
|
|
|
|
listingStatus, reviewStatus, publishedAt := initialPublishState(reviewRequired)
|
|
|
|
@@ -215,7 +219,7 @@ func (r *Repository) adminUpdateStatus(adminID uint64, listingID uint64, req Adm
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if listing.Status == "rented" {
|
|
|
|
|
if listing.Status == "rented" || listing.InTransaction {
|
|
|
|
|
return ErrListingLocked
|
|
|
|
|
}
|
|
|
|
|
beforeListingStatus := listing.Status
|
|
|
|
@@ -270,7 +274,7 @@ func (r *Repository) Approve(listingID uint64) (*ListingDTO, error) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if listing.Status == "rented" {
|
|
|
|
|
if listing.Status == "rented" || listing.InTransaction {
|
|
|
|
|
return ErrListingLocked
|
|
|
|
|
}
|
|
|
|
|
now := time.Now()
|
|
|
|
@@ -309,7 +313,7 @@ func (r *Repository) Reject(listingID uint64, req ReviewRequest) (*ListingDTO, e
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if listing.Status == "rented" {
|
|
|
|
|
if listing.Status == "rented" || listing.InTransaction {
|
|
|
|
|
return ErrListingLocked
|
|
|
|
|
}
|
|
|
|
|
listing.Status = "draft"
|
|
|
|
@@ -346,7 +350,7 @@ func (r *Repository) Offline(ownerID uint64, listingID uint64) error {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if listing.Status == "rented" {
|
|
|
|
|
if listing.Status == "rented" || listing.InTransaction {
|
|
|
|
|
return ErrListingLocked
|
|
|
|
|
}
|
|
|
|
|
listing.Status = "offline"
|
|
|
|
@@ -484,6 +488,66 @@ func rowsToDTO(rows []listingRow) []ListingDTO {
|
|
|
|
|
return items
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func publicListings(items []ListingDTO) []ListingDTO {
|
|
|
|
|
for index := range items {
|
|
|
|
|
applyPublicListingURLs(&items[index])
|
|
|
|
@@ -501,6 +565,7 @@ 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,
|
|
|
|
@@ -517,11 +582,13 @@ func (row listingRow) toDTO() ListingDTO {
|
|
|
|
|
AssetSummary: assetSummary,
|
|
|
|
|
ScreenshotURLS: screenshotURLS,
|
|
|
|
|
CoverURL: publicCoverURL(row.ID, screenshotURLS, row.Status, row.ReviewStatus),
|
|
|
|
|
PriceHourly: row.PriceHourly,
|
|
|
|
|
PriceDaily: row.PriceDaily,
|
|
|
|
|
PriceWeekly: row.PriceWeekly,
|
|
|
|
|
Price: price,
|
|
|
|
|
PriceHourly: priceHourly,
|
|
|
|
|
PriceDaily: priceDaily,
|
|
|
|
|
PriceWeekly: priceWeekly,
|
|
|
|
|
DepositAmount: row.DepositAmount,
|
|
|
|
|
IsAccelerated: isAcceleratedSale(assetSummary),
|
|
|
|
|
InTransaction: row.InTransaction,
|
|
|
|
|
Status: row.Status,
|
|
|
|
|
ReviewStatus: row.ReviewStatus,
|
|
|
|
|
ReviewReason: row.ReviewReason,
|
|
|
|
@@ -534,6 +601,7 @@ 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,
|
|
|
|
@@ -548,11 +616,13 @@ func toDTO(account model.GameAccount, listing model.RentalListing) *ListingDTO {
|
|
|
|
|
AssetSummary: assetSummary,
|
|
|
|
|
ScreenshotURLS: screenshotURLS,
|
|
|
|
|
CoverURL: publicCoverURL(listing.ID, screenshotURLS, listing.Status, listing.ReviewStatus),
|
|
|
|
|
PriceHourly: listing.PriceHourly,
|
|
|
|
|
PriceDaily: listing.PriceDaily,
|
|
|
|
|
PriceWeekly: listing.PriceWeekly,
|
|
|
|
|
Price: price,
|
|
|
|
|
PriceHourly: priceHourly,
|
|
|
|
|
PriceDaily: priceDaily,
|
|
|
|
|
PriceWeekly: priceWeekly,
|
|
|
|
|
DepositAmount: listing.DepositAmount,
|
|
|
|
|
IsAccelerated: isAcceleratedSale(assetSummary),
|
|
|
|
|
InTransaction: listing.InTransaction,
|
|
|
|
|
Status: listing.Status,
|
|
|
|
|
ReviewStatus: listing.ReviewStatus,
|
|
|
|
|
ReviewReason: listing.ReviewReason,
|
|
|
|
|