25 lines
773 B
Go
25 lines
773 B
Go
package platformsetting
|
|
|
|
import (
|
|
"context"
|
|
kratoserrors "github.com/go-kratos/kratos/v3/errors"
|
|
)
|
|
|
|
var ErrInvalid = kratoserrors.BadRequest("PLATFORM_SETTING_INVALID", "diamond rate must be between 0.01 and 1.00")
|
|
|
|
type Setting struct{ DiamondRateCents int64 }
|
|
type Repo interface {
|
|
Get(context.Context) (*Setting, error)
|
|
Save(context.Context, *Setting) error
|
|
}
|
|
type Usecase struct{ repo Repo }
|
|
|
|
func NewUsecase(repo Repo) *Usecase { return &Usecase{repo: repo} }
|
|
func (uc *Usecase) Get(ctx context.Context) (*Setting, error) { return uc.repo.Get(ctx) }
|
|
func (uc *Usecase) Save(ctx context.Context, v *Setting) error {
|
|
if v == nil || v.DiamondRateCents < 1 || v.DiamondRateCents > 100 {
|
|
return ErrInvalid
|
|
}
|
|
return uc.repo.Save(ctx, v)
|
|
}
|