Revert "feat(loyalty): EnakPoint & EnakCoin" (#32)
This reverts merge commit645da30, returning main tof0ff59f. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
645da3048e
commit
4e24f9bbb0
@@ -9,6 +9,20 @@ import (
|
||||
)
|
||||
|
||||
type GamificationValidator interface {
|
||||
// Customer Points
|
||||
ValidateCreateCustomerPointsRequest(req *contract.CreateCustomerPointsRequest) (error, string)
|
||||
ValidateUpdateCustomerPointsRequest(req *contract.UpdateCustomerPointsRequest) (error, string)
|
||||
ValidateListCustomerPointsRequest(req *contract.ListCustomerPointsRequest) (error, string)
|
||||
ValidateAddCustomerPointsRequest(req *contract.AddCustomerPointsRequest) (error, string)
|
||||
ValidateDeductCustomerPointsRequest(req *contract.DeductCustomerPointsRequest) (error, string)
|
||||
|
||||
// Customer Tokens
|
||||
ValidateCreateCustomerTokensRequest(req *contract.CreateCustomerTokensRequest) (error, string)
|
||||
ValidateUpdateCustomerTokensRequest(req *contract.UpdateCustomerTokensRequest) (error, string)
|
||||
ValidateListCustomerTokensRequest(req *contract.ListCustomerTokensRequest) (error, string)
|
||||
ValidateAddCustomerTokensRequest(req *contract.AddCustomerTokensRequest) (error, string)
|
||||
ValidateDeductCustomerTokensRequest(req *contract.DeductCustomerTokensRequest) (error, string)
|
||||
|
||||
// Tiers
|
||||
ValidateCreateTierRequest(req *contract.CreateTierRequest) (error, string)
|
||||
ValidateUpdateTierRequest(req *contract.UpdateTierRequest) (error, string)
|
||||
@@ -46,6 +60,152 @@ func NewGamificationValidator() *GamificationValidatorImpl {
|
||||
}
|
||||
}
|
||||
|
||||
// Customer Points Validators
|
||||
func (v *GamificationValidatorImpl) ValidateCreateCustomerPointsRequest(req *contract.CreateCustomerPointsRequest) (error, string) {
|
||||
if err := v.validate.Struct(req); err != nil {
|
||||
return err, "VALIDATION_ERROR"
|
||||
}
|
||||
|
||||
if req.Balance < 0 {
|
||||
return errors.New("balance cannot be negative"), "INVALID_BALANCE"
|
||||
}
|
||||
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
func (v *GamificationValidatorImpl) ValidateUpdateCustomerPointsRequest(req *contract.UpdateCustomerPointsRequest) (error, string) {
|
||||
if err := v.validate.Struct(req); err != nil {
|
||||
return err, "VALIDATION_ERROR"
|
||||
}
|
||||
|
||||
if req.Balance < 0 {
|
||||
return errors.New("balance cannot be negative"), "INVALID_BALANCE"
|
||||
}
|
||||
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
func (v *GamificationValidatorImpl) ValidateListCustomerPointsRequest(req *contract.ListCustomerPointsRequest) (error, string) {
|
||||
if err := v.validate.Struct(req); err != nil {
|
||||
return err, "VALIDATION_ERROR"
|
||||
}
|
||||
|
||||
if req.Page <= 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
if req.Limit <= 0 {
|
||||
req.Limit = 10
|
||||
}
|
||||
if req.Limit > 100 {
|
||||
req.Limit = 100
|
||||
}
|
||||
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
func (v *GamificationValidatorImpl) ValidateAddCustomerPointsRequest(req *contract.AddCustomerPointsRequest) (error, string) {
|
||||
if err := v.validate.Struct(req); err != nil {
|
||||
return err, "VALIDATION_ERROR"
|
||||
}
|
||||
|
||||
if req.Points <= 0 {
|
||||
return errors.New("points must be greater than 0"), "INVALID_POINTS"
|
||||
}
|
||||
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
func (v *GamificationValidatorImpl) ValidateDeductCustomerPointsRequest(req *contract.DeductCustomerPointsRequest) (error, string) {
|
||||
if err := v.validate.Struct(req); err != nil {
|
||||
return err, "VALIDATION_ERROR"
|
||||
}
|
||||
|
||||
if req.Points <= 0 {
|
||||
return errors.New("points must be greater than 0"), "INVALID_POINTS"
|
||||
}
|
||||
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
// Customer Tokens Validators
|
||||
func (v *GamificationValidatorImpl) ValidateCreateCustomerTokensRequest(req *contract.CreateCustomerTokensRequest) (error, string) {
|
||||
if err := v.validate.Struct(req); err != nil {
|
||||
return err, "VALIDATION_ERROR"
|
||||
}
|
||||
|
||||
if req.Balance < 0 {
|
||||
return errors.New("balance cannot be negative"), "INVALID_BALANCE"
|
||||
}
|
||||
|
||||
validTokenTypes := []string{"SPIN", "RAFFLE", "MINIGAME"}
|
||||
if !contains(validTokenTypes, req.TokenType) {
|
||||
return errors.New("invalid token type"), "INVALID_TOKEN_TYPE"
|
||||
}
|
||||
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
func (v *GamificationValidatorImpl) ValidateUpdateCustomerTokensRequest(req *contract.UpdateCustomerTokensRequest) (error, string) {
|
||||
if err := v.validate.Struct(req); err != nil {
|
||||
return err, "VALIDATION_ERROR"
|
||||
}
|
||||
|
||||
if req.Balance < 0 {
|
||||
return errors.New("balance cannot be negative"), "INVALID_BALANCE"
|
||||
}
|
||||
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
func (v *GamificationValidatorImpl) ValidateListCustomerTokensRequest(req *contract.ListCustomerTokensRequest) (error, string) {
|
||||
if err := v.validate.Struct(req); err != nil {
|
||||
return err, "VALIDATION_ERROR"
|
||||
}
|
||||
|
||||
if req.Page <= 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
if req.Limit <= 0 {
|
||||
req.Limit = 10
|
||||
}
|
||||
if req.Limit > 100 {
|
||||
req.Limit = 100
|
||||
}
|
||||
|
||||
if req.TokenType != "" {
|
||||
validTokenTypes := []string{"SPIN", "RAFFLE", "MINIGAME"}
|
||||
if !contains(validTokenTypes, req.TokenType) {
|
||||
return errors.New("invalid token type"), "INVALID_TOKEN_TYPE"
|
||||
}
|
||||
}
|
||||
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
func (v *GamificationValidatorImpl) ValidateAddCustomerTokensRequest(req *contract.AddCustomerTokensRequest) (error, string) {
|
||||
if err := v.validate.Struct(req); err != nil {
|
||||
return err, "VALIDATION_ERROR"
|
||||
}
|
||||
|
||||
if req.Tokens <= 0 {
|
||||
return errors.New("tokens must be greater than 0"), "INVALID_TOKENS"
|
||||
}
|
||||
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
func (v *GamificationValidatorImpl) ValidateDeductCustomerTokensRequest(req *contract.DeductCustomerTokensRequest) (error, string) {
|
||||
if err := v.validate.Struct(req); err != nil {
|
||||
return err, "VALIDATION_ERROR"
|
||||
}
|
||||
|
||||
if req.Tokens <= 0 {
|
||||
return errors.New("tokens must be greater than 0"), "INVALID_TOKENS"
|
||||
}
|
||||
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
// Tier Validators
|
||||
func (v *GamificationValidatorImpl) ValidateCreateTierRequest(req *contract.CreateTierRequest) (error, string) {
|
||||
if err := v.validate.Struct(req); err != nil {
|
||||
@@ -276,8 +436,8 @@ func (v *GamificationValidatorImpl) ValidateCreateGamePlayRequest(req *contract.
|
||||
return err, "VALIDATION_ERROR"
|
||||
}
|
||||
|
||||
if req.CoinsUsed < 0 {
|
||||
return errors.New("coins used cannot be negative"), "INVALID_COINS_USED"
|
||||
if req.TokenUsed < 0 {
|
||||
return errors.New("token used cannot be negative"), "INVALID_TOKEN_USED"
|
||||
}
|
||||
|
||||
return nil, ""
|
||||
@@ -306,6 +466,10 @@ func (v *GamificationValidatorImpl) ValidatePlayGameRequest(req *contract.PlayGa
|
||||
return err, "VALIDATION_ERROR"
|
||||
}
|
||||
|
||||
if req.TokenUsed < 0 {
|
||||
return errors.New("token used cannot be negative"), "INVALID_TOKEN_USED"
|
||||
}
|
||||
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user