You can not select more than 25 topics
Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- package reward
-
- import (
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/services/reward/point"
- "errors"
- "fmt"
- )
-
- var RewardOperatorMap = map[string]RewardOperator{
- fmt.Sprint(models.RewardTypePoint): new(point.PointOperator),
- }
-
- type RewardOperateContext struct {
- SourceType models.RewardSourceType
- SourceId string
- Remark string
- Reward Reward
- TargetUserId int64
- }
-
- type RewardOperateResponse int
-
- const (
- RewardOperateSuccess RewardOperateResponse = iota + 1
- RewardOperateBalanceNotEnough
- )
-
- func (t RewardOperateResponse) IsSuccess() bool {
- return t == RewardOperateSuccess
- }
-
- type RewardOperator interface {
- IsOperated(ctx RewardOperateContext) bool
- IsLimited(ctx RewardOperateContext) bool
- Operate(ctx RewardOperateContext) error
- }
-
- func Send(ctx RewardOperateContext) error {
- operator := GetOperator(ctx.Reward.Type)
- if operator == nil {
- return errors.New("operator of reward type is not exist")
- }
- if operator.IsOperated(ctx) {
- return nil
- }
- if operator.IsLimited(ctx) {
- return nil
- }
- if err := operator.Operate(ctx); err != nil {
- return err
- }
- return nil
- }
-
- func GetOperator(rewardType string) RewardOperator {
- return RewardOperatorMap[rewardType]
- }
|