[server] Black Friday 2024
This commit is contained in:
@@ -27,9 +27,11 @@ const (
|
||||
// PeriodMonth is the unit for the duration of the monthly plan
|
||||
PeriodMonth = "month"
|
||||
|
||||
Period3Years = "3years"
|
||||
Period3Years = "3"
|
||||
|
||||
Period5Years = "5years"
|
||||
Period5Years = "5"
|
||||
|
||||
Period10Years = "10"
|
||||
|
||||
// FamilyPlanProductID is the product ID of family (internal employees & their friends & family) plan
|
||||
FamilyPlanProductID = "family"
|
||||
|
||||
@@ -2,12 +2,12 @@ package ente
|
||||
|
||||
// BlackFridayOffer represents the latest Black Friday Offer
|
||||
type BlackFridayOffer struct {
|
||||
ID string `json:"id"`
|
||||
Storage int64 `json:"storage"`
|
||||
Price string `json:"price"`
|
||||
OldPrice string `json:"oldPrice"`
|
||||
Period string `json:"period"`
|
||||
PaymentLink string `json:"paymentLink"`
|
||||
ID string `json:"id"`
|
||||
Storage int64 `json:"storage"`
|
||||
Price string `json:"price"`
|
||||
OldPrice string `json:"oldPrice"`
|
||||
PeriodInYears string `json:"periodInYears"`
|
||||
PaymentLink string `json:"paymentLink"`
|
||||
}
|
||||
|
||||
type BlackFridayOfferPerCountry map[string][]BlackFridayOffer
|
||||
|
||||
@@ -11,21 +11,22 @@ const (
|
||||
|
||||
// AddOnSupport is the bonus for users added by the support team
|
||||
AddOnSupport = "ADD_ON_SUPPORT"
|
||||
// AddOnBf2023 is the bonus for users who have opted for the Black Friday 2023 offer
|
||||
// AddOnBf is the bonus for users who have opted for the Black Friday offers
|
||||
AddOnBf2023 = "ADD_ON_BF_2023"
|
||||
AddOnBf2024 = "ADD_ON_BF_2024"
|
||||
// In the future, we can add various types of bonuses based on different events like Anniversary,
|
||||
// or finishing tasks like ML indexing, enabling sharing etc etc
|
||||
)
|
||||
|
||||
// PaidAddOnTypes : These add-ons can be purchased by the users and help in the expiry of an account
|
||||
// as long as the add-on is active.
|
||||
var PaidAddOnTypes = []BonusType{AddOnSupport, AddOnBf2023}
|
||||
var PaidAddOnTypes = []BonusType{AddOnSupport, AddOnBf2023, AddOnBf2024}
|
||||
|
||||
// ExtendsExpiry returns true if the bonus type extends the expiry of the account.
|
||||
// By default, all bonuses don't extend expiry.
|
||||
func (t BonusType) ExtendsExpiry() bool {
|
||||
switch t {
|
||||
case AddOnSupport, AddOnBf2023:
|
||||
case AddOnSupport, AddOnBf2023, AddOnBf2024:
|
||||
return true
|
||||
case Referral, SignUp:
|
||||
return false
|
||||
@@ -44,6 +45,8 @@ func BonusFromType(bonusType string) BonusType {
|
||||
return AddOnSupport
|
||||
case "ADD_ON_BF_2023":
|
||||
return AddOnBf2023
|
||||
case "ADD_ON_BF_2024":
|
||||
return AddOnBf2024
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/ente-io/museum/pkg/controller/offer"
|
||||
"github.com/ente-io/museum/pkg/utils/network"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -14,8 +15,7 @@ type OfferHandler struct {
|
||||
|
||||
// Deprecated for now
|
||||
func (h *OfferHandler) GetBlackFridayOffers(c *gin.Context) {
|
||||
// Return an empty list until the next sale
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"offers": []interface{}{},
|
||||
"offers": h.Controller.GetBlackFridayOffers(network.GetClientCountry(c)),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/ente-io/museum/pkg/controller/usercache"
|
||||
|
||||
"github.com/ente-io/museum/ente"
|
||||
storeageBonusEntity "github.com/ente-io/museum/ente/storagebonus"
|
||||
storageBonusEntity "github.com/ente-io/museum/ente/storagebonus"
|
||||
"github.com/ente-io/museum/pkg/controller/discord"
|
||||
"github.com/ente-io/museum/pkg/repo"
|
||||
"github.com/ente-io/museum/pkg/repo/storagebonus"
|
||||
@@ -87,10 +87,12 @@ func (c *OfferController) ApplyOffer(email string, productID string) error {
|
||||
return stacktrace.Propagate(ente.ErrNotFound, "Could not find an offer for "+productID)
|
||||
}
|
||||
var validTill int64
|
||||
if offerToBeApplied.Period == ente.Period3Years {
|
||||
if offerToBeApplied.PeriodInYears == ente.Period3Years {
|
||||
validTill = time.NDaysFromNow(3 * 365)
|
||||
} else if offerToBeApplied.Period == ente.Period5Years {
|
||||
} else if offerToBeApplied.PeriodInYears == ente.Period5Years {
|
||||
validTill = time.NDaysFromNow(5 * 365)
|
||||
} else if offerToBeApplied.PeriodInYears == ente.Period10Years {
|
||||
validTill = time.NDaysFromNow(10 * 365)
|
||||
} else {
|
||||
return stacktrace.Propagate(ente.ErrNotFound, "Could not find a valid time period for "+productID)
|
||||
}
|
||||
@@ -106,7 +108,7 @@ func (c *OfferController) ApplyOffer(email string, productID string) error {
|
||||
}
|
||||
}
|
||||
|
||||
err = c.StorageBonusRepo.InsertAddOnBonus(context.Background(), storeageBonusEntity.AddOnBf2023, userID, validTill, offerToBeApplied.Storage)
|
||||
err = c.StorageBonusRepo.InsertAddOnBonus(context.Background(), storageBonusEntity.AddOnBf2024, userID, validTill, offerToBeApplied.Storage)
|
||||
if err != nil {
|
||||
c.DiscordController.Notify("Error inserting bonus")
|
||||
return stacktrace.Propagate(err, "")
|
||||
|
||||
@@ -11,7 +11,7 @@ func (r *Repository) InsertAddOnBonus(ctx context.Context, bonusType storagebonu
|
||||
return err
|
||||
}
|
||||
bonusID := fmt.Sprintf("%s-%d", bonusType, userID)
|
||||
_, err := r.DB.ExecContext(ctx, "INSERT INTO storage_bonus (bonus_id, user_id, storage, type, valid_till) VALUES ($1, $2, $3, $4, $5)", bonusID, userID, storage, storagebonus.AddOnBf2023, validTill)
|
||||
_, err := r.DB.ExecContext(ctx, "INSERT INTO storage_bonus (bonus_id, user_id, storage, type, valid_till) VALUES ($1, $2, $3, $4, $5)", bonusID, userID, storage, bonusType, validTill)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -43,7 +43,7 @@ func (r *Repository) UpdateAddOnBonus(ctx context.Context, bonusType storagebonu
|
||||
}
|
||||
|
||||
func _validate(bonusType storagebonus.BonusType) error {
|
||||
if bonusType == storagebonus.AddOnBf2023 || bonusType == storagebonus.AddOnSupport {
|
||||
if bonusType == storagebonus.AddOnBf2023 || bonusType == storagebonus.AddOnBf2024 || bonusType == storagebonus.AddOnSupport {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("invalid bonus type: %s", bonusType)
|
||||
|
||||
Reference in New Issue
Block a user