mirror of
https://github.com/ente-io/ente.git
synced 2025-08-07 23:18:10 +00:00
[server] Allow adding support bonus
This commit is contained in:
parent
bf7f1d43c0
commit
0925f7f0a2
@ -87,6 +87,7 @@ const (
|
||||
)
|
||||
|
||||
type SupportUpdateBonus struct {
|
||||
BonusType string `json:"bonusType" binding:"required"`
|
||||
Action AddOnAction `json:"action" binding:"required"`
|
||||
UserID int64 `json:"userID" binding:"required"`
|
||||
Year int `json:"year"`
|
||||
@ -105,17 +106,26 @@ func (u SupportUpdateBonus) UpdateLog() string {
|
||||
}
|
||||
|
||||
func (u SupportUpdateBonus) Validate() error {
|
||||
isSupportBonus := u.BonusType == "ADD_ON_SUPPORT"
|
||||
if u.BonusType != "ADD_ON_SUPPORT" && u.BonusType != "ADD_ON_BF_2023" {
|
||||
return errors.New("invalid bonus type")
|
||||
}
|
||||
if u.Action == ADD || u.Action == UPDATE {
|
||||
if u.Testing {
|
||||
if u.StorageInMB == 0 && u.Minute == 0 {
|
||||
return errors.New("invalid input, set in MB and minute for test")
|
||||
}
|
||||
} else {
|
||||
if u.StorageInGB != 100 && u.StorageInGB != 2000 && u.StorageInGB != 500 {
|
||||
if u.StorageInGB != 200 && u.StorageInGB != 2000 && u.StorageInGB != 500 {
|
||||
return errors.New("invalid input for deal, only 100, 500, 2000 allowed")
|
||||
}
|
||||
if u.Year != 3 && u.Year != 5 {
|
||||
if isSupportBonus {
|
||||
if u.Year == 0 || u.Year > 100 {
|
||||
return errors.New("invalid input for year, only 1-100")
|
||||
}
|
||||
} else if u.Year != 3 && u.Year != 5 {
|
||||
return errors.New("invalid input for year, only 3 or 5")
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,21 @@ func (t BonusType) ExtendsExpiry() bool {
|
||||
}
|
||||
}
|
||||
|
||||
func BonusFromType(bonusType string) BonusType {
|
||||
switch bonusType {
|
||||
case "REFERRAL":
|
||||
return Referral
|
||||
case "SIGN_UP":
|
||||
return SignUp
|
||||
case "ADD_ON_SUPPORT":
|
||||
return AddOnSupport
|
||||
case "ADD_ON_BF_2023":
|
||||
return AddOnBf2023
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// RestrictToDoublingStorage returns true if the bonus type restricts the doubling of storage.
|
||||
// This indicates, the usable bonus storage should not exceed the current plan storage.
|
||||
// Note: Current plan storage includes both base subscription and storage bonus that can ExtendsExpiry
|
||||
|
@ -472,13 +472,14 @@ func (h *AdminHandler) UpdateBonus(c *gin.Context) {
|
||||
validTill = gTime.Now().AddDate(r.Year, 0, 0).UnixMicro()
|
||||
}
|
||||
var err error
|
||||
bonusType := bonusEntity.BonusType(r.BonusType)
|
||||
switch r.Action {
|
||||
case ente.ADD:
|
||||
err = h.StorageBonusRepo.InsertAddOnBonus(c, bonusEntity.AddOnBf2023, r.UserID, validTill, storage)
|
||||
err = h.StorageBonusRepo.InsertAddOnBonus(c, bonusType, r.UserID, validTill, storage)
|
||||
case ente.UPDATE:
|
||||
err = h.StorageBonusRepo.UpdateAddOnBonus(c, bonusEntity.AddOnBf2023, r.UserID, validTill, storage)
|
||||
err = h.StorageBonusRepo.UpdateAddOnBonus(c, bonusType, r.UserID, validTill, storage)
|
||||
case ente.REMOVE:
|
||||
_, err = h.StorageBonusRepo.RemoveAddOnBonus(c, bonusEntity.AddOnBf2023, r.UserID)
|
||||
_, err = h.StorageBonusRepo.RemoveAddOnBonus(c, bonusType, r.UserID)
|
||||
}
|
||||
if err != nil {
|
||||
handler.Error(c, stacktrace.Propagate(err, ""))
|
||||
|
Loading…
x
Reference in New Issue
Block a user